refactor(login): move match-route logic to dedicated service and fix import
- 提取登录回跳、产品对比的路由匹配逻辑至独立的 match-route.uts 服务 - 修复登录页面导入对比服务的错误,改为导入新的 match-route 模块 - 保持原有的路由参数校验和跳转逻辑不变,仅重构代码结构
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
function validRecordId(value: string): boolean { return /^[1-9][0-9]{0,9}$/.test(value) }
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user