Files
app-govern/pages/user/login.vue

264 lines
9.5 KiB
Vue
Raw Normal View History

2023-01-11 16:33:13 +08:00
<template>
<Cn-page :loading="loading">
<view slot="body">
<view class="login">
<view class="login-title">登录</view>
2023-03-20 08:51:21 +08:00
<view class="login-des">灿能物联</view>
2023-01-11 16:33:13 +08:00
<view class="login-box">
<!-- <image class="login-box-logo" mode="widthFix" src="/static/logo.png"></image> -->
2023-02-07 17:59:54 +08:00
<image class="login-box-logo" mode="widthFix" src="/static/logo.png"></image>
2023-01-11 16:33:13 +08:00
<template v-if="loginType == 'yzm'">
<view class="login-box-input mt100">
2023-07-03 20:29:24 +08:00
<input class="login-box-input-main" maxlength="11" v-model="yzmForm.phone" placeholder="请输入手机号" />
2023-01-11 16:33:13 +08:00
</view>
<!-- <view class="login-box-input mt40">
<input class="login-box-input-main" v-model="yzmForm.imgCode" placeholder="图形验证码" />
<view class="login-box-input-img"></view>
</view> -->
<view class="login-box-input mt40">
<input class="login-box-input-main" v-model="yzmForm.code" placeholder="手机验证码" />
2023-07-03 09:16:54 +08:00
<view
class="ml40"
style="font-size: 28rpx; color: #666; width: 200rpx; text-align: center"
v-if="waitTime > 0"
>{{ waitTime + 's后重新获取' }}</view
>
2023-01-11 16:33:13 +08:00
<button class="login-box-input-btn" v-else @click="getCode" size="mini">获取验证码</button>
</view>
</template>
<template v-else>
<view class="login-box-input mt100">
2023-03-20 08:51:21 +08:00
<input class="login-box-input-main" v-model="pwdForm.phone" placeholder="请输入账号" />
2023-01-11 16:33:13 +08:00
</view>
<view class="login-box-input mt40">
2023-03-16 15:26:25 +08:00
<input type="password" class="login-box-input-main" v-model="pwdForm.pwd" placeholder="请输入密码" />
2023-01-11 16:33:13 +08:00
</view>
<!-- <view class="login-box-input mt40">
<view class="login-box-input-icon"></view>
<input class="login-box-input-main" v-model="pwdForm.imgCode" placeholder="图形验证码" />
<view class="login-box-input-img"></view>
</view> -->
</template>
<view class="login-box-btn" @click="login"> 登录 </view>
<view class="login-box-footer">
<view @click="loginType = 'pwd'" v-if="loginType == 'yzm'">账号密码登录</view>
<view @click="loginType = 'yzm'" v-else>短信验证码登录</view>
2023-07-03 09:16:54 +08:00
<view style="flex: 1"></view>
2023-01-13 16:32:56 +08:00
<navigator url="/pages/user/forget" hover-class="none">忘记密码</navigator>
2023-07-03 09:16:54 +08:00
<view style="margin: 0 10px; color: #999">|</view>
2023-01-13 16:32:56 +08:00
<navigator url="/pages/user/register" hover-class="none">快速注册</navigator>
2023-01-11 16:33:13 +08:00
</view>
<view class="login-box-tips">
2023-07-03 09:16:54 +08:00
<view style="color: #999">点击登录即表示同意</view>
2023-01-13 16:32:56 +08:00
<navigator url="/pages/mine/agreement" hover-class="none">用户协议</navigator>
<navigator url="/pages/mine/policy" hover-class="none">个人信息保护政策</navigator>
2023-01-11 16:33:13 +08:00
</view>
</view>
</view>
</view>
</Cn-page>
</template>
<script>
2023-07-03 09:16:54 +08:00
import { apiGetYms, apiLogin, apiYsmLogin } from '@/common/api/user'
2023-01-11 16:33:13 +08:00
export default {
2023-07-03 09:16:54 +08:00
data() {
2023-01-11 16:33:13 +08:00
return {
loading: false,
loginType: 'pwd',
pwdForm: {
2023-03-20 08:51:21 +08:00
phone: '',
2023-01-11 16:33:13 +08:00
pwd: '',
imgCode: '',
},
yzmForm: {
phone: '',
code: '',
imgCode: '',
},
waitTime: 0,
tenantId: '',
companyName: '',
}
},
components: {},
methods: {
2023-07-03 09:16:54 +08:00
getCode() {
2023-03-16 15:26:25 +08:00
if (!this.yzmForm.phone) {
return this.$util.toast('请输入手机号!')
}
2023-03-20 08:51:21 +08:00
uni.showLoading({
2023-07-03 09:16:54 +08:00
title: '请稍等',
2023-03-20 08:51:21 +08:00
})
apiGetYms({
2023-03-16 15:26:25 +08:00
phone: this.yzmForm.phone,
type: 0,
})
2023-07-03 09:16:54 +08:00
.then((res) => {
uni.hideLoading()
console.log(res)
this.waitTime = 60
this.inter = setInterval(() => {
if (this.waitTime == 0) {
clearInterval(this.inter)
} else {
this.waitTime--
}
}, 1000)
})
.catch((err) => {
uni.hideLoading()
console.log(err)
})
2023-01-11 16:33:13 +08:00
},
2023-07-03 09:16:54 +08:00
login() {
console.log(this.loginType)
2023-01-11 16:33:13 +08:00
if (this.loginType == 'pwd') {
this.pwdLogin()
} else {
this.yzmLogin()
}
},
2023-07-03 09:16:54 +08:00
pwdLogin() {
2023-03-20 08:51:21 +08:00
if (!this.pwdForm.phone && !this.pwdForm.pwd) {
2023-01-11 16:33:13 +08:00
return this.$util.toast('请填写登录信息!')
}
2023-03-16 15:26:25 +08:00
apiLogin({
2023-03-20 08:51:21 +08:00
phone: this.pwdForm.phone,
key: this.pwdForm.pwd,
2023-03-16 15:26:25 +08:00
type: 1,
2023-07-03 09:16:54 +08:00
}).then((res) => {
console.log(res)
2023-03-16 15:26:25 +08:00
uni.setStorageSync('userInfo', res.data)
uni.reLaunch({
url: '/pages/index/index',
})
2023-01-11 16:33:13 +08:00
})
},
2023-07-03 09:16:54 +08:00
yzmLogin() {
2023-01-11 16:33:13 +08:00
if (!this.yzmForm.phone && !this.yzmForm.code) {
return this.$util.toast('请填写登录信息!')
}
2023-07-03 09:16:54 +08:00
apiYsmLogin({
2023-03-16 15:26:25 +08:00
phone: this.yzmForm.phone,
2023-07-03 09:16:54 +08:00
smsCode: this.yzmForm.code,
}).then((res) => {
console.log(res)
2023-07-03 20:29:24 +08:00
uni.setStorageSync('access_token', res.data.token_type + ' ' + res.data.access_token)
uni.setStorageSync('refresh_token', res.data.refresh_token)
let strings = res.data.access_token.split('.') //截取token获取载体
var userInfo = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, '+').replace(/_/g, '/')))))
userInfo.authorities = userInfo.authorities[0]
uni.setStorageSync('userInfo', userInfo)
2023-03-16 15:26:25 +08:00
uni.reLaunch({
url: '/pages/index/index',
})
2023-01-11 16:33:13 +08:00
})
},
},
2023-07-03 09:16:54 +08:00
onLoad(o) {},
2023-01-11 16:33:13 +08:00
}
</script>
2023-07-03 09:16:54 +08:00
<style lang="scss">
2023-01-11 16:33:13 +08:00
.login {
.login-title {
padding-left: 64rpx;
padding-top: 48rpx;
font-size: 56rpx;
font-weight: 600;
color: #111;
}
.login-des {
padding-left: 64rpx;
margin-top: 12rpx;
font-size: 28rpx;
color: #999;
}
.login-box {
display: flex;
flex-direction: column;
margin: 60rpx auto 0;
box-sizing: border-box;
width: 680rpx;
padding: 100rpx 40rpx;
border-radius: 40rpx;
2023-02-07 17:59:54 +08:00
background: $uni-theme-white;
2023-01-11 16:33:13 +08:00
overflow: hidden;
.login-box-logo {
background: $uni-theme-blue;
height: 100rpx;
width: 100rpx;
margin: 0 auto;
}
.login-box-input {
height: 110rpx;
display: flex;
align-items: center;
border-bottom: 1rpx solid #f0f0f0;
.login-box-input-icon {
width: 40rpx;
margin-right: 40rpx;
}
.login-box-input-main {
font-size: 28rpx;
flex: 1;
height: 100rpx;
line-height: 100rpx;
}
.login-box-input-btn {
width: 200rpx;
margin-left: 40rpx;
background: $uni-theme-blue;
color: #fff;
}
.login-box-input-img {
margin-left: 40rpx;
background: skyblue;
height: 80rpx;
width: 200rpx;
}
}
.login-box-switch {
margin-top: 60rpx;
color: $uni-theme-blue;
font-size: 28rpx;
text-align: center;
}
.login-box-btn {
display: flex;
align-items: center;
justify-content: center;
margin-top: 80rpx;
width: 100%;
background: $uni-theme-blue;
color: #fff;
height: 80rpx;
border-radius: 12rpx;
}
.login-box-footer {
display: flex;
margin-top: 40rpx;
font-size: 28rpx;
color: $uni-theme-blue;
}
.login-box-tips {
margin-top: 60rpx;
display: flex;
justify-content: center;
font-size: 20rpx;
}
}
}
2023-07-03 09:16:54 +08:00
</style>