|
|
|
@ -26,7 +26,7 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import { login, userBinding, getSessionKey, queryPartnerAccount, douYinLogin, douYinLoginByOpenid } from '@/apis/modules/user.js' |
|
|
|
|
import { login, userBinding, getSessionKey, queryPartnerAccount, douYinLogin, douYinLoginByOpenid, douYinUserBinding } from '@/apis/modules/user.js' |
|
|
|
|
import WXBizDataCrypt from '@/libs/WXBizDataCrypt' |
|
|
|
|
export default { |
|
|
|
|
data() { |
|
|
|
@ -75,40 +75,37 @@ |
|
|
|
|
if (code) { |
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
|
|
let fn = login |
|
|
|
|
let param = { |
|
|
|
|
code, |
|
|
|
|
avatarUrl: userInfo.avatarUrl |
|
|
|
|
} |
|
|
|
|
// 抖音登录 |
|
|
|
|
if (this.isDy) { |
|
|
|
|
fn = douYinLogin |
|
|
|
|
param = code |
|
|
|
|
const res1 = await douYinLoginByOpenid('_000P6jr9bt8gW0ySNSzGsNBnCB0er4KtN3M') |
|
|
|
|
uni.setStorageSync('token', res1.data.token) |
|
|
|
|
this.toIndex() |
|
|
|
|
// fn(param).then(async res => { |
|
|
|
|
// const { data, status } = res |
|
|
|
|
// this.submiting = false |
|
|
|
|
// this.sessionKey = data.sessionKey |
|
|
|
|
// this.openid = data.openid |
|
|
|
|
// this.unionid = data.unionid |
|
|
|
|
// uni.setStorageSync('sessionKey', data.sessionKey) |
|
|
|
|
// uni.setStorageSync('openid', data.openid) |
|
|
|
|
try { |
|
|
|
|
const res = await douYinLogin(code) |
|
|
|
|
const { data, status } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
this.sessionKey = data.sessionKey |
|
|
|
|
this.openid = data.openid |
|
|
|
|
this.unionid = data.unionid |
|
|
|
|
uni.setStorageSync('sessionKey', data.sessionKey) |
|
|
|
|
uni.setStorageSync('openid', data.openid) |
|
|
|
|
|
|
|
|
|
// const res1 = await douYinLoginByOpenid('_000P6jr9bt8gW0ySNSzGsNBnCB0er4KtN3M') |
|
|
|
|
// // 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
// // if (data.state === 'login') { |
|
|
|
|
// // this.toIndex() |
|
|
|
|
// // uni.setStorageSync('token', data.token) |
|
|
|
|
// // } else { |
|
|
|
|
// // this.isLogin = true |
|
|
|
|
// // } |
|
|
|
|
// }).catch(e => { |
|
|
|
|
// this.submiting = false |
|
|
|
|
// }) |
|
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
this.toIndex() |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
} else { |
|
|
|
|
fn(param).then((res) => { |
|
|
|
|
this.isLogin = true |
|
|
|
|
// this.isReg = true |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 微信小程序登录 |
|
|
|
|
try { |
|
|
|
|
const res = await login({ |
|
|
|
|
code, |
|
|
|
|
avatarUrl: userInfo.avatarUrl |
|
|
|
|
}) |
|
|
|
|
const { data, status } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
// 用户不存在,则让用户授权手机号,直接去注册 |
|
|
|
@ -141,11 +138,10 @@ |
|
|
|
|
this.isLogin = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}).catch(e => { |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.submiting = false |
|
|
|
|
that.$util.errMsg('登录失败!') |
|
|
|
@ -162,14 +158,12 @@ |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 绑定手机号 |
|
|
|
|
onGetPhoneNumber(e){ |
|
|
|
|
async onGetPhoneNumber(e){ |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
|
// 获取手机号有两种方法,1.前端使用js完成;2.使用接口完成 (抖音) |
|
|
|
|
const appId = this.isDy ? 'tt2192572fbea04fe601' : uni.getAccountInfoSync().miniProgram.appId |
|
|
|
|
console.log(1121, appId, this.sessionKey) |
|
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
|
console.log(22, pc, encryptedData, e) |
|
|
|
|
const data = pc.decryptData(encryptedData , iv) |
|
|
|
|
this.submiting = true |
|
|
|
|
const phone = data.phoneNumber |
|
|
|
@ -177,12 +171,14 @@ |
|
|
|
|
this.submiting = false |
|
|
|
|
this.$util.to(`../reg/reg?openid=${this.openid}&phone=${phone}`) |
|
|
|
|
} else { // 登录绑定手机号 |
|
|
|
|
userBinding({ |
|
|
|
|
try { |
|
|
|
|
const fn = this.isDy ? douYinUserBinding : userBinding |
|
|
|
|
const res = await fn({ |
|
|
|
|
openid: this.openid, |
|
|
|
|
phone, |
|
|
|
|
unionid: this.unionid, |
|
|
|
|
platformId: 4 |
|
|
|
|
}).then(res => { |
|
|
|
|
}) |
|
|
|
|
const { token, status } = res |
|
|
|
|
if (status == 10014) { |
|
|
|
|
// 这里需要再调一次uni的login,因为code用过了一次,已经失效了 |
|
|
|
@ -203,13 +199,13 @@ |
|
|
|
|
uni.setStorageSync('token', token) |
|
|
|
|
this.toIndex() |
|
|
|
|
} |
|
|
|
|
}).catch(e => { |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: e.message, |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 注册申请授权 |
|
|
|
@ -221,7 +217,6 @@ |
|
|
|
|
lang: 'zh_CN', |
|
|
|
|
desc: '登录', |
|
|
|
|
success: ({ userInfo }) => { |
|
|
|
|
console.log(22, userInfo) |
|
|
|
|
uni.setStorageSync('userName', userInfo.nickName) |
|
|
|
|
uni.setStorageSync('avatar', userInfo.avatarUrl) |
|
|
|
|
uni.login({ |
|
|
|
@ -231,12 +226,10 @@ |
|
|
|
|
getSessionKey({ |
|
|
|
|
code, |
|
|
|
|
}).then(({ sessionKey }) => { |
|
|
|
|
console.log(11, sessionKey) |
|
|
|
|
this.sessionKey = sessionKey.session_key |
|
|
|
|
this.openid = sessionKey.openid |
|
|
|
|
this.submiting = false |
|
|
|
|
this.isLogin = true |
|
|
|
|
|
|
|
|
|
}).catch(e => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
@ -256,7 +249,7 @@ |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
toAgreement(id) { |
|
|
|
|
this.$util.openFile(id) |
|
|
|
|
this.$util.to(id ? `/order/privacyAgreement/privacyAgreement` : `/order/serviceAgreement/serviceAgreement`) |
|
|
|
|
}, |
|
|
|
|
// 跳转到首页 |
|
|
|
|
toIndex() { |
|
|
|
|