|
|
@ -2,8 +2,8 @@ |
|
|
|
<view class="page"> |
|
|
|
<view class="page"> |
|
|
|
<view class="wrap"> |
|
|
|
<view class="wrap"> |
|
|
|
<image class="logo" src="https://eduvessel.com/images/occupationlab/hjyz-logo.png" mode="widthFix"></image> |
|
|
|
<image class="logo" src="https://eduvessel.com/images/occupationlab/hjyz-logo.png" mode="widthFix"></image> |
|
|
|
<button v-if="isBind" class="btn" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">快捷登录</button> |
|
|
|
<button v-if="!agree.length" class="btn"@click="toAccounts">登录</button> |
|
|
|
<button v-else class="btn" @click="toAccounts">快捷登录</button> |
|
|
|
<button v-else class="btn" open-type="getPhoneNumber" @getphonenumber="toAccounts">登录</button> |
|
|
|
|
|
|
|
|
|
|
|
<view class="agree"> |
|
|
|
<view class="agree"> |
|
|
|
<uni-data-checkbox class="check" multiple v-model="agree" :localdata="agreeData"></uni-data-checkbox> |
|
|
|
<uni-data-checkbox class="check" multiple v-model="agree" :localdata="agreeData"></uni-data-checkbox> |
|
|
@ -15,11 +15,12 @@ |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import { studentWeChatAppletCallback, studentBinding, weChatToken } from '@/apis/modules/user.js' |
|
|
|
import { studentWeChatAppletCallback, studentBinding } from '@/apis/modules/user.js' |
|
|
|
import WXBizDataCrypt from '@/libs/WXBizDataCrypt' |
|
|
|
import WXBizDataCrypt from '@/libs/WXBizDataCrypt' |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
|
|
|
|
token: uni.getStorageSync('token'), |
|
|
|
agree: [], |
|
|
|
agree: [], |
|
|
|
agreeData: [{ |
|
|
|
agreeData: [{ |
|
|
|
text: '同意', |
|
|
|
text: '同意', |
|
|
@ -29,37 +30,18 @@ |
|
|
|
openid: '', |
|
|
|
openid: '', |
|
|
|
unionid: '', |
|
|
|
unionid: '', |
|
|
|
submiting: false, |
|
|
|
submiting: false, |
|
|
|
token: '', |
|
|
|
|
|
|
|
isBind: false, |
|
|
|
|
|
|
|
accounts: [], |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
onShow() { |
|
|
|
onShow() { |
|
|
|
const pages = getCurrentPages() |
|
|
|
|
|
|
|
const { options } = pages[pages.length - 1] |
|
|
|
|
|
|
|
this.fromLogout = options.logout || 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.checkLogin() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
|
|
// 检查登录状态 |
|
|
|
|
|
|
|
checkLogin() { |
|
|
|
|
|
|
|
if (uni.getStorageSync('token')) { |
|
|
|
|
|
|
|
this.toIndex() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
uni.clearStorageSync() |
|
|
|
|
|
|
|
this.token = '' |
|
|
|
|
|
|
|
this.isBind = false |
|
|
|
|
|
|
|
this.submiting = false |
|
|
|
this.submiting = false |
|
|
|
this.autoLogin() |
|
|
|
this.autoLogin() |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
// 获取openid等 |
|
|
|
// 获取openid等 |
|
|
|
autoLogin() { |
|
|
|
autoLogin() { |
|
|
|
uni.login({ |
|
|
|
uni.login({ |
|
|
|
success: async ({ code }) => { |
|
|
|
success: async ({ code }) => { |
|
|
|
if (code) { |
|
|
|
if (code) { |
|
|
|
// 微信小程序登录 |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const res = await studentWeChatAppletCallback({ |
|
|
|
const res = await studentWeChatAppletCallback({ |
|
|
|
code, |
|
|
|
code, |
|
|
@ -71,16 +53,6 @@ |
|
|
|
this.openid = e.openid |
|
|
|
this.openid = e.openid |
|
|
|
uni.setStorageSync('sessionKey', e.session_key) |
|
|
|
uni.setStorageSync('sessionKey', e.session_key) |
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
|
|
|
this.token = data.token |
|
|
|
|
|
|
|
} else if (data.state === 'bind') { |
|
|
|
|
|
|
|
// 注册 |
|
|
|
|
|
|
|
this.isBind = true |
|
|
|
|
|
|
|
} else if (data.data.userAccounts) { |
|
|
|
|
|
|
|
// 多个账号 |
|
|
|
|
|
|
|
this.accounts = JSON.stringify(data.data.userAccounts) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
} catch (e) {} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
that.$util.errMsg('登录失败!') |
|
|
|
that.$util.errMsg('登录失败!') |
|
|
@ -88,34 +60,35 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
async toAccounts() { |
|
|
|
async toAccounts(e) { |
|
|
|
if (this.agree.length) { |
|
|
|
if (this.agree.length) { |
|
|
|
if (this.submiting) return false |
|
|
|
if (this.submiting) return false |
|
|
|
this.submiting = true |
|
|
|
this.submiting = true |
|
|
|
if (!this.token) { |
|
|
|
|
|
|
|
uni.setStorageSync('accounts', this.accounts) |
|
|
|
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}`) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
uni.setStorageSync('token', this.token) |
|
|
|
|
|
|
|
this.toIndex() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.$util.errMsg('请先阅读勾选协议!') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 绑定手机号 |
|
|
|
|
|
|
|
async onGetPhoneNumber(e){ |
|
|
|
|
|
|
|
if (this.agree.length) { |
|
|
|
|
|
|
|
if (this.submiting) return false |
|
|
|
|
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
const appId = uni.getAccountInfoSync().miniProgram.appId |
|
|
|
const appId = uni.getAccountInfoSync().miniProgram.appId |
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
const decData = pc.decryptData(encryptedData , iv) |
|
|
|
const decData = pc.decryptData(encryptedData , iv) |
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
const phone = decData.phoneNumber |
|
|
|
const phone = decData.phoneNumber |
|
|
|
uni.setStorageSync('phone', phone) |
|
|
|
uni.setStorageSync('phone', phone) |
|
|
|
// 新用户则前往绑定账号 |
|
|
|
const { data } = await studentBinding({ |
|
|
|
this.$util.to(`/user/reg/reg?openid=${this.openid}&phone=${phone}`) |
|
|
|
openid: this.openid, |
|
|
|
|
|
|
|
phone, |
|
|
|
|
|
|
|
platformId: 1 |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if (data) { |
|
|
|
|
|
|
|
if (data.token) { |
|
|
|
|
|
|
|
// 直接登录成功 |
|
|
|
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
|
|
|
this.toIndex() |
|
|
|
|
|
|
|
} else if (data.userAccounts) { |
|
|
|
|
|
|
|
// 选择账号 |
|
|
|
|
|
|
|
uni.setStorageSync('accounts', JSON.stringify(data.userAccounts)) |
|
|
|
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}`) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 新用户注册 |
|
|
|
|
|
|
|
this.$util.to(`/user/reg/reg`) |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.$util.errMsg('请先阅读勾选协议!') |
|
|
|
this.$util.errMsg('请先阅读勾选协议!') |
|
|
|
} |
|
|
|
} |
|
|
@ -154,9 +127,6 @@ |
|
|
|
margin-bottom: 80rpx; |
|
|
|
margin-bottom: 80rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
.btn { |
|
|
|
.btn { |
|
|
|
display: flex; |
|
|
|
|
|
|
|
justify-content: center; |
|
|
|
|
|
|
|
align-items: center; |
|
|
|
|
|
|
|
width: 100%; |
|
|
|
width: 100%; |
|
|
|
height: 88rpx; |
|
|
|
height: 88rpx; |
|
|
|
margin-bottom: 50rpx; |
|
|
|
margin-bottom: 50rpx; |
|
|
|