diff --git a/pages-game/game/minesweeper/room-list.vue b/pages-game/game/minesweeper/room-list.vue index ee264f1..8fcdeec 100644 --- a/pages-game/game/minesweeper/room-list.vue +++ b/pages-game/game/minesweeper/room-list.vue @@ -5,7 +5,7 @@ 实时对战信号 - {{ loading ? '同步中...' : '刷新信号' }} + {{ loading ? '同步中...' : `刷新信号 (${countdown}s)` }} @@ -66,7 +66,10 @@ export default { isRefreshing: false, gameToken: '', nakamaServer: '', - nakamaKey: '' + nakamaKey: '', + refreshInterval: null, + countdownInterval: null, + countdown: 5 } }, onLoad(options) { @@ -74,6 +77,30 @@ export default { this.nakamaServer = decodeURIComponent(options.nakama_server || ''); this.nakamaKey = decodeURIComponent(options.nakama_key || ''); this.initAndLoad(); + + // 启动倒计时定时器,每秒更新一次 + this.countdownInterval = setInterval(() => { + this.countdown--; + if (this.countdown <= 0) { + this.countdown = 5; + } + }, 1000); + + // 启动自动刷新定时器,每5秒刷新一次 + this.refreshInterval = setInterval(() => { + this.loadRooms(); + }, 5000); + }, + onUnload() { + // 清理定时器 + if (this.refreshInterval) { + clearInterval(this.refreshInterval); + this.refreshInterval = null; + } + if (this.countdownInterval) { + clearInterval(this.countdownInterval); + this.countdownInterval = null; + } }, methods: { async initAndLoad() { @@ -95,6 +122,8 @@ export default { try { const res = await nakamaManager.rpc('list_matches', {}); this.rooms = res || []; + // 重置倒计时 + this.countdown = 5; } catch (e) { console.error('Failed to load rooms', e); } finally { diff --git a/pages-shop/shop/detail.vue b/pages-shop/shop/detail.vue index 5ddb87f..e9f3b6c 100644 --- a/pages-shop/shop/detail.vue +++ b/pages-shop/shop/detail.vue @@ -2,6 +2,7 @@ 加载中... + 商品库存不足,由于市场价格存在波动,请联系客服核实价格和补充库存 @@ -43,6 +44,7 @@ import { redeemProductByPoints } from '../../utils/request.js' const detail = ref({}) const loading = ref(false) +const isOutOfStock = ref(false) function formatPrice(p) { if (p === undefined || p === null) return '0.00' @@ -51,11 +53,34 @@ function formatPrice(p) { async function fetchDetail(id) { loading.value = true + isOutOfStock.value = false try { const res = await getProductDetail(id) detail.value = res || {} + console.log(detail.value); + if (detail.value.code === 20002 || detail.value.message === '商品缺货') { + // 商品缺货时标记状态,这样页面会显示缺货提示而不是"商品不存在" + // request.js 中已经会弹出提示窗口 + isOutOfStock.value = true + console.log('[商品详情] 商品缺货') + } } catch (e) { - detail.value = {} + + // 检查是否是商品缺货错误 (code: 20002) + const errorCode = e?.data?.code || e?.code + const errorMessage = e?.data?.message || e?.message || e?.msg + + if (errorCode === 20002 || errorMessage === '商品缺货') { + // 商品缺货时标记状态,这样页面会显示缺货提示而不是"商品不存在" + // request.js 中已经会弹出提示窗口 + isOutOfStock.value = true + console.log('[商品详情] 商品缺货') + } else { + // 其他错误才清空并显示"商品不存在" + detail.value = {} + console.log('[商品详情] 错误信息:', e) + uni.showToast({ title: errorMessage || '加载失败', icon: 'none' }) + } } finally { loading.value = false } diff --git a/pages/shop/index.vue b/pages/shop/index.vue index d7239f6..1214b93 100644 --- a/pages/shop/index.vue +++ b/pages/shop/index.vue @@ -84,7 +84,7 @@ 仅剩{{p.stock}}件 - 已罄 + 售罄 {{ p.title }} diff --git a/utils/request.js b/utils/request.js index d94781c..24e5ccb 100644 --- a/utils/request.js +++ b/utils/request.js @@ -40,6 +40,17 @@ export function request({ url, method = 'GET', data = {}, header = {} }) { handleAuthExpired() } } + + // 检查是否是商品缺货错误 (code: 20002) + // 仅当是商品详情接口时才弹窗 + if (res.data && res.data.code === 20002 && url.startsWith('/api/app/products/')) { + uni.showModal({ + title: '商品库存不足', + content: '当前商品库存不足,由于市场价格存在波动请联系客服核对价格,补充库存。', + showCancel: false + }) + } + const msg = (res.data && (res.data.message || res.data.msg)) || '请求错误' reject({ message: msg, statusCode: code, data: res.data }) }