Merge branch 'fanpeng' into 'develop'

fix: 修复手机号登录bug

See merge request StarlockTeam/wx-starlock!33
This commit is contained in:
刘燕峰 2025-03-25 10:44:56 +00:00
commit 5fbfa56826
4 changed files with 133 additions and 69 deletions

View File

@ -447,17 +447,35 @@
if (data.detail.errMsg === 'getPhoneNumber:fail user deny') { if (data.detail.errMsg === 'getPhoneNumber:fail user deny') {
return return
} }
const result = await this.phoneLogin({
encryptedData: data.detail.encryptedData, const that = this
iv: data.detail.iv 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) { if (!result) {
uni.showToast({ uni.showToast({
title: '登录失败,请重试', title: result.message,
icon: 'none' icon: 'none'
}) })
} }
}, },
fail() {
uni.hideLoading()
uni.showToast({
title: '登录失败,请重试'
})
}
})
},
async nextPage() { async nextPage() {
if (this.lockList.length < this.lockTotal) { if (this.lockList.length < this.lockTotal) {
const sreach = { const sreach = {

View File

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

View File

@ -157,17 +157,35 @@
if (data.detail.errMsg === 'getPhoneNumber:fail user deny') { if (data.detail.errMsg === 'getPhoneNumber:fail user deny') {
return return
} }
const result = await this.phoneLogin({
encryptedData: data.detail.encryptedData, const that = this
iv: data.detail.iv 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) { if (!result) {
uni.showToast({ uni.showToast({
title: '登录失败,请重试', title: result.message,
icon: 'none' icon: 'none'
}) })
} }
}, },
fail() {
uni.hideLoading()
uni.showToast({
title: '登录失败,请重试'
})
}
})
},
scroll() { scroll() {
this.$refs.swipeItem.forEach(item => { this.$refs.swipeItem.forEach(item => {
if (item.show) { if (item.show) {

View File

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