feat: token失效问题修复
This commit is contained in:
parent
37089cad06
commit
62f9d8f6db
@ -151,3 +151,25 @@ export const withdrawApply = async (data) => {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 可提现金额转账给指定用户
|
||||||
|
export const transferActivityDollar = async (data) => {
|
||||||
|
try {
|
||||||
|
const response = await post('/activity/lottery/transfer', data)
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch transfer activity dollar:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 可提现金额兑换金币
|
||||||
|
export const exchangeCoin = async (data) => {
|
||||||
|
try {
|
||||||
|
const response = await post('/activity/lottery/exchange', data)
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch exchange coin:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -289,7 +289,7 @@
|
|||||||
v-for="coin in coinOptions"
|
v-for="coin in coinOptions"
|
||||||
:key="coin.id"
|
:key="coin.id"
|
||||||
@click="selectCoin(coin)"
|
@click="selectCoin(coin)"
|
||||||
:class="['coin-item', { selected: selectedCoin === coin.id }]"
|
:class="['coin-item', { selected: selectedCoin.id === coin.id }]"
|
||||||
>
|
>
|
||||||
<img src="/src/assets/icon/dollar.png" alt="" style="width: 40%" />
|
<img src="/src/assets/icon/dollar.png" alt="" style="width: 40%" />
|
||||||
<div style="font-weight: 500; color: #131111">${{ coin.price }}</div>
|
<div style="font-weight: 500; color: #131111">${{ coin.price }}</div>
|
||||||
@ -310,7 +310,7 @@
|
|||||||
font-weight: 590;
|
font-weight: 590;
|
||||||
"
|
"
|
||||||
@click="transfer"
|
@click="transfer"
|
||||||
:disabled="!selectedCoin || !selectedPayee.value?.id"
|
:disabled="!selectedCoin || !selectedPayee.value.id"
|
||||||
>
|
>
|
||||||
Transfer
|
Transfer
|
||||||
</div>
|
</div>
|
||||||
@ -349,7 +349,7 @@
|
|||||||
v-for="coin in coinOptions"
|
v-for="coin in coinOptions"
|
||||||
:key="coin.id"
|
:key="coin.id"
|
||||||
@click="selectCoin(coin)"
|
@click="selectCoin(coin)"
|
||||||
:class="['coin-item', { selected: selectedCoin === coin.id }]"
|
:class="['coin-item', { selected: selectedCoin.id == coin.id }]"
|
||||||
>
|
>
|
||||||
<img src="/src/assets/icon/coin.png" alt="" style="width: 40%" />
|
<img src="/src/assets/icon/coin.png" alt="" style="width: 40%" />
|
||||||
<div style="font-size: 0.7em">{{ coin.amount }} coins x1</div>
|
<div style="font-size: 0.7em">{{ coin.amount }} coins x1</div>
|
||||||
@ -370,7 +370,7 @@
|
|||||||
background: linear-gradient(135deg, #bb92ff 2.82%, #8b45ff 99.15%);
|
background: linear-gradient(135deg, #bb92ff 2.82%, #8b45ff 99.15%);
|
||||||
font-weight: 590;
|
font-weight: 590;
|
||||||
"
|
"
|
||||||
:disabled="!selectedCoin || !selectedPayee.value?.id"
|
:disabled="!selectedCoin.id || !selectedPayee.value?.id"
|
||||||
>
|
>
|
||||||
Exchange
|
Exchange
|
||||||
</div>
|
</div>
|
||||||
@ -850,6 +850,8 @@ import {
|
|||||||
receiveTickets, // 领取任务奖励
|
receiveTickets, // 领取任务奖励
|
||||||
winnerHistory, //获取历史中奖用户
|
winnerHistory, //获取历史中奖用户
|
||||||
withdrawableAmount, //获取可提现金额
|
withdrawableAmount, //获取可提现金额
|
||||||
|
transferActivityDollar, // 转账活动美金
|
||||||
|
exchangeCoin, //兑换代币
|
||||||
} from '@/api/lottery'
|
} from '@/api/lottery'
|
||||||
import Barrage from '@/components/Lottery/Barrage.vue'
|
import Barrage from '@/components/Lottery/Barrage.vue'
|
||||||
|
|
||||||
@ -986,10 +988,10 @@ const coinOptions = ref([
|
|||||||
//选择金币
|
//选择金币
|
||||||
const selectCoin = (coin) => {
|
const selectCoin = (coin) => {
|
||||||
// 单选逻辑:如果已经选中相同的金币,则取消选择;否则选中新的金币
|
// 单选逻辑:如果已经选中相同的金币,则取消选择;否则选中新的金币
|
||||||
if (selectedCoin.value === coin.id) {
|
if (selectedCoin.value.id === coin.id) {
|
||||||
selectedCoin.value = null
|
selectedCoin.value = null
|
||||||
} else {
|
} else {
|
||||||
selectedCoin.value = coin.id
|
selectedCoin.value = coin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1005,18 +1007,9 @@ const transfer = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedCoinData = coinOptions.find((coin) => coin.id === selectedCoin.value)
|
|
||||||
|
|
||||||
// 获取支付密码
|
|
||||||
// const password = prompt('Please enter your payment password:')
|
|
||||||
// if (!password) {
|
|
||||||
// showError('Payment password is required')
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 构造请求参数
|
// 构造请求参数
|
||||||
const transferData = {
|
const transferData = {
|
||||||
amount: selectedCoinData.price,
|
amount: selectedCoin.value.price,
|
||||||
acceptUserId: selectedPayee.value?.id,
|
acceptUserId: selectedPayee.value?.id,
|
||||||
acceptMethod: 'BANK_TRANSFER',
|
acceptMethod: 'BANK_TRANSFER',
|
||||||
// password: password
|
// password: password
|
||||||
@ -1214,7 +1207,7 @@ const connectToApp = async () => {
|
|||||||
console.groupEnd()
|
console.groupEnd()
|
||||||
|
|
||||||
// 触发连接成功回调
|
// 触发连接成功回调
|
||||||
getUserInfo()
|
initData() // 页面初始化数据
|
||||||
|
|
||||||
return { success: true, environment: 'browser' }
|
return { success: true, environment: 'browser' }
|
||||||
}
|
}
|
||||||
@ -1234,7 +1227,7 @@ const connectToApp = async () => {
|
|||||||
console.groupEnd()
|
console.groupEnd()
|
||||||
|
|
||||||
// 触发连接成功回调
|
// 触发连接成功回调
|
||||||
getUserInfo()
|
initData() // 页面初始化数据
|
||||||
|
|
||||||
return { success: true, environment: 'app', fromCache: true }
|
return { success: true, environment: 'app', fromCache: true }
|
||||||
}
|
}
|
||||||
@ -1248,7 +1241,7 @@ const connectToApp = async () => {
|
|||||||
console.groupEnd()
|
console.groupEnd()
|
||||||
|
|
||||||
// 触发连接成功回调
|
// 触发连接成功回调
|
||||||
getUserInfo()
|
initData() // 页面初始化数据
|
||||||
|
|
||||||
return { success: true, environment: 'app', fromCache: true }
|
return { success: true, environment: 'app', fromCache: true }
|
||||||
}
|
}
|
||||||
@ -1299,7 +1292,7 @@ const connectToApp = async () => {
|
|||||||
console.groupEnd()
|
console.groupEnd()
|
||||||
|
|
||||||
// 触发连接成功回调
|
// 触发连接成功回调
|
||||||
getUserInfo()
|
initData() // 页面初始化数据
|
||||||
|
|
||||||
return connectionResult
|
return connectionResult
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -1417,9 +1410,9 @@ const receiveTaskReward = async (code) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
// 页面初始化数据
|
||||||
connectToApp()
|
const initData = () => {
|
||||||
isInAppEnvironment.value = isInApp()
|
getUserInfo() //获取用户信息
|
||||||
initializePayee() //获取收款人信息
|
initializePayee() //获取收款人信息
|
||||||
getRanking() //获取排行榜
|
getRanking() //获取排行榜
|
||||||
getActivityDetail() //获取奖池
|
getActivityDetail() //获取奖池
|
||||||
@ -1427,6 +1420,11 @@ onMounted(() => {
|
|||||||
getTickets() //获取拥有的抽奖券
|
getTickets() //获取拥有的抽奖券
|
||||||
getTaskList() //获取任务列表
|
getTaskList() //获取任务列表
|
||||||
getWinners() //获取历史中奖用户
|
getWinners() //获取历史中奖用户
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
connectToApp()
|
||||||
|
isInAppEnvironment.value = isInApp()
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|||||||
@ -205,7 +205,7 @@
|
|||||||
);
|
);
|
||||||
"
|
"
|
||||||
></div>
|
></div>
|
||||||
<div style="font-weight: 590; font-size: 0.85em">Remaining time</div>
|
<div style="font-weight: 590; font-size: 0.82em">Remaining time</div>
|
||||||
<div
|
<div
|
||||||
style="
|
style="
|
||||||
width: 1px;
|
width: 1px;
|
||||||
@ -218,7 +218,7 @@
|
|||||||
"
|
"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<div style="flex: 1; font-weight: 590; text-align: end; font-size: 0.85em">
|
<div style="flex: 1; font-weight: 590; text-align: end; font-size: 0.82em">
|
||||||
Prowide income
|
Prowide income
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -505,128 +505,6 @@ const copyCode = (text) => {
|
|||||||
}, 2000)
|
}, 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 连接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()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
// getUserInfo()
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
// getUserInfo()
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
// getUserInfo()
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
// 触发连接成功回调
|
|
||||||
// getUserInfo()
|
|
||||||
|
|
||||||
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 confirmInvitationCode = () => {
|
const confirmInvitationCode = () => {
|
||||||
if (!invitationCode.value.trim()) {
|
if (!invitationCode.value.trim()) {
|
||||||
@ -696,14 +574,139 @@ const receiveAward = async (awardId) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
// 页面初始化数据
|
||||||
connectToApp()
|
const initData = () => {
|
||||||
isInAppEnvironment.value = isInApp()
|
|
||||||
|
|
||||||
apiGetMyInviteCode() // 获取我的邀请码
|
apiGetMyInviteCode() // 获取我的邀请码
|
||||||
apiGetMyInviteIncome() // 获取收益统计
|
apiGetMyInviteIncome() // 获取收益统计
|
||||||
apiGetMyInviteUsers() // 有效邀请用户列表
|
apiGetMyInviteUsers() // 有效邀请用户列表
|
||||||
apiGetInviteAwardPool() // 邀请用户奖励池
|
apiGetInviteAwardPool() // 邀请用户奖励池
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
connectToApp()
|
||||||
|
isInAppEnvironment.value = isInApp()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user