feat(邀请码页面): 修复未绑定别人跳转到自己私聊页的问题
This commit is contained in:
parent
808308b181
commit
cc29b63c79
@ -456,6 +456,7 @@ import {
|
|||||||
getInviteReceiveAward, // 邀请用户领取奖励
|
getInviteReceiveAward, // 邀请用户领取奖励
|
||||||
getMyInviter, // 获取我的邀请人信息
|
getMyInviter, // 获取我的邀请人信息
|
||||||
} from '@/api/invitation.js'
|
} from '@/api/invitation.js'
|
||||||
|
import { connectToApp } from '@/utils/appConnector.js'
|
||||||
|
|
||||||
// vite动态导入图片
|
// vite动态导入图片
|
||||||
const imageModules = import.meta.glob('@/assets/images/InvitationNewUser/*.{png,jpg,svg}', {
|
const imageModules = import.meta.glob('@/assets/images/InvitationNewUser/*.{png,jpg,svg}', {
|
||||||
@ -489,7 +490,7 @@ const inviteAwardPool = ref({})
|
|||||||
const showModule = ref('list') //显示模块
|
const showModule = ref('list') //显示模块
|
||||||
|
|
||||||
const showBindingBt = computed(() => {
|
const showBindingBt = computed(() => {
|
||||||
return !myInviter.myInfo?.expired && !myInviter.inviterInfo
|
return !myInviter.value.myInfo?.expired && !myInviter.value.inviterInfo
|
||||||
})
|
})
|
||||||
|
|
||||||
// 展示遮罩层
|
// 展示遮罩层
|
||||||
@ -615,130 +616,24 @@ const initData = () => {
|
|||||||
apiGetInviteAwardPool() // 邀请用户奖励池
|
apiGetInviteAwardPool() // 邀请用户奖励池
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 使用工具函数连接APP
|
||||||
* 连接APP并获取认证信息(优化版 - 仅专注连接)
|
const connectToAppHandler = async () => {
|
||||||
*/
|
await connectToApp(
|
||||||
const connectToApp = async () => {
|
() => {
|
||||||
console.group('🔗 APP Connection Process')
|
// 连接成功回调
|
||||||
console.debug('🚀 Starting APP connection...')
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 检查是否在APP环境中
|
|
||||||
if (!isInApp()) {
|
|
||||||
console.debug('🌐 Browser environment detected')
|
|
||||||
appConnected.value = true
|
|
||||||
console.groupEnd()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
initData()
|
initData()
|
||||||
|
},
|
||||||
return { success: true, environment: 'browser' }
|
(error) => {
|
||||||
}
|
// 连接失败回调
|
||||||
|
if (error.message && error.message.includes('parse access')) {
|
||||||
// 检查是否已经连接且未过期
|
router.push({ path: '/not_app', query: { message: error.message } })
|
||||||
if (isAppConnected()) {
|
|
||||||
console.debug('✅ APP already connected and valid')
|
|
||||||
appConnected.value = true
|
|
||||||
|
|
||||||
// 使用缓存的头部信息
|
|
||||||
const cachedHeaderInfo = getAppHeaderInfo()
|
|
||||||
if (cachedHeaderInfo) {
|
|
||||||
headerInfo.value = cachedHeaderInfo
|
|
||||||
console.debug('🔧 Using cached HTTP headers')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.groupEnd()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
initData()
|
|
||||||
|
|
||||||
return { success: true, environment: 'app', fromCache: true }
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
// 检查是否有正在进行的连接
|
|
||||||
if (appConnectionManager.isConnecting()) {
|
|
||||||
console.debug('⏳ Connection already in progress, waiting...')
|
|
||||||
await appConnectionManager.getConnectionPromise()
|
|
||||||
appConnected.value = true
|
|
||||||
console.debug('✅ Connected via existing process')
|
|
||||||
console.groupEnd()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
initData()
|
|
||||||
|
|
||||||
return { success: true, environment: 'app', fromCache: true }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 建立新的APP连接
|
|
||||||
console.debug('📱 Establishing new APP connection...')
|
|
||||||
|
|
||||||
const connectionResult = await new Promise((resolve, reject) => {
|
|
||||||
const connectionPromise = new Promise((connectResolve, connectReject) => {
|
|
||||||
connectApplication(async (access) => {
|
|
||||||
try {
|
|
||||||
const result = parseAccessOrigin(access)
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
// 解析头部信息
|
|
||||||
headerInfo.value = parseHeader(result.data)
|
|
||||||
|
|
||||||
// 设置HTTP请求头
|
|
||||||
console.debug('🔧 Setting HTTP headers...')
|
|
||||||
await setHttpHeaders(headerInfo.value)
|
|
||||||
|
|
||||||
// 标记连接成功
|
|
||||||
appConnected.value = true
|
|
||||||
appConnectionManager.setConnected(headerInfo.value)
|
|
||||||
|
|
||||||
console.debug('🎉 APP connection established successfully')
|
|
||||||
connectResolve({ success: true, environment: 'app', fromCache: false })
|
|
||||||
} else {
|
|
||||||
console.error('❌ Failed to parse access origin:', result.error)
|
|
||||||
appConnectionManager.reset()
|
|
||||||
connectReject(new Error(result.error))
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Connection process failed:', error)
|
|
||||||
appConnectionManager.reset()
|
|
||||||
connectReject(error)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// 设置连接状态
|
|
||||||
appConnectionManager.setConnecting(connectionPromise)
|
|
||||||
|
|
||||||
connectionPromise.then(resolve).catch(reject)
|
|
||||||
})
|
|
||||||
|
|
||||||
console.debug('✅ Connection completed successfully')
|
|
||||||
console.groupEnd()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
initData()
|
|
||||||
|
|
||||||
return connectionResult
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Connection failed:', error)
|
|
||||||
appConnected.value = false
|
|
||||||
console.groupEnd()
|
|
||||||
|
|
||||||
// 触发连接失败回调
|
|
||||||
// if (onConnectionFailed) {
|
|
||||||
// onConnectionFailed(error)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 连接失败的特殊处理
|
|
||||||
if (error.message && error.message.includes('parse access')) {
|
|
||||||
router.push({ path: '/not_app', query: { message: error.message } })
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: false, error: error.message }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
connectToApp()
|
connectToAppHandler()
|
||||||
isInAppEnvironment.value = isInApp()
|
isInAppEnvironment.value = isInApp()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user