fix:修改了显示的字符,feat:增加对战列表自动刷新的功能
This commit is contained in:
parent
1d2599441e
commit
ea7b3e33c0
@ -5,7 +5,7 @@
|
||||
<view class="header">
|
||||
<text class="title">实时对战信号</text>
|
||||
<view class="refresh-text-btn" :class="{ loading: loading }" @tap="loadRooms">
|
||||
{{ loading ? '同步中...' : '刷新信号' }}
|
||||
{{ loading ? '同步中...' : `刷新信号 (${countdown}s)` }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
<view class="page">
|
||||
<view class="bg-decoration"></view>
|
||||
<view class="loading" v-if="loading">加载中...</view>
|
||||
<view v-else-if="isOutOfStock" class="empty">商品库存不足,由于市场价格存在波动,请联系客服核实价格和补充库存</view>
|
||||
<view v-else-if="detail.id" class="detail-wrap">
|
||||
<image v-if="detail.main_image" class="main-image" :src="detail.main_image" mode="widthFix" />
|
||||
<view class="info-card">
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@
|
||||
<view class="thumb-wrap">
|
||||
<image class="product-thumb" :src="p.image" mode="aspectFill" lazy-load="true" />
|
||||
<view class="stock-tag" v-if="p.stock !== null && p.stock < 10 && p.stock > 0">仅剩{{p.stock}}件</view>
|
||||
<view class="stock-tag out" v-else-if="p.stock === 0">已罄</view>
|
||||
<view class="stock-tag out" v-else-if="p.stock === 0">售罄</view>
|
||||
</view>
|
||||
<view class="product-info">
|
||||
<text class="product-title">{{ p.title }}</text>
|
||||
|
||||
@ -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 })
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user