87 lines
1.9 KiB
Vue
87 lines
1.9 KiB
Vue
<template>
|
|
<view class="app">
|
|
<view class="title">
|
|
<image src="../../static/logo.png" mode=""></image>
|
|
<view class="text">
|
|
泉医到家
|
|
</view>
|
|
</view>
|
|
<button class="loginbtn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumberp">微信一键登录</button>
|
|
<u-toast ref="uToast" />
|
|
</view>
|
|
</template>
|
|
<script>
|
|
import {
|
|
getPersonWeChatUserInfo,
|
|
createMobileToken
|
|
} from '@/api/login/index.js'
|
|
export default {
|
|
data() {
|
|
return {
|
|
phonecode: '',
|
|
logincode: '',
|
|
timer: null,
|
|
};
|
|
},
|
|
//获取到传值
|
|
onLoad(options) {},
|
|
methods: {
|
|
getPhoneNumberp(val) {
|
|
let that = this;
|
|
if (val.detail.code) {
|
|
that.phonecode = val.detail.code
|
|
wx.login({
|
|
provider: 'weixin',
|
|
success: function(loginRes) {
|
|
that.logincode = loginRes.code
|
|
that.pwdlogin();
|
|
}
|
|
});
|
|
}
|
|
},
|
|
login() {
|
|
getPersonWeChatUserInfo(this.logincode, this.phonecode).then(res => {
|
|
if (res.code == 200) {
|
|
if (res.data.personRoleLoginFlag == 'nursePersonRole') {
|
|
uni.setStorageSync("nursePersonId", res.data.nurseStationPersonId)
|
|
}
|
|
uni.setStorageSync("personRoleLoginFlag", res.data.personRoleLoginFlag)
|
|
uni.setStorageSync("phone", res.data.phone)
|
|
this.$refs.uToast.show({
|
|
title: '登录成功',
|
|
type: 'success',
|
|
duration: '1500'
|
|
})
|
|
if (this.timer) {
|
|
clearTimeout(this.timer)
|
|
}
|
|
this.timer = setTimeout(e => {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
}, 500)
|
|
} else {
|
|
this.$refs.uToast.show({
|
|
title: '登录失败',
|
|
type: 'error',
|
|
duration: '1500'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
pwdlogin() {
|
|
uni.removeStorageSync('token');
|
|
var that = this
|
|
createMobileToken().then(res => {
|
|
uni.setStorageSync("token", res.data.token)
|
|
that.login()
|
|
})
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import './login.scss';
|
|
</style>
|