完善多赛道联调与全局产品架构
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { loadBackendAuthTokens, loadBackendBaseUrl } from '../../utils/backendAuth'
|
||||
import { getEventPlay, launchEvent, type BackendEventPlayResult } from '../../utils/backendApi'
|
||||
import { adaptBackendLaunchResultToEnvelope } from '../../utils/backendLaunchAdapter'
|
||||
import { prepareMapPageUrlForLaunch } from '../../utils/gameLaunch'
|
||||
import { getEventPlay, type BackendEventPlayResult } from '../../utils/backendApi'
|
||||
|
||||
type EventPageData = {
|
||||
eventId: string
|
||||
@@ -11,6 +9,33 @@ type EventPageData = {
|
||||
releaseText: string
|
||||
actionText: string
|
||||
statusText: string
|
||||
variantModeText: string
|
||||
variantSummaryText: string
|
||||
}
|
||||
|
||||
function formatAssignmentMode(mode?: string | null): string {
|
||||
if (mode === 'manual') {
|
||||
return '手动选择'
|
||||
}
|
||||
if (mode === 'random') {
|
||||
return '随机分配'
|
||||
}
|
||||
if (mode === 'server-assigned') {
|
||||
return '后台指定'
|
||||
}
|
||||
return '默认单赛道'
|
||||
}
|
||||
|
||||
function formatVariantSummary(result: BackendEventPlayResult): string {
|
||||
const variants = result.play.courseVariants || []
|
||||
if (!variants.length) {
|
||||
return '当前未声明额外赛道版本'
|
||||
}
|
||||
|
||||
const selectable = variants.filter((item) => item.selectable !== false)
|
||||
const preview = variants.slice(0, 3).map((item) => item.routeCode || item.name).join(' / ')
|
||||
const suffix = variants.length > 3 ? ' / ...' : ''
|
||||
return `${variants.length} 条赛道,可选 ${selectable.length} 条:${preview}${suffix}`
|
||||
}
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
@@ -30,6 +55,8 @@ Page({
|
||||
releaseText: '--',
|
||||
actionText: '--',
|
||||
statusText: '待加载',
|
||||
variantModeText: '--',
|
||||
variantSummaryText: '--',
|
||||
} as EventPageData,
|
||||
|
||||
onLoad(query: { eventId?: string }) {
|
||||
@@ -83,6 +110,8 @@ Page({
|
||||
: '当前无可用 release',
|
||||
actionText: `${result.play.primaryAction} / ${result.play.reason}`,
|
||||
statusText: result.play.canLaunch ? '可启动' : '当前不可启动',
|
||||
variantModeText: formatAssignmentMode(result.play.assignmentMode),
|
||||
variantSummaryText: formatVariantSummary(result),
|
||||
})
|
||||
},
|
||||
|
||||
@@ -91,33 +120,8 @@ Page({
|
||||
},
|
||||
|
||||
async handleLaunch() {
|
||||
const accessToken = getAccessToken()
|
||||
if (!accessToken) {
|
||||
wx.redirectTo({ url: '/pages/login/login' })
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
statusText: '正在创建 session 并进入地图',
|
||||
wx.navigateTo({
|
||||
url: `/pages/event-prepare/event-prepare?eventId=${encodeURIComponent(this.data.eventId)}`,
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await launchEvent({
|
||||
baseUrl: loadBackendBaseUrl(),
|
||||
eventId: this.data.eventId,
|
||||
accessToken,
|
||||
clientType: 'wechat',
|
||||
deviceKey: 'mini-dev-device-001',
|
||||
})
|
||||
const envelope = adaptBackendLaunchResultToEnvelope(result)
|
||||
wx.navigateTo({
|
||||
url: prepareMapPageUrlForLaunch(envelope),
|
||||
})
|
||||
} catch (error) {
|
||||
const message = error && (error as { message?: string }).message ? (error as { message: string }).message : '未知错误'
|
||||
this.setData({
|
||||
statusText: `launch 失败:${message}`,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
<view class="summary">Release:{{releaseText}}</view>
|
||||
<view class="summary">主动作:{{actionText}}</view>
|
||||
<view class="summary">状态:{{statusText}}</view>
|
||||
<view class="summary">赛道模式:{{variantModeText}}</view>
|
||||
<view class="summary">赛道摘要:{{variantSummaryText}}</view>
|
||||
<view class="actions">
|
||||
<button class="btn btn--secondary" bindtap="handleRefresh">刷新</button>
|
||||
<button class="btn btn--primary" bindtap="handleLaunch">开始比赛</button>
|
||||
<button class="btn btn--primary" bindtap="handleLaunch">前往准备页</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user