refactor(login): move match-route logic to dedicated service and fix import
- 提取登录回跳、产品对比的路由匹配逻辑至独立的 match-route.uts 服务 - 修复登录页面导入对比服务的错误,改为导入新的 match-route 模块 - 保持原有的路由参数校验和跳转逻辑不变,仅重构代码结构
This commit is contained in:
@@ -1,21 +1,11 @@
|
||||
import { getSession } from '@/services/api.uts'
|
||||
import { validRecordId, MatchDetail, MatchReason } from './matches.uts'
|
||||
import { MatchDetail, MatchReason } from './matches.uts'
|
||||
import { parseCompareIds } from '@/services/match-route.uts'
|
||||
export { parseCompareIds, compareQuery, matchReturnPath } from '@/services/match-route.uts'
|
||||
|
||||
let scope = ''
|
||||
let selected: string[] = []
|
||||
|
||||
export function parseCompareIds(raw: string): string[] {
|
||||
if (raw.length == 0) return []
|
||||
const ids = raw.split(',')
|
||||
if (ids.length > 3) throw new Error('每次最多对比3个产品,请返回重新选择。')
|
||||
const seen: string[] = []
|
||||
ids.forEach((id: string) => {
|
||||
if (!validRecordId(id) || seen.includes(id)) throw new Error('对比产品编号无效或重复,请返回重新选择。')
|
||||
seen.push(id)
|
||||
})
|
||||
return ids
|
||||
}
|
||||
|
||||
// 只缓存少量选择ID,不持久化产品或个人事实;换账号、会话或评估后立即隔离。
|
||||
export function compareSelection(assessmentId: string, revisionId: string = ''): string[] {
|
||||
const session = getSession()
|
||||
@@ -27,23 +17,6 @@ export function saveCompareSelection(assessmentId: string, ids: string[], revisi
|
||||
compareSelection(assessmentId, revisionId)
|
||||
selected = parseCompareIds(ids.join(','))
|
||||
}
|
||||
export function compareQuery(assessmentId: string, ids: string[], revisionId: string = ''): string {
|
||||
return '?assessmentId=' + encodeURIComponent(assessmentId) + '&productIds=' + ids.join(',') + (revisionId.length > 0 ? '&revisionId=' + revisionId : '')
|
||||
}
|
||||
// 登录回跳只接受已声明页面与编号,不接受任意URL。
|
||||
export function matchReturnPath(page: string, assessmentId: string, rawIds: string, revisionId: string, productId: string = '', group: string = 'eligible', tab: string = 'explanation', from: string = ''): string {
|
||||
if (!['matches','product','compare'].includes(page) || (revisionId.length > 0 && !validRecordId(revisionId))) return ''
|
||||
if (assessmentId.length > 0 ? !validRecordId(assessmentId) : page != 'product') return ''
|
||||
let ids: string[] = []
|
||||
try { ids = parseCompareIds(rawIds) } catch (err) { return '' }
|
||||
if (assessmentId.length == 0 && (revisionId.length > 0 || ids.length > 0)) return ''
|
||||
if (page == 'matches' && !['eligible','ineligible','unknown'].includes(group)) return ''
|
||||
if (page == 'product' && (!validRecordId(productId) || !['explanation','details','conditions'].includes(tab) || (assessmentId.length == 0 && tab == 'explanation') || !['','matches','product','compare','report','next-step','archive'].includes(from))) return ''
|
||||
const query = assessmentId.length > 0 ? compareQuery(assessmentId, ids, revisionId) : '?'
|
||||
if (page == 'matches') return '/packages/finance/matches/matches' + query + '&group=' + group
|
||||
if (page == 'compare') return '/packages/finance/compare/compare' + query
|
||||
return '/packages/finance/product/product' + query + (assessmentId.length > 0 ? '&' : '') + 'productId=' + productId + '&tab=' + tab + '&from=' + from
|
||||
}
|
||||
export function sameMatchSnapshot(a: MatchDetail, b: MatchDetail): boolean {
|
||||
return a.assessmentId == b.assessmentId && a.revisionId == b.revisionId && a.resultVersion == b.resultVersion && a.snapshotId == b.snapshotId && a.ruleVersion == b.ruleVersion && a.orderingVersion == b.orderingVersion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user