diff --git a/src/api/API.js b/src/api/API.js index 42e6bc5..d9632d6 100644 --- a/src/api/API.js +++ b/src/api/API.js @@ -1,19 +1,19 @@ -import request from "../utils/request"; -const APIurl = import.meta.env.VITE_APP_API_BASE_URL; -// 开发环境使用代理,生产环境使用环境变量 -// const APIurl = import.meta.env.DEV ? '/Api' : import.meta.env.VITE_APP_API_BASE_URL; +// import request from "../utils/request"; +// const APIurl = import.meta.env.VITE_APP_API_BASE_URL; +// // 开发环境使用代理,生产环境使用环境变量 +// // const APIurl = import.meta.env.DEV ? '/Api' : import.meta.env.VITE_APP_API_BASE_URL; -export function addRecordAPI(data) { - return request({ - url: `Api/api/funding/addRecord`, - method: 'post', - data: data - }) -} -// 新增:获取活动信息接口 -export function getActivity1API() { - return request({ - url: `Api/api/funding/getActivity1`, - method: 'post' - }) -} \ No newline at end of file +// export function addRecordAPI(data) { +// return request({ +// url: `Api/api/funding/addRecord`, +// method: 'post', +// data: data +// }) +// } +// // 新增:获取活动信息接口 +// export function getActivity1API() { +// return request({ +// url: `Api/api/funding/getActivity1`, +// method: 'post' +// }) +// } \ No newline at end of file diff --git a/src/views/zhongchou/index.vue b/src/views/zhongchou/index.vue index f6012b0..311fa33 100644 --- a/src/views/zhongchou/index.vue +++ b/src/views/zhongchou/index.vue @@ -128,7 +128,9 @@ import { ref, computed, onMounted, nextTick, watch } from 'vue' // 活动时间显示 const activityPeriod = ref('加载中...') - +// 添加响应式变量存储活动ID和市场ID +const activityId = ref(null) +const usMarketId = ref(null) // 格式化日期函数 const formatDate = (dateString) => { if (!dateString) return '' @@ -145,8 +147,13 @@ async function fetchActivity() { const response = await getActivity1API() if (response.code === 200) { console.log('活动数据:', response.data) + // 处理返回的数据 - const { startTime, endTime, marketTwoStatus, marketTwoCount } = response.data + const { activityId: id, data, startTime, endTime, totalcount } = response.data + + // 存储活动ID + activityId.value = id + if (startTime && endTime) { const formattedStartTime = formatDate(startTime) const formattedEndTime = formatDate(endTime) @@ -155,27 +162,46 @@ async function fetchActivity() { activityPeriod.value = '时间待定' } - // 根据marketTwoStatus设置助力状态 - if (marketTwoStatus === '已助力') { - usBoostStatus.value = true - } else { - usBoostStatus.value = false - } - - // 根据marketTwoCount计算进度和剩余时间 - if (marketTwoCount !== undefined) { - const totalPeople = 1500 // 总人数1500人 - const currentCount = marketTwoCount || 0 // 当前助力人数 - - // 计算进度百分比 (0-100) - const progressPercent = Math.min((currentCount / totalPeople) * 100, 100) - - // 根据进度计算剩余时间 (15分钟对应100%进度) - const usedTime = (progressPercent / 100) * 15 - const remainingTime = Math.max(0, 15 - usedTime) - - usRemainingTime.value = Math.round(remainingTime) - console.log(`助力人数: ${currentCount}/${totalPeople}, 进度: ${progressPercent.toFixed(1)}%, 剩余时间: ${remainingTime.toFixed(1)}分钟`) + // 处理市场数据 + if (data && data.length > 0) { + // 遍历数据数组 + data.forEach(item => { + if (item.market === "美股" && item.marketId === 8) { + // 存储美股市场ID + usMarketId.value = item.marketId + + // 根据marketStatus设置助力状态 + if (item.marketStatus === '已助力') { + usBoostStatus.value = true + } else { + usBoostStatus.value = false + } + + // 根据marketCount计算进度和剩余时间 + if (item.marketCount !== undefined) { + const totalPeople = 1500 // 总人数1500人 + const currentCount = item.marketCount || 0 // 当前助力人数 + + // 计算进度百分比 (0-100) + const progressPercent = Math.min((currentCount / totalPeople) * 100, 100) + + // 根据进度计算剩余时间 (15分钟对应100%进度) + const usedTime = (progressPercent / 100) * 15 + const remainingTime = Math.max(0, 15 - usedTime) + + usRemainingTime.value = Math.round(remainingTime) + console.log(`美股助力人数: ${currentCount}/${totalPeople}, 进度: ${progressPercent.toFixed(1)}%, 剩余时间: ${remainingTime.toFixed(1)}分钟`) + + // 更新进度条高度 + nextTick(() => { + updateProgressDisplay() + }) + } + } + + // 如果需要处理港股数据,可以添加类似的逻辑 + // if (item.market === "港股" && item.marketId === 5) { ... } + }) } } else { console.error('获取活动失败:', response.message) @@ -186,6 +212,8 @@ async function fetchActivity() { activityPeriod.value = '网络错误' } } + + const numberToChinese = (num) => { const chineseNumbers = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五'] return chineseNumbers[num] || num.toString() @@ -290,7 +318,7 @@ onMounted(() => { // 添加窗口大小改变监听 window.addEventListener('resize', () => { nextTick(() => { - updateProgressBarHeight() + updateProgressBarHeight() }) }) }) @@ -308,17 +336,23 @@ onMounted(() => { const handleBoostClick = async (area) => { if (area === 'us' && !usBoostStatus.value) { try { - // 调用助力API + // 检查是否已获取到活动ID和市场ID + if (!activityId.value || !usMarketId.value) { + console.error('活动ID或市场ID未获取,请先获取活动数据') + return + } + + // 调用助力API,使用动态获取的值 const response = await addRecordAPI({ - "activityId": 41,//需要动态获取,没有上线前问后端要id - "marketSign": 5 + "activityId": activityId.value, + "marketSign": usMarketId.value }); if (response.code === 200) { console.log('美股助力成功:', response.message) // 重新获取活动数据以更新按钮状态和进度 await fetchActivity() - console.log('美股已助力,剩余时间:', usRemainingTime.value) + console.log('美股已助力状态:', usBoostStatus.value, '剩余时间:', usRemainingTime.value) } else { console.error('美股助力失败:', response.message) } @@ -326,27 +360,7 @@ const handleBoostClick = async (area) => { console.error('美股助力请求失败:', error) } } - // else if (area === 'hk' && !hkBoostStatus.value) { - // try { - // // 调用助力API - // const response = await addRecordAPI({ - // "activityId": 1, - // "marketSign": 5 - // }); - - // if (response.code === 200) { - // hkBoostStatus.value = true - // // 助力后减少1分钟时间 - // simulateTimeDecrease('hk') - // console.log('港股助力成功:', response.message) - // console.log('港股已助力,剩余时间:', hkRemainingTime.value) - // } else { - // console.error('港股助力失败:', response.message) - // } - // } catch (error) { - // console.error('港股助力请求失败:', error) - // } - // } + // ... existing code ... } const showRulesFunc = () => { @@ -994,7 +1008,7 @@ const hideRules = () => { } */ @media (max-width: 768px) { - + /* 平板端周年庆装饰元素 */ .anniversary-decoration { width: 40vw; @@ -1006,6 +1020,7 @@ const hideRules = () => { background-image: url('@/assets/img/zhongchou/手机周年庆装饰.png'); /* 需要准备此图片资源 */ } + .main-title img { max-height: 60px; }