NurseStationPersonAppletUl/pages/login/login.vue

87 lines
1.9 KiB
Vue
Raw Normal View History

2023-03-28 10:02:47 +08:00
<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 {
2023-04-04 17:14:06 +08:00
getPersonWeChatUserInfo,
2023-03-28 10:02:47 +08:00
createMobileToken
} from '@/api/login/index.js'
export default {
data() {
return {
2023-04-04 17:14:06 +08:00
phonecode: '',
logincode: '',
timer: null,
2023-03-28 10:02:47 +08:00
};
},
//获取到传值
2023-04-04 17:14:06 +08:00
onLoad(options) {},
2023-03-28 10:02:47 +08:00
methods: {
2023-04-04 17:14:06 +08:00
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();
}
});
}
},
2023-03-28 10:02:47 +08:00
login() {
2023-04-04 17:14:06 +08:00
getPersonWeChatUserInfo(this.logincode, this.phonecode).then(res => {
2023-03-28 10:02:47 +08:00
if (res.code == 200) {
2023-04-10 16:31:11 +08:00
if (res.data.personRoleLoginFlag == 'nursePersonRole') {
uni.setStorageSync("nursePersonId", res.data.nurseStationPersonId)
}
2023-04-06 15:52:19 +08:00
uni.setStorageSync("personRoleLoginFlag", res.data.personRoleLoginFlag)
2023-04-10 16:40:18 +08:00
uni.setStorageSync("phone", res.data.phone)
2023-04-04 17:14:06 +08:00
this.$refs.uToast.show({
2023-03-28 10:02:47 +08:00
title: '登录成功',
type: 'success',
duration: '1500'
})
2023-04-04 17:14:06 +08:00
if (this.timer) {
clearTimeout(this.timer)
}
this.timer = setTimeout(e => {
uni.navigateBack({
delta: 1
2023-03-28 10:02:47 +08:00
})
2023-04-04 17:14:06 +08:00
}, 500)
2023-03-28 10:02:47 +08:00
} else {
2023-04-04 17:14:06 +08:00
this.$refs.uToast.show({
title: '登录失败',
type: 'error',
duration: '1500'
2023-03-28 10:02:47 +08:00
})
}
})
},
pwdlogin() {
2023-04-04 17:14:06 +08:00
uni.removeStorageSync('token');
2023-03-28 10:02:47 +08:00
var that = this
createMobileToken().then(res => {
uni.setStorageSync("token", res.data.token)
2023-04-04 17:14:06 +08:00
that.login()
2023-03-28 10:02:47 +08:00
})
},
},
}
</script>
<style lang="scss">
@import './login.scss';
</style>