feat(order-service): 重构分类资料收集与订单状态链路
This commit is contained in:
@@ -22,6 +22,7 @@ export const WORKER_PLATFORM_TAB_KEYS: readonly string[] = [
|
||||
'after-sales',
|
||||
'announcement',
|
||||
'rules',
|
||||
'order-service',
|
||||
'product-match',
|
||||
'categories',
|
||||
'workers',
|
||||
@@ -49,6 +50,11 @@ export const WORKER_PLATFORM_TAB_QUERY_KEYS: Record<string, string[][]> = {
|
||||
'after-sales': [['admin-after-sales-orders'], ['admin-after-sales-stats']],
|
||||
feedbacks: [['admin-feedbacks']],
|
||||
rules: [['admin-product-rules']],
|
||||
'order-service': [
|
||||
['admin-order-service-profiles'],
|
||||
['admin-order-service-auto-publish-jobs'],
|
||||
['admin-categories'],
|
||||
],
|
||||
'product-match': [['admin-product-match']],
|
||||
categories: [['admin-categories']],
|
||||
workers: [['admin-workers'], ['admin-worker-users']],
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* 一次性补资料链接的路径解析。
|
||||
*
|
||||
* 公开链接有两种形态:
|
||||
* - `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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/** 客户订单服务页路径解析:/o 与 /o/:orderNo。 */
|
||||
export function isOrderServicePath(pathname: unknown): boolean {
|
||||
const segments = splitPathSegments(pathname)
|
||||
return segments[0] === 'o'
|
||||
}
|
||||
|
||||
export function isLegacySupplementPath(pathname: unknown): boolean {
|
||||
return splitPathSegments(pathname)[0] === 'supplement'
|
||||
}
|
||||
|
||||
export function resolveLegacySupplementOrderNo(pathname: unknown): string {
|
||||
const segments = splitPathSegments(pathname)
|
||||
if (segments.length !== 2 || segments[0] !== 'supplement') return ''
|
||||
return decodePathSegment(segments[1])
|
||||
}
|
||||
|
||||
export function resolveOrderServiceOrderNo(pathname: unknown): string {
|
||||
const segments = splitPathSegments(pathname)
|
||||
if (segments.length !== 2 || segments[0] !== 'o') return ''
|
||||
return decodePathSegment(segments[1])
|
||||
}
|
||||
|
||||
export function buildOrderServiceUrl(origin: unknown, orderNo: unknown): string {
|
||||
const base = String(origin ?? '')
|
||||
.trim()
|
||||
.replace(/\/+$/, '')
|
||||
const order = String(orderNo ?? '').trim()
|
||||
if (!base || !order) return ''
|
||||
return `${base}/o/${encodeURIComponent(order)}`
|
||||
}
|
||||
|
||||
export function normalizeOrderServiceInput(value: unknown): string {
|
||||
const raw = String(value ?? '').trim()
|
||||
if (!raw) return ''
|
||||
for (const marker of ['/o/', '/supplement/']) {
|
||||
const index = raw.indexOf(marker)
|
||||
if (index < 0) continue
|
||||
return decodePathSegment(
|
||||
raw
|
||||
.slice(index + marker.length)
|
||||
.split(/[?#]/)[0]
|
||||
.replace(/\/+$/, '')
|
||||
.trim(),
|
||||
)
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user