|
|
|
@ -2,17 +2,8 @@ |
|
|
|
|
<view class="page"> |
|
|
|
|
<view class="wrap"> |
|
|
|
|
<image class="logo" src="https://eduvessel.com/images/occupationlab/hjyz-logo.png" mode="widthFix"></image> |
|
|
|
|
<template v-if="isLogin"> |
|
|
|
|
<button class="btn phone" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber"> |
|
|
|
|
<!-- <image src="@/static/image/phone.png" mode="widthFix"></image> --> |
|
|
|
|
{{ isReg ? '获取手机号' : '绑定手机'}} |
|
|
|
|
</button> |
|
|
|
|
</template> |
|
|
|
|
<template v-else> |
|
|
|
|
<view class="btn wechat" @click="login"> |
|
|
|
|
快捷登录 |
|
|
|
|
</view> |
|
|
|
|
</template> |
|
|
|
|
<button v-if="isBind" class="btn" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">快捷登录</button> |
|
|
|
|
<button v-else class="btn" @click="toAccounts">快捷登录</button> |
|
|
|
|
|
|
|
|
|
<view class="agree"> |
|
|
|
|
<uni-data-checkbox class="check" multiple v-model="agree" :localdata="agreeData"></uni-data-checkbox> |
|
|
|
@ -34,17 +25,16 @@ |
|
|
|
|
text: '同意', |
|
|
|
|
value: 1 |
|
|
|
|
}], |
|
|
|
|
isLogin: false, // 是否已登录 |
|
|
|
|
isReg: false, // 是否是注册 |
|
|
|
|
sessionKey: '', |
|
|
|
|
openid: '', |
|
|
|
|
unionid: '', |
|
|
|
|
submiting: false |
|
|
|
|
submiting: false, |
|
|
|
|
isBind: false, |
|
|
|
|
accounts: [], |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onShow() { |
|
|
|
|
// uni.setStorageSync('token', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjM5NTc2LCJyblN0ciI6IjZXZUtCNTdOMU9ubGhBSG53RmJwMWN0c3VuVWlyR2l5IiwiYWNjb3VudElkIjozOTU3NiwidXNlcklkIjozOTU3NSwic2Nob29sSWQiOjI4NDYsInVzZXJOYW1lIjoiYWMiLCJwbGF0Zm9ybUlkIjoiMSJ9.hYkjwTUdMMYQLXJVRmqnw3tqRvGndNAzUiVh1ClyCec') |
|
|
|
|
// 先授权用户信息,再授权手机号 |
|
|
|
|
this.checkLogin() |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
@ -54,71 +44,60 @@ |
|
|
|
|
this.toIndex() |
|
|
|
|
} else { |
|
|
|
|
uni.clearStorageSync() |
|
|
|
|
this.isLogin = false |
|
|
|
|
this.isReg = false |
|
|
|
|
this.submiting = false |
|
|
|
|
this.autoLogin() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 授权用户信息 |
|
|
|
|
login() { |
|
|
|
|
this.isReg = false |
|
|
|
|
if (this.agree.length) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const that = this |
|
|
|
|
uni.getUserProfile({ |
|
|
|
|
lang: 'zh_CN', |
|
|
|
|
desc: '登录', |
|
|
|
|
success: ({ userInfo }) => { |
|
|
|
|
uni.login({ |
|
|
|
|
success: async ({ code }) => { |
|
|
|
|
if (code) { |
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
|
|
// 微信小程序登录 |
|
|
|
|
try { |
|
|
|
|
const res = await studentWeChatAppletCallback({ |
|
|
|
|
code, |
|
|
|
|
avatarUrl: userInfo.avatarUrl |
|
|
|
|
}) |
|
|
|
|
const { data, status } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
const e = data.sessionKey |
|
|
|
|
this.sessionKey = e.session_key |
|
|
|
|
this.openid = e.openid |
|
|
|
|
uni.setStorageSync('sessionKey', e.session_key) |
|
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
this.toIndex() |
|
|
|
|
} else { |
|
|
|
|
// 新用户,前往绑定账号页面 |
|
|
|
|
this.isLogin = true |
|
|
|
|
this.isReg = true |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.submiting = false |
|
|
|
|
that.$util.errMsg('登录失败!') |
|
|
|
|
} |
|
|
|
|
// 获取openid等 |
|
|
|
|
autoLogin() { |
|
|
|
|
uni.login({ |
|
|
|
|
success: async ({ code }) => { |
|
|
|
|
if (code) { |
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
|
|
// 微信小程序登录 |
|
|
|
|
try { |
|
|
|
|
const res = await studentWeChatAppletCallback({ |
|
|
|
|
code, |
|
|
|
|
avatarUrl: '' |
|
|
|
|
}) |
|
|
|
|
const { data } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
const e = data.sessionKey |
|
|
|
|
this.sessionKey = e.session_key |
|
|
|
|
this.openid = e.openid |
|
|
|
|
uni.setStorageSync('sessionKey', e.session_key) |
|
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
this.toIndex() |
|
|
|
|
} else if (data.state === 'bind') { |
|
|
|
|
// 注册 |
|
|
|
|
this.isBind = true |
|
|
|
|
} else if (data.data.userAccounts) { |
|
|
|
|
// 多个账号 |
|
|
|
|
this.accounts = JSON.stringify(data.data.userAccounts) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
fail(res) { |
|
|
|
|
that.$util.errMsg('登录授权失败!') |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.submiting = false |
|
|
|
|
that.$util.errMsg('登录失败!') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.$util.errMsg('请先阅读勾选协议!') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
async toAccounts() { |
|
|
|
|
uni.setStorageSync('accounts', this.accounts) |
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}`) |
|
|
|
|
}, |
|
|
|
|
// 绑定手机号 |
|
|
|
|
async onGetPhoneNumber(e){ |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
|
const appId = this.isDy ? 'tt2192572fbea04fe601' : uni.getAccountInfoSync().miniProgram.appId |
|
|
|
|
const appId = uni.getAccountInfoSync().miniProgram.appId |
|
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
|
const decData = pc.decryptData(encryptedData , iv) |
|
|
|
|
this.submiting = true |
|
|
|
@ -131,9 +110,16 @@ |
|
|
|
|
}) |
|
|
|
|
if (data) { |
|
|
|
|
const accounts = data.userAccounts |
|
|
|
|
// 老用户则前往选择账号 |
|
|
|
|
uni.setStorageSync('accounts', JSON.stringify(accounts)) |
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}&phone=${phone}`) |
|
|
|
|
if (accounts) { |
|
|
|
|
// 多个账号则前往选择账号 |
|
|
|
|
uni.setStorageSync('accounts', JSON.stringify(accounts)) |
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}&phone=${phone}`) |
|
|
|
|
} else { |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
uni.switchTab({ |
|
|
|
|
url: '/pages/index/index' |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 新用户则前往绑定账号 |
|
|
|
|
this.$util.to(`/user/reg/reg?openid=${this.openid}&phone=${phone}`) |
|
|
|
@ -180,28 +166,9 @@ |
|
|
|
|
height: 88rpx; |
|
|
|
|
margin-bottom: 50rpx; |
|
|
|
|
font-size: 32rpx; |
|
|
|
|
border-radius: 10rpx; |
|
|
|
|
image { |
|
|
|
|
width: 50rpx; |
|
|
|
|
margin-right: 15rpx; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.wechat { |
|
|
|
|
color: #fff; |
|
|
|
|
background-color: #007EFF; |
|
|
|
|
} |
|
|
|
|
.phone { |
|
|
|
|
color: #007EFF; |
|
|
|
|
border: 1px solid #007EFF; |
|
|
|
|
background-color: #fff; |
|
|
|
|
image { |
|
|
|
|
width: 40rpx; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.reg { |
|
|
|
|
font-size: 28rpx; |
|
|
|
|
color: #e61717; |
|
|
|
|
text-align: right; |
|
|
|
|
border-radius: 10rpx; |
|
|
|
|
} |
|
|
|
|
.agree { |
|
|
|
|
display: flex; |
|
|
|
|