完善多赛道联调与全局产品架构
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { loadBackendAuthTokens, loadBackendBaseUrl } from '../../utils/backendAuth'
|
||||
import { getMyResults, getSessionResult, type BackendSessionResultView } from '../../utils/backendApi'
|
||||
import { getSessionResult } from '../../utils/backendApi'
|
||||
import type { MapEngineResultSnapshot } from '../../engine/map/mapEngine'
|
||||
|
||||
type ResultPageData = {
|
||||
sessionId: string
|
||||
@@ -7,7 +8,6 @@ type ResultPageData = {
|
||||
sessionTitleText: string
|
||||
sessionSubtitleText: string
|
||||
rows: Array<{ label: string; value: string }>
|
||||
recentResults: BackendSessionResultView[]
|
||||
}
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
@@ -25,6 +25,22 @@ function formatValue(value: unknown): string {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function formatRouteSummary(input: {
|
||||
variantName?: string | null
|
||||
routeCode?: string | null
|
||||
}): string {
|
||||
if (input.variantName && input.routeCode) {
|
||||
return `${input.variantName} / ${input.routeCode}`
|
||||
}
|
||||
if (input.variantName) {
|
||||
return input.variantName
|
||||
}
|
||||
if (input.routeCode) {
|
||||
return input.routeCode
|
||||
}
|
||||
return '默认赛道'
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
sessionId: '',
|
||||
@@ -32,17 +48,49 @@ Page({
|
||||
sessionTitleText: '结果页',
|
||||
sessionSubtitleText: '未加载',
|
||||
rows: [],
|
||||
recentResults: [],
|
||||
} as ResultPageData,
|
||||
|
||||
onLoad(query: { sessionId?: string }) {
|
||||
const sessionId = query && query.sessionId ? decodeURIComponent(query.sessionId) : ''
|
||||
this.setData({ sessionId })
|
||||
this.applyPendingResultSnapshot()
|
||||
if (sessionId) {
|
||||
this.loadSingleResult(sessionId)
|
||||
return
|
||||
}
|
||||
this.loadRecentResults()
|
||||
this.setData({
|
||||
statusText: '未提供单局会话,已跳转历史结果',
|
||||
})
|
||||
wx.redirectTo({
|
||||
url: '/pages/results/results',
|
||||
})
|
||||
},
|
||||
|
||||
applyPendingResultSnapshot() {
|
||||
const app = getApp<IAppOption>()
|
||||
const snapshot = app.globalData && app.globalData.pendingResultSnapshot
|
||||
? app.globalData.pendingResultSnapshot as MapEngineResultSnapshot
|
||||
: null
|
||||
if (!snapshot) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
statusText: '正在加载结果',
|
||||
sessionTitleText: snapshot.title,
|
||||
sessionSubtitleText: snapshot.subtitle,
|
||||
rows: [
|
||||
{ label: snapshot.heroLabel, value: snapshot.heroValue },
|
||||
...snapshot.rows.map((row) => ({
|
||||
label: row.label,
|
||||
value: row.value,
|
||||
})),
|
||||
],
|
||||
})
|
||||
|
||||
if (app.globalData) {
|
||||
app.globalData.pendingResultSnapshot = null
|
||||
}
|
||||
},
|
||||
|
||||
async loadSingleResult(sessionId: string) {
|
||||
@@ -65,8 +113,9 @@ Page({
|
||||
this.setData({
|
||||
statusText: '单局结果加载完成',
|
||||
sessionTitleText: result.session.eventName || result.session.eventDisplayName || result.session.eventId || result.session.id || result.session.sessionId,
|
||||
sessionSubtitleText: `${result.session.status || result.session.sessionStatus} / ${result.result.status}`,
|
||||
sessionSubtitleText: `${result.session.status || result.session.sessionStatus} / ${result.result.status} / ${formatRouteSummary(result.session)}`,
|
||||
rows: [
|
||||
{ label: '赛道版本', value: formatRouteSummary(result.session) },
|
||||
{ label: '最终得分', value: formatValue(result.result.finalScore) },
|
||||
{ label: '最终用时(秒)', value: formatValue(result.result.finalDurationSec) },
|
||||
{ label: '完成点数', value: formatValue(result.result.completedControls) },
|
||||
@@ -84,51 +133,9 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async loadRecentResults() {
|
||||
const accessToken = getAccessToken()
|
||||
if (!accessToken) {
|
||||
wx.redirectTo({ url: '/pages/login/login' })
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
statusText: '正在加载最近结果',
|
||||
})
|
||||
|
||||
try {
|
||||
const results = await getMyResults({
|
||||
baseUrl: loadBackendBaseUrl(),
|
||||
accessToken,
|
||||
limit: 20,
|
||||
})
|
||||
this.setData({
|
||||
statusText: '最近结果加载完成',
|
||||
sessionSubtitleText: '最近结果列表',
|
||||
recentResults: results,
|
||||
})
|
||||
} catch (error) {
|
||||
const message = error && (error as { message?: string }).message ? (error as { message: string }).message : '未知错误'
|
||||
this.setData({
|
||||
statusText: `结果加载失败:${message}`,
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenResult(event: WechatMiniprogram.TouchEvent) {
|
||||
const sessionId = event.currentTarget.dataset.sessionId as string | undefined
|
||||
if (!sessionId) {
|
||||
return
|
||||
}
|
||||
wx.redirectTo({
|
||||
url: `/pages/result/result?sessionId=${encodeURIComponent(sessionId)}`,
|
||||
})
|
||||
},
|
||||
|
||||
handleBackToList() {
|
||||
this.setData({
|
||||
sessionId: '',
|
||||
rows: [],
|
||||
wx.redirectTo({
|
||||
url: '/pages/results/results',
|
||||
})
|
||||
this.loadRecentResults()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<view class="panel">
|
||||
<view class="panel__title">当前状态</view>
|
||||
<view class="summary">{{statusText}}</view>
|
||||
<button wx:if="{{sessionId}}" class="btn btn--ghost" bindtap="handleBackToList">返回最近结果</button>
|
||||
<button class="btn btn--ghost" bindtap="handleBackToList">查看历史结果</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{rows.length}}" class="panel">
|
||||
@@ -19,15 +19,5 @@
|
||||
<view class="row__value">{{item.value}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!sessionId}}" class="panel">
|
||||
<view class="panel__title">最近结果</view>
|
||||
<view wx:if="{{!recentResults.length}}" class="summary">当前没有结果记录</view>
|
||||
<view wx:for="{{recentResults}}" wx:key="session.id" class="result-card" bindtap="handleOpenResult" data-session-id="{{item.session.id}}">
|
||||
<view class="result-card__title">{{item.session.eventName || item.session.id}}</view>
|
||||
<view class="result-card__meta">{{item.result.status}} / {{item.session.status}}</view>
|
||||
<view class="result-card__meta">得分 {{item.result.finalScore || '--'}} / 用时 {{item.result.finalDurationSec || '--'}}s</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
Reference in New Issue
Block a user