diff --git a/src/api/lottery.js b/src/api/lottery.js
index 272911b..e715b7d 100644
--- a/src/api/lottery.js
+++ b/src/api/lottery.js
@@ -151,3 +151,25 @@ export const withdrawApply = async (data) => {
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
+ }
+}
diff --git a/src/views/Activities/Lottery/Lottery.vue b/src/views/Activities/Lottery/Lottery.vue
index fe40234..772b32a 100644
--- a/src/views/Activities/Lottery/Lottery.vue
+++ b/src/views/Activities/Lottery/Lottery.vue
@@ -289,7 +289,7 @@
v-for="coin in coinOptions"
:key="coin.id"
@click="selectCoin(coin)"
- :class="['coin-item', { selected: selectedCoin === coin.id }]"
+ :class="['coin-item', { selected: selectedCoin.id === coin.id }]"
>
${{ coin.price }}
@@ -310,7 +310,7 @@
font-weight: 590;
"
@click="transfer"
- :disabled="!selectedCoin || !selectedPayee.value?.id"
+ :disabled="!selectedCoin || !selectedPayee.value.id"
>
Transfer
@@ -349,7 +349,7 @@
v-for="coin in coinOptions"
:key="coin.id"
@click="selectCoin(coin)"
- :class="['coin-item', { selected: selectedCoin === coin.id }]"
+ :class="['coin-item', { selected: selectedCoin.id == coin.id }]"
>
{{ coin.amount }} coins x1
@@ -370,7 +370,7 @@
background: linear-gradient(135deg, #bb92ff 2.82%, #8b45ff 99.15%);
font-weight: 590;
"
- :disabled="!selectedCoin || !selectedPayee.value?.id"
+ :disabled="!selectedCoin.id || !selectedPayee.value?.id"
>
Exchange
@@ -850,6 +850,8 @@ import {
receiveTickets, // 领取任务奖励
winnerHistory, //获取历史中奖用户
withdrawableAmount, //获取可提现金额
+ transferActivityDollar, // 转账活动美金
+ exchangeCoin, //兑换代币
} from '@/api/lottery'
import Barrage from '@/components/Lottery/Barrage.vue'
@@ -986,10 +988,10 @@ const coinOptions = ref([
//选择金币
const selectCoin = (coin) => {
// 单选逻辑:如果已经选中相同的金币,则取消选择;否则选中新的金币
- if (selectedCoin.value === coin.id) {
+ if (selectedCoin.value.id === coin.id) {
selectedCoin.value = null
} else {
- selectedCoin.value = coin.id
+ selectedCoin.value = coin
}
}
@@ -1005,18 +1007,9 @@ const transfer = async () => {
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 = {
- amount: selectedCoinData.price,
+ amount: selectedCoin.value.price,
acceptUserId: selectedPayee.value?.id,
acceptMethod: 'BANK_TRANSFER',
// password: password
@@ -1214,7 +1207,7 @@ const connectToApp = async () => {
console.groupEnd()
// 触发连接成功回调
- getUserInfo()
+ initData() // 页面初始化数据
return { success: true, environment: 'browser' }
}
@@ -1234,7 +1227,7 @@ const connectToApp = async () => {
console.groupEnd()
// 触发连接成功回调
- getUserInfo()
+ initData() // 页面初始化数据
return { success: true, environment: 'app', fromCache: true }
}
@@ -1248,7 +1241,7 @@ const connectToApp = async () => {
console.groupEnd()
// 触发连接成功回调
- getUserInfo()
+ initData() // 页面初始化数据
return { success: true, environment: 'app', fromCache: true }
}
@@ -1299,7 +1292,7 @@ const connectToApp = async () => {
console.groupEnd()
// 触发连接成功回调
- getUserInfo()
+ initData() // 页面初始化数据
return connectionResult
} catch (error) {
@@ -1417,9 +1410,9 @@ const receiveTaskReward = async (code) => {
}
}
-onMounted(() => {
- connectToApp()
- isInAppEnvironment.value = isInApp()
+// 页面初始化数据
+const initData = () => {
+ getUserInfo() //获取用户信息
initializePayee() //获取收款人信息
getRanking() //获取排行榜
getActivityDetail() //获取奖池
@@ -1427,6 +1420,11 @@ onMounted(() => {
getTickets() //获取拥有的抽奖券
getTaskList() //获取任务列表
getWinners() //获取历史中奖用户
+}
+
+onMounted(() => {
+ connectToApp()
+ isInAppEnvironment.value = isInApp()
})
onUnmounted(() => {
diff --git a/src/views/Invitation/InvitationToRegister.vue b/src/views/Invitation/InvitationToRegister.vue
index 20807d5..18e4528 100644
--- a/src/views/Invitation/InvitationToRegister.vue
+++ b/src/views/Invitation/InvitationToRegister.vue
@@ -205,7 +205,7 @@
);
"
>
- Remaining time
+ Remaining time
-
@@ -505,128 +505,6 @@ const copyCode = (text) => {
}, 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 = () => {
if (!invitationCode.value.trim()) {
@@ -696,14 +574,139 @@ const receiveAward = async (awardId) => {
}
}
-onMounted(() => {
- connectToApp()
- isInAppEnvironment.value = isInApp()
-
+// 页面初始化数据
+const initData = () => {
apiGetMyInviteCode() // 获取我的邀请码
apiGetMyInviteIncome() // 获取收益统计
apiGetMyInviteUsers() // 有效邀请用户列表
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()
})