fix:修改了显示的字符,feat:增加对战列表自动刷新的功能

This commit is contained in:
tsui110 2026-01-05 16:22:53 +08:00
parent 1d2599441e
commit ea7b3e33c0
4 changed files with 69 additions and 4 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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>

View File

@ -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 })
}