fix: 修复手机号登录bug

This commit is contained in:
范鹏 2025-03-25 15:08:00 +08:00
parent e7b9056f4c
commit ec5b623940
4 changed files with 133 additions and 69 deletions

View File

@ -447,16 +447,34 @@
if (data.detail.errMsg === 'getPhoneNumber:fail user deny') {
return
}
const result = await this.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv
const that = this
uni.showLoading({
title: '登录中'
})
uni.login({
provider: 'weixin',
async success(loginRes) {
const result = await that.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv,
code: loginRes.code
})
uni.hideLoading()
if (!result) {
uni.showToast({
title: result.message,
icon: 'none'
})
}
},
fail() {
uni.hideLoading()
uni.showToast({
title: '登录失败,请重试'
})
}
})
if (!result) {
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
})
}
},
async nextPage() {
if (this.lockList.length < this.lockTotal) {

View File

@ -143,62 +143,90 @@
if (res.detail.errMsg === 'getPhoneNumber:fail user deny') {
return
}
const result = await this.checkSession()
if (!result) {
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
})
return
}
const openid = getStorage('openid')
const { code, data, message } = await phoneLoginRequest({
encryptedData: res.detail.encryptedData,
iv: res.detail.iv,
rebind: true,
openid
const that = this
uni.showLoading({
title: '登录中'
})
uni.login({
provider: 'weixin',
async success(loginRes) {
const openid = getStorage('openid')
const { code, data, message } = await phoneLoginRequest({
encryptedData: res.detail.encryptedData,
iv: res.detail.iv,
rebind: true,
openid,
js_code: loginRes.code
})
uni.hideLoading()
if (code === 0) {
removeStorage('userInfo')
removeStorage('lockList')
setStorage('token', data.accessToken)
that.updateLockSearch({
...that.lockSearch,
pageNo: 1
})
that.getUserInfo()
that.getLockList(that.lockSearch)
that.updateNotificationSearch({
pageNo: 1
})
that.getNotificationList(that.notificationSearch)
uni.showToast({
title: '账号切换成功',
icon: 'none'
})
} else if (code === 438) {
/* empty */
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
},
fail() {
uni.hideLoading()
uni.showToast({
title: '登录失败,请重试'
})
}
})
if (code === 0) {
removeStorage('userInfo')
removeStorage('lockList')
setStorage('token', data.accessToken)
this.updateLockSearch({
...this.lockSearch,
pageNo: 1
})
this.getUserInfo()
this.getLockList(this.lockSearch)
this.updateNotificationSearch({
pageNo: 1
})
this.getNotificationList(this.notificationSearch)
uni.showToast({
title: '账号切换成功',
icon: 'none'
})
} else if (code === 438) {
/* empty */
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
},
async getphonenumber(data) {
if (data.detail.errMsg === 'getPhoneNumber:fail user deny') {
return
}
const result = await this.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv
const that = this
uni.showLoading({
title: '登录中'
})
uni.login({
provider: 'weixin',
async success(loginRes) {
const result = await that.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv,
code: loginRes.code
})
uni.hideLoading()
if (!result) {
uni.showToast({
title: result.message,
icon: 'none'
})
}
},
fail() {
uni.hideLoading()
uni.showToast({
title: '登录失败,请重试'
})
}
})
if (!result) {
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
})
}
},
toUsereInfo() {
this.routeJump({

View File

@ -157,16 +157,34 @@
if (data.detail.errMsg === 'getPhoneNumber:fail user deny') {
return
}
const result = await this.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv
const that = this
uni.showLoading({
title: '登录中'
})
uni.login({
provider: 'weixin',
async success(loginRes) {
const result = await that.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv,
code: loginRes.code
})
uni.hideLoading()
if (!result) {
uni.showToast({
title: result.message,
icon: 'none'
})
}
},
fail() {
uni.hideLoading()
uni.showToast({
title: '登录失败,请重试'
})
}
})
if (!result) {
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
})
}
},
scroll() {
this.$refs.swipeItem.forEach(item => {

View File

@ -35,12 +35,12 @@ export const useUserStore = defineStore('user', {
return code
},
async phoneLogin(params) {
const { iv, encryptedData } = params
const { iv, encryptedData, code: js_code } = params
const openid = await getStorage('openid')
if (!openid) {
return false
}
const { code, data } = await phoneLoginRequest({ iv, encryptedData, openid })
const { code, data } = await phoneLoginRequest({ iv, encryptedData, openid, js_code })
if (code === 0) {
setStorage('token', data.accessToken)
this.getUserInfo()