weizong song 6 days ago
parent 3ccced9c01
commit 9d39f58d25

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

Loading…
Cancel
Save