更新 Vite 配置以使用 localhost,新增游戏完成时间戳和过期判断,优化链接生成逻辑,调整路由以支持路径参数,改进游戏界面状态显示
This commit is contained in:
@@ -37,7 +37,9 @@ export function usePlayState() {
|
||||
machineId: null,
|
||||
qrCreatedAt: null,
|
||||
qrExpireAt: null,
|
||||
qrDelayTimeoutId: null
|
||||
qrDelayTimeoutId: null,
|
||||
completedAt: null,
|
||||
isCompletedExpired: false
|
||||
})
|
||||
|
||||
const initializePage = async () => {
|
||||
@@ -148,6 +150,25 @@ export function usePlayState() {
|
||||
|
||||
state.status = 'COMPLETED'
|
||||
|
||||
// 保存完成时间戳
|
||||
if (gameData.completedAt) {
|
||||
state.completedAt = gameData.completedAt
|
||||
|
||||
// 判断是否超过24小时
|
||||
const now = Math.floor(Date.now() / 1000) // 当前时间戳(秒)
|
||||
const completedTime = gameData.completedAt
|
||||
const hoursPassed = (now - completedTime) / 3600 // 转换为小时
|
||||
|
||||
state.isCompletedExpired = hoursPassed > 24
|
||||
|
||||
console.log('完成时间判断:', {
|
||||
completedAt: completedTime,
|
||||
now: now,
|
||||
hoursPassed: hoursPassed.toFixed(2),
|
||||
isExpired: state.isCompletedExpired
|
||||
})
|
||||
}
|
||||
|
||||
// 更新区域和机器信息
|
||||
if (gameData.region) {
|
||||
state.region = gameData.region
|
||||
@@ -181,6 +202,8 @@ export function usePlayState() {
|
||||
totalPoints: state.totalPoints,
|
||||
completedPoints: state.completedPoints,
|
||||
currentPoints: state.currentPoints,
|
||||
completedAt: state.completedAt,
|
||||
isCompletedExpired: state.isCompletedExpired,
|
||||
assets: !!state.assets
|
||||
})
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ export const LINK_CONFIG = {
|
||||
|
||||
// 链接地址模板
|
||||
getLinkUrl: (codeNo) => {
|
||||
return `${LINK_CONFIG.BASE_URL}${LINK_CONFIG.GAME_PATH}?${LINK_CONFIG.CODE_PARAM}=${codeNo}`
|
||||
// 生成随机参数:时间戳 + 随机字符串
|
||||
const timestamp = Date.now()
|
||||
const random = Math.random().toString(36).substring(2, 8)
|
||||
const randomParam = `${timestamp}${random}`
|
||||
return `${LINK_CONFIG.BASE_URL}${LINK_CONFIG.GAME_PATH}/${codeNo}?t=${randomParam}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ const NotFound = () => import('@/views/NotFound.vue')
|
||||
|
||||
export const routes = [
|
||||
{ path: '/login', name: 'Login', component: Login, meta: { public: true, title: '登录' } },
|
||||
{ path: '/play', name: 'Play', component: Play, meta: { public: true, title: '上号任务' } },
|
||||
{ path: '/play/:code', name: 'Play', component: Play, meta: { public: true, title: '上号任务' } },
|
||||
{ path: '/play', name: 'PlayLegacy', component: Play, meta: { public: true, title: '上号任务' } },
|
||||
{
|
||||
path: '/',
|
||||
component: AdminLayout,
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
<!-- 游戏界面 -->
|
||||
<GamePage
|
||||
v-else-if="state.status === 'LOGGED_IN'"
|
||||
v-else-if="state.status === 'LOGGED_IN' || (state.status === 'COMPLETED' && !state.isCompletedExpired)"
|
||||
:region="state.region"
|
||||
:region-desc="state.regionDesc"
|
||||
:machine-id="state.machineId"
|
||||
@@ -47,8 +47,8 @@
|
||||
:code-no="state.code"
|
||||
/>
|
||||
|
||||
<!-- 完成状态 -->
|
||||
<div v-else-if="state.status === 'COMPLETED'" class="completed-page">
|
||||
<!-- 完成状态(超过24小时) -->
|
||||
<div v-else-if="state.status === 'COMPLETED' && state.isCompletedExpired" class="completed-page">
|
||||
<div class="completed-text">已打完</div>
|
||||
</div>
|
||||
|
||||
@@ -141,7 +141,8 @@ export default {
|
||||
} = useQrCode()
|
||||
|
||||
onMounted(() => {
|
||||
const code = route.query.code
|
||||
// 兼容两种方式:路径参数和查询参数
|
||||
const code = route.params.code || route.query.code
|
||||
if (!code) {
|
||||
state.error = 'INVALID_CODE'
|
||||
state.loading = false
|
||||
|
||||
@@ -27,7 +27,8 @@ export default defineConfig({
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:18080',
|
||||
// target: 'https://uzi1.cn/api',
|
||||
target: 'http://localhost:18080',
|
||||
changeOrigin: true,
|
||||
rewrite: (p) => p.replace(/^\/api/, ''),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user