This commit is contained in:
lcj
2026-09-11 17:31:59 +08:00
parent dac4260d73
commit b4360ada34
5 changed files with 77 additions and 43 deletions
+16 -4
View File
@@ -80,17 +80,21 @@
})
}
this.initLogin()
uni.$on('authorizationExpired', this.onAuthExpired)
},
onUnload() {
uni.$off('authorizationExpired', this.onAuthExpired)
},
onShow() {
if (this.blocked) return
const openId = uni.getStorageSync('openIdGift')
const isRegisteredGift = uni.getStorageSync('isRegisteredGift')
const userId = uni.getStorageSync('userIdGift')
const auth = uni.getStorageSync('authorizationGift')
this.registered = !!isRegisteredGift
if (openId && (!isRegisteredGift || !userId)) {
if (openId && (!auth || !isRegisteredGift || !userId)) {
this.loginWithOpenId(openId)
}
if (isRegisteredGift && userId) {
} else if (isRegisteredGift && userId) {
this.fetchUserResult()
}
},
@@ -174,8 +178,13 @@
console.error('请求失败', err)
})
},
onAuthExpired() {
const openId = uni.getStorageSync('openIdGift')
if (openId) this.loginWithOpenId(openId)
},
loginWithOpenId(openId) {
return this.$u.api.wxOpenidLogin({ wenjuan_id: 1003, open_id: openId }).then(loginRes => {
if (this._loginPromise) return this._loginPromise
this._loginPromise = this.$u.api.wxOpenidLogin({ wenjuan_id: 1003, open_id: openId }).then(loginRes => {
if (!loginRes.Data) {
uni.setStorageSync('isRegisteredGift', false)
this.registered = false
@@ -191,7 +200,10 @@
}
}).catch(err => {
console.error('登录请求失败', err)
}).finally(() => {
this._loginPromise = null
})
return this._loginPromise
},
toPrize() {
uni.navigateTo({