ai-watch-app/pages/login/login.vue

226 lines
5.4 KiB
Vue

<template>
<view class="login">
<view class="flx flx_jc flx_ac" v-if="login_type == 0" style="height: 100vh;">
<view class="">
<!-- <view class="header">
<image src="https://img.agrimedia.cn/watch-app/logo.jpeg"></image>
</view> -->
<view class="flx flx_jc ">
<uqrcode v-if="qrCode" ref="uqrcode" canvas-id="qrcode" :value="qrCode" :options="{ margin: 10 }"></uqrcode>
<view class="flx flx_ac" v-else style="width: 200px;height: 200px;border: 2rpx #000 dashed;border-radius: 10rpx;">
<view class="" style="text-align: center; width: 100%;">
{{qrCodeMsg}}
</view>
</view>
</view>
<view class="">
<wButton
class="wbutton"
text="刷新二维码"
:rotate="isRotate"
@click="getLoginCode"
></wButton>
</view>
<view class="footer">
<view class="" @click="doLoginType(1)">
密码登录
</view>
<text>|</text>
<navigator url="register" open-type="navigate">注册账号</navigator>
</view>
</view>
</view>
<view class="content" v-if="login_type == 1">
<!-- 返回 -->
<tm-nav-bar left-icon="arrow-left" title="登陆账号" @clickLeft="back" />
<!-- 头部logo -->
<view class="header">
<image src="../../static/a-ziyuan85.png"></image>
</view>
<!-- 主体表单 -->
<view class="main">
<wInput
v-model="phoneData"
type="text"
maxlength="11"
placeholder="用户名/电话"
:focus="isFocus"
></wInput>
<wInput
v-model="passData"
type="password"
maxlength="9999"
placeholder="密码"
></wInput>
</view>
<wButton
class="wbutton"
text="登 录"
:rotate="isRotate"
@click="startLogin"
></wButton>
<!-- 底部信息 -->
<view class="footer">
<navigator url="forget" open-type="navigate">找回密码</navigator>
<text>|</text>
<navigator url="register" open-type="navigate">注册账号</navigator>
<text>|</text>
<view class="" @click="doLoginType(0)">
扫码登录
</view>
</view>
</view>
</view>
</template>
<script>
let _this;
import store from "@/store/index.js";
import wInput from '../../components/watch-login/watch-input.vue' //input
import wButton from '../../components/watch-login/watch-button.vue' //button
export default {
data() {
return {
qrCodeMsg:'加载中...',
qrCode:'',
qrCodeVal:'',
login_type:0,
phoneData:'', //用户/电话
passData:'', //密码
isRotate: false, //是否加载旋转
isFocus: true // 是否聚焦
};
},
watch(){
},
onLoad() {
let token = this.$store.getters['api/getApiToken']
if(token){
uni.navigateTo({
url: '/pages/index/index'
})
}
if(this.login_type == 0){
this.getLoginCode()
}
},
components:{
wInput,
wButton,
},
mounted() {
_this= this;
},
methods: {
back() {
uni.navigateTo({
url: '/pages/index/index'
})
},
doLoginType(type){
this.login_type = type
if(type == 0){
this.qrCodeMsg = '加载中...'
this.qrCode = ''
this.getLoginCode()
}else{
this.qrCodeMsg = '加载中...'
this.qrCode = ''
}
},
getLoginCode(){
this.$store.dispatch('api/getLoginCode').then(res => {
this.qrCode = 'https://ai.agrimedia.cn/qrcodeLogin/index?qrcode=' + res.key
this.qrCodeVal = res.key
setTimeout(() => {
this.qrCode = '';
this.qrCodeMsg = '二维码已过期'
},55000)
this.checkQrCode()
})
},
checkQrCode(){
if(this.qrCode){
setTimeout(() => {
this.$store.dispatch('api/checkLoginCode',{
key:this.qrCodeVal
}).then(res => {
if(res.status == 0){
this.checkQrCode()
}
if(res.status == 1){
this.$store.commit('api/setApiToken',res.token)
uni.reLaunch({
url: '/pages/index/index'
})
}
})
},1000)
// this.$store.dispatch('api/checkLoginCode',{
// key:this.qrCodeVal
// }).then(res => {
// if(res.status == 0){
// setTimeout(this.checkQrCode(),2000)
// }
// if(res.status == 1){
// this.$store.commit('api/setApiToken',res.token)
// console.log('123')
// uni.reLaunch({
// url: '/pages/index/index'
// })
// }
// //
// })
}
},
startLogin(e){
//登录
if(this.isRotate){
//判断是否加载中,避免重复点击请求
return false;
}
if (this.phoneData == "") {
uni.showToast({
icon: 'none',
position: 'bottom',
title: '账号不能为空'
});
return;
}
if (this.passData == "") {
uni.showToast({
icon: 'none',
position: 'bottom',
title: '密码不能为空'
});
return;
}
uni.showLoading({
title: '登录中'
});
this.$store.dispatch('api/dologin', { mobile: this.phoneData, password: this. passData }).then(res => {
if (res.token) {
this.$store.commit('api/setApiToken',res.token)
console.log('123')
uni.reLaunch({
url: '/pages/index/index'
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
@import url("../../components/watch-login/css/icon.css");
@import url("./css/main.css");
</style>