Files
order_site/apps/frontend/src/utils/collect-link.ts
T
zhaoxing a2cf48f5fc feat(collect): 补资料改为订单号直连并按状态一次性提交
- 公开补资料页 /supplement/:订单号 直接按平台订单号查询,不再依赖链接记录;旧 token 链接一律 404
- 仅「待完善 + 未指派 + 无拼单份额」可提交,提交后状态变为待分配,重复提交返回 409
- 非可编辑工单只返回商品、工单号、状态与客服提示,不返回已填资料和截图
- 管理端新增「重置补资料」:待分配且未指派、无份额、未发布时一键重置回待完善
- 新增 canResetMaterial 能力与 material_reset 流转事件,工单状态文案统一为「待分配」
2026-11-01 18:12:44 +08:00

69 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 一次性补资料链接的路径解析。
*
* 公开链接有两种形态:
* - `https://<域名>/supplement/`:输入平台订单号;
* - `https://<域名>/supplement/<平台订单号>`:直接打开对应订单的补资料页。
* 与后台 HashRouter 完全隔离。
*/
export function isCollectMaterialLinkPath(pathname: unknown): boolean {
return splitPathSegments(pathname)[0] === 'supplement'
}
/**
* 只认 `/supplement/<一段 code>`:
* - `/supplement/abc` 命中,结尾多余斜杠容忍;
* - `/supplement`、`/supplement/a/b` 不命中(由入口页/页面自己展示无效)。
*/
export function resolveCollectMaterialLinkCode(pathname: unknown): string {
const segments = splitPathSegments(pathname)
if (segments.length !== 2 || segments[0] !== 'supplement') return ''
return decodePathSegment(segments[1])
}
/** 统一拼补资料链接;origin 结尾多余斜杠会被去掉。 */
export function buildCollectMaterialLinkUrl(origin: unknown, code: unknown): string {
const base = String(origin ?? '')
.trim()
.replace(/\/+$/, '')
const normalized = String(code ?? '').trim()
if (!base || !normalized) return ''
return `${base}/supplement/${encodeURIComponent(normalized)}`
}
/**
* 入口页输入归一化:去空格;如果用户粘贴了完整 `/supplement/<订单号>` 链接,
* 自动提取最后一段,避免把整条 URL 当成订单号。
*/
export function normalizeOrderNoInput(value: unknown): string {
const raw = String(value ?? '').trim()
if (!raw) return ''
const marker = '/supplement/'
const index = raw.indexOf(marker)
if (index < 0) return raw
const segment = raw
.slice(index + marker.length)
.split(/[?#]/)[0]
.replace(/\/+$/, '')
.trim()
return decodePathSegment(segment)
}
function splitPathSegments(pathname: unknown): string[] {
const normalized = String(pathname ?? '').trim()
if (!normalized.startsWith('/')) return []
return normalized.split(/[?#]/)[0].replace(/\/+$/, '').split('/').filter(Boolean)
}
function decodePathSegment(segment: string): string {
try {
return decodeURIComponent(segment)
} catch {
return segment
}
}