weizong song 1 week ago
parent 3ccced9c01
commit 9d39f58d25

@ -5,8 +5,13 @@
import wx from 'jweixin-module' import wx from 'jweixin-module'
// #endif // #endif
export default { export default {
onLaunch: function() { data() {
return {
h5LoginInFlight: false
}
},
onLaunch: function() {
console.log('App Launch') console.log('App Launch')
// //
// #ifdef H5 // #ifdef H5
@ -151,13 +156,18 @@
}) })
}, },
// H5 // H5
wxH5AuthLogin() { wxH5AuthLogin() {
// if (this.h5LoginInFlight) {
const isWeixinBrowser = /MicroMessenger/i.test(navigator.userAgent) console.log('[App] 登录流程进行中,跳过重复调用')
if (!isWeixinBrowser) { return
console.log('[App] 非微信环境,跳过登录') }
return
//
const isWeixinBrowser = /MicroMessenger/i.test(navigator.userAgent)
if (!isWeixinBrowser) {
console.log('[App] 非微信环境,跳过登录')
return
} }
// token // token
@ -199,12 +209,14 @@
console.error('[App] 提取 code 失败:', e) console.error('[App] 提取 code 失败:', e)
} }
console.log('[App] 提取到的 code:', code) console.log('[App] 提取到的 code:', code)
if (code) { if (code) {
// URL code this.h5LoginInFlight = true
try {
const url = new URL(link) // URL code
try {
const url = new URL(link)
url.searchParams.delete('code') url.searchParams.delete('code')
url.searchParams.delete('state') url.searchParams.delete('state')
// 使 replaceState URL // 使 replaceState URL
@ -235,12 +247,15 @@
uni.showToast({ title: result.errmsg || '登录失败', icon: 'none' }) uni.showToast({ title: result.errmsg || '登录失败', icon: 'none' })
} }
}, },
fail: (err) => { fail: (err) => {
console.error('[App] 获取 token 失败:', err) console.error('[App] 获取 token 失败:', err)
uni.showToast({ title: '网络错误,请重试', icon: 'none' }) uni.showToast({ title: '网络错误,请重试', icon: 'none' })
} },
}) complete: () => {
} else { this.h5LoginInFlight = false
}
})
} else {
// code // code
console.log('[App] 未找到 code跳转到授权页面') console.log('[App] 未找到 code跳转到授权页面')
const appId = 'wx9538bc740fe87fce' const appId = 'wx9538bc740fe87fce'

Loading…
Cancel
Save