/** 客户订单服务页路径解析:/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 } }