diff --git a/composables/useRewards.js b/composables/useRewards.js
index 6e89d36..04e08ad 100644
--- a/composables/useRewards.js
+++ b/composables/useRewards.js
@@ -5,7 +5,6 @@ import { ref, computed, watch } from 'vue'
import { getActivityIssueRewards } from '@/api/appUser'
import { normalizeRewards, groupRewardsByLevel } from '@/utils/activity'
import { cleanUrl } from '@/utils/format'
-import { getRewardCacheItem, setRewardCache, isFresh } from '@/utils/cache'
/**
* 奖励数据管理
@@ -27,27 +26,15 @@ export function useRewards(activityIdRef, currentIssueIdRef) {
})
/**
- * 获取多期的奖励数据(带缓存)
+ * 获取多期的奖励数据 (无缓存)
* @param {Array} issueList - 期列表
*/
async function fetchRewardsForIssues(issueList) {
const activityId = activityIdRef?.value || activityIdRef
if (!activityId) return
- const list = issueList || []
- const toFetch = []
-
- // 先从缓存加载
- list.forEach(issue => {
- const cached = getRewardCacheItem(activityId, issue.id)
- if (cached) {
- rewardsMap.value = { ...rewardsMap.value, [issue.id]: cached }
- } else {
- toFetch.push(issue)
- }
- })
-
- if (!toFetch.length) return
+ const toFetch = issueList || []
+ if (toFetch.length === 0) return
loading.value = true
try {
@@ -59,7 +46,6 @@ export function useRewards(activityIdRef, currentIssueIdRef) {
if (!issueId) return
const value = res.status === 'fulfilled' ? normalizeRewards(res.value, cleanUrl) : []
rewardsMap.value = { ...rewardsMap.value, [issueId]: value }
- setRewardCache(activityId, issueId, value)
})
} catch (e) {
console.error('fetchRewardsForIssues error', e)
@@ -76,19 +62,12 @@ export function useRewards(activityIdRef, currentIssueIdRef) {
const activityId = activityIdRef?.value || activityIdRef
if (!activityId || !issueId) return
- // 先检查缓存
- const cached = getRewardCacheItem(activityId, issueId)
- if (cached) {
- rewardsMap.value = { ...rewardsMap.value, [issueId]: cached }
- return
- }
loading.value = true
try {
const res = await getActivityIssueRewards(activityId, issueId)
const value = normalizeRewards(res, cleanUrl)
rewardsMap.value = { ...rewardsMap.value, [issueId]: value }
- setRewardCache(activityId, issueId, value)
} catch (e) {
console.error('fetchRewardsForIssue error', e)
} finally {
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 3c60c3c..ef46839 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -135,7 +135,8 @@ export default {
banners: [],
activities: [],
selectedGroupName: '',
- bannerIndex: 0
+ bannerIndex: 0,
+ isHomeLoading: false
}
},
computed: {
@@ -169,24 +170,15 @@ export default {
return Array.isArray(this.activities) ? this.activities : []
}
},
- onShow() {
- const token = uni.getStorageSync('token')
- const phoneBound = !!uni.getStorageSync('phone_bound')
- if (!token || !phoneBound) {
- uni.showModal({
- title: '提示',
- content: '请先登录并绑定手机号',
- confirmText: '去登录',
- success: (res) => {
- if (res.confirm) {
- uni.navigateTo({ url: '/pages/login/index' })
- }
- }
- })
- }
- try { console.log('home onShow', { token: !!token, phoneBound }) } catch (_) {}
+ onLoad() {
this.loadHomeData()
},
+ onShow() {
+ // 只有非首次进入或数据为空时才触发刷新,避免 onLoad/onShow 双重触发
+ if (this.activities.length === 0 && !this.isHomeLoading) {
+ this.loadHomeData()
+ }
+ },
methods: {
onBannerChange(e) {
this.bannerIndex = e.detail.current
@@ -256,28 +248,23 @@ export default {
return parts.join(' · ')
},
async loadHomeData() {
- // Notices
+ if (this.isHomeLoading) return
+ this.isHomeLoading = true
+ // 同时发起请求,大幅提升首屏加载速度
try {
- const nData = await this.apiGet('/api/app/notices')
- this.notices = this.normalizeNotices(nData)
- } catch (e) {
- this.notices = []
- }
+ const [nData, bData, acData] = await Promise.all([
+ this.apiGet('/api/app/notices').catch(() => null),
+ this.apiGet('/api/app/banners').catch(() => null),
+ this.apiGet('/api/app/activities').catch(() => null)
+ ])
- // Banners
- try {
- const bData = await this.apiGet('/api/app/banners')
- this.banners = this.normalizeBanners(bData)
+ if (nData) this.notices = this.normalizeNotices(nData)
+ if (bData) this.banners = this.normalizeBanners(bData)
+ if (acData) this.activities = this.normalizeActivities(acData)
} catch (e) {
- this.banners = []
- }
-
- // Activities
- try {
- const acData = await this.apiGet('/api/app/activities')
- this.activities = this.normalizeActivities(acData)
- } catch (e) {
- this.activities = []
+ console.error('Home data load failed', e)
+ } finally {
+ this.isHomeLoading = false
}
},
onBannerTap(b) {
diff --git a/pages/login/index.vue b/pages/login/index.vue
index c9e93f0..604d37b 100644
--- a/pages/login/index.vue
+++ b/pages/login/index.vue
@@ -1,105 +1,85 @@
-
-
-
-
+
+
+
-
-
+
+
-
-
+
+
- 开启欧气之旅 ✨
+ 获取手机号
+
+ 为保障您的权益并提供精准的发货服务,我们需要获取您的手机号码作为登录标识。
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
- ✓
-
- 记住密码
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 登录即代表同意 用户协议 & 隐私政策
+
+
+
+
+ ✓
+
+
+ 我已阅读并同意 《用户协议》 和 《隐私政策》
+
- {{ error }}
+
+
diff --git a/pages/shop/detail.vue b/pages/shop/detail.vue
index 05aaf35..ce1b93e 100644
--- a/pages/shop/detail.vue
+++ b/pages/shop/detail.vue
@@ -8,7 +8,7 @@
{{ detail.title || detail.name || '-' }}
- {{ detail.points_required || (detail.price ? Math.floor(detail.price / 100) : 0) }}
+ {{ (detail.points_required ? Math.floor(detail.points_required / 100) : 0) || (detail.price ? Math.floor(detail.price / 100) : 0) }}
积分
@@ -74,7 +74,7 @@ async function onRedeem() {
return
}
- const points = detail.value.points_required || (detail.value.price ? Math.floor(detail.value.price / 100) : 0)
+ const points = (detail.value.points_required ? Math.floor(detail.value.points_required / 100) : 0) || (detail.value.price ? Math.floor(detail.value.price / 100) : 0)
uni.showModal({
title: '确认兑换',
content: `是否消耗 ${points} 积分兑换 ${p.title || p.name}?`,
diff --git a/pages/shop/index.vue b/pages/shop/index.vue
index e9e87cf..1e9a9e7 100644
--- a/pages/shop/index.vue
+++ b/pages/shop/index.vue
@@ -143,7 +143,7 @@ function normalizeItems(list, kind) {
image: cleanUrl(i.main_image || i.image || ''),
title: i.name || i.title || '',
price: i.price || i.discount_value || 0,
- points: i.points_required || (i.price ? Math.floor(i.price / 100) : (i.discount_value ? Math.floor(i.discount_value / 100) : 0)),
+ points: i.points_required ? Math.floor(i.points_required / 100) : (i.price ? Math.floor(i.price / 100) : (i.discount_value ? Math.floor(i.discount_value / 100) : 0)),
stock: i.in_stock ? 99 : 0, // Simplified stock check if returned as bool
discount_value: i.discount_value || 0,
min_spend: i.min_spend || 0,
diff --git a/static/logo.png b/static/logo.png
index b5771e2..d8ab0d3 100644
Binary files a/static/logo.png and b/static/logo.png differ