feat(抽奖活动页): 使用新的获取请求头工具类

This commit is contained in:
hzj 2025-11-03 15:22:24 +08:00
parent c1897088db
commit 5c142dd374

View File

@ -822,21 +822,10 @@
</template>
<script setup>
import {
connectApplication,
parseAccessOrigin,
parseHeader,
setHttpHeaders,
isInApp,
} from '@/utils/appBridge.js'
import {
appConnectionManager,
isAppConnected,
getAppHeaderInfo,
} from '@/utils/appConnectionManager.js'
import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue'
import { isInApp } from '@/utils/appBridge.js'
import { connectToApp } from '@/utils/appConnector.js'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import maskLayer from '@/components/MaskLayer.vue'
import { useDebounce, useThrottle } from '@/utils/useDebounce'
import { formatUTCCustom } from '@/utils/utcFormat.js'
import { getMemberProfile, getUserIdentity } from '@/api/wallet'
import { getSelectedPayee, clearSelectedPayee } from '@/utils/payeeStore.js'
@ -1224,128 +1213,6 @@ const getUserInfo = async () => {
}
}
/**
* 连接APP并获取认证信息优化版 - 仅专注连接
*/
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() //
return { success: true, environment: 'browser' }
}
//
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 }
}
}
//
const getRanking = async () => {
const resRanking = await ranklist()
@ -1451,9 +1318,16 @@ const initData = () => {
getTaskList() //
getWinners() //
}
// 使APP
const connectToAppHandler = async () => {
await connectToApp(() => {
//
initData()
})
}
onMounted(() => {
connectToApp()
connectToAppHandler()
isInAppEnvironment.value = isInApp()
})