更新 Vite 配置以使用 localhost,新增游戏完成时间戳和过期判断,优化链接生成逻辑,调整路由以支持路径参数,改进游戏界面状态显示
This commit is contained in:
@@ -37,7 +37,9 @@ export function usePlayState() {
|
|||||||
machineId: null,
|
machineId: null,
|
||||||
qrCreatedAt: null,
|
qrCreatedAt: null,
|
||||||
qrExpireAt: null,
|
qrExpireAt: null,
|
||||||
qrDelayTimeoutId: null
|
qrDelayTimeoutId: null,
|
||||||
|
completedAt: null,
|
||||||
|
isCompletedExpired: false
|
||||||
})
|
})
|
||||||
|
|
||||||
const initializePage = async () => {
|
const initializePage = async () => {
|
||||||
@@ -148,6 +150,25 @@ export function usePlayState() {
|
|||||||
|
|
||||||
state.status = 'COMPLETED'
|
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) {
|
if (gameData.region) {
|
||||||
state.region = gameData.region
|
state.region = gameData.region
|
||||||
@@ -181,6 +202,8 @@ export function usePlayState() {
|
|||||||
totalPoints: state.totalPoints,
|
totalPoints: state.totalPoints,
|
||||||
completedPoints: state.completedPoints,
|
completedPoints: state.completedPoints,
|
||||||
currentPoints: state.currentPoints,
|
currentPoints: state.currentPoints,
|
||||||
|
completedAt: state.completedAt,
|
||||||
|
isCompletedExpired: state.isCompletedExpired,
|
||||||
assets: !!state.assets
|
assets: !!state.assets
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ export const LINK_CONFIG = {
|
|||||||
|
|
||||||
// 链接地址模板
|
// 链接地址模板
|
||||||
getLinkUrl: (codeNo) => {
|
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 = [
|
export const routes = [
|
||||||
{ path: '/login', name: 'Login', component: Login, meta: { public: true, title: '登录' } },
|
{ 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: '/',
|
path: '/',
|
||||||
component: AdminLayout,
|
component: AdminLayout,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<!-- 游戏界面 -->
|
<!-- 游戏界面 -->
|
||||||
<GamePage
|
<GamePage
|
||||||
v-else-if="state.status === 'LOGGED_IN'"
|
v-else-if="state.status === 'LOGGED_IN' || (state.status === 'COMPLETED' && !state.isCompletedExpired)"
|
||||||
:region="state.region"
|
:region="state.region"
|
||||||
:region-desc="state.regionDesc"
|
:region-desc="state.regionDesc"
|
||||||
:machine-id="state.machineId"
|
:machine-id="state.machineId"
|
||||||
@@ -47,8 +47,8 @@
|
|||||||
:code-no="state.code"
|
:code-no="state.code"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 完成状态 -->
|
<!-- 完成状态(超过24小时) -->
|
||||||
<div v-else-if="state.status === 'COMPLETED'" class="completed-page">
|
<div v-else-if="state.status === 'COMPLETED' && state.isCompletedExpired" class="completed-page">
|
||||||
<div class="completed-text">已打完</div>
|
<div class="completed-text">已打完</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -141,7 +141,8 @@ export default {
|
|||||||
} = useQrCode()
|
} = useQrCode()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const code = route.query.code
|
// 兼容两种方式:路径参数和查询参数
|
||||||
|
const code = route.params.code || route.query.code
|
||||||
if (!code) {
|
if (!code) {
|
||||||
state.error = 'INVALID_CODE'
|
state.error = 'INVALID_CODE'
|
||||||
state.loading = false
|
state.loading = false
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://127.0.0.1:18080',
|
// target: 'https://uzi1.cn/api',
|
||||||
|
target: 'http://localhost:18080',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (p) => p.replace(/^\/api/, ''),
|
rewrite: (p) => p.replace(/^\/api/, ''),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user