front/src/composables/useAskAdvisor.ts
zzh 4ff22fed57
Some checks failed
Build and Deploy Front / deploy (push) Failing after 12s
feat: Nana 升级为 Edi,H5 仓操接入装袋打板并补分析页
助手改为浮窗 Edi、运营/客户分流;官网跑道虹膜后重播;H5 FAB 增加装袋/打板原生页与 3D 入口图标;并带上财务/营销/代理分析相关改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 14:33:27 +08:00

125 lines
4.3 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.

import type { LocationQuery, Router } from 'vue-router';
import { useEdiAdvisorPanel } from '@/composables/useEdiAdvisorPanel';
export type WaybillSource = 'myOrders' | 'waybillManage' | 'h5Orders';
export type WaybillContext = {
orderId?: string;
waybillNo?: string;
trackingNo?: string;
customerOrderNo?: string;
from?: WaybillSource;
orderStatus?: string;
};
function pickQueryValue(value: LocationQuery[string]): string | undefined {
const raw = Array.isArray(value) ? value[0] : value;
if (raw == null) return undefined;
const text = String(raw).trim();
return text || undefined;
}
function pickWaybillSource(value: LocationQuery[string]): WaybillSource | undefined {
const raw = pickQueryValue(value);
if (raw === 'myOrders' || raw === 'waybillManage' || raw === 'h5Orders') return raw;
return undefined;
}
export function buildWaybillContextFromRow(
row: Record<string, unknown>,
from?: WaybillSource,
): WaybillContext {
const orderId = row.id ?? row.Id;
const waybillNo = row.waybillNo ?? row.serviceNo ?? row.ServiceNo;
const trackingNo = row.trackingNo ?? row.trackNo ?? row.TrackNo;
const customerOrderNo = row.customerOrderNo ?? row.clientNo ?? row.ClientNo;
const orderStatus = row.orderStatus ?? row.status ?? row.Status ?? row.OrderStatus;
return {
orderId: orderId != null && String(orderId).trim() ? String(orderId).trim() : undefined,
waybillNo: waybillNo != null && String(waybillNo).trim() ? String(waybillNo).trim() : undefined,
trackingNo: trackingNo != null && String(trackingNo).trim() ? String(trackingNo).trim() : undefined,
customerOrderNo:
customerOrderNo != null && String(customerOrderNo).trim() ? String(customerOrderNo).trim() : undefined,
from,
orderStatus:
orderStatus != null && String(orderStatus).trim() ? String(orderStatus).trim() : undefined,
};
}
export function parseWaybillContextFromQuery(query: LocationQuery): WaybillContext | null {
const ctx: WaybillContext = {
orderId: pickQueryValue(query.orderId),
waybillNo: pickQueryValue(query.waybillNo),
trackingNo: pickQueryValue(query.trackingNo),
customerOrderNo: pickQueryValue(query.customerOrderNo),
from: pickWaybillSource(query.from),
orderStatus: pickQueryValue(query.orderStatus),
};
if (!ctx.orderId && !ctx.waybillNo && !ctx.trackingNo && !ctx.customerOrderNo) {
return null;
}
return ctx;
}
export function getWaybillContextKey(ctx: WaybillContext): string {
return ctx.orderId || ctx.waybillNo || ctx.trackingNo || ctx.customerOrderNo || '';
}
export function getWaybillDisplayNo(ctx: WaybillContext): string {
return ctx.waybillNo || ctx.trackingNo || ctx.customerOrderNo || ctx.orderId || '';
}
export function getWaybillPrefillText(ctx: WaybillContext): string {
return ctx.trackingNo || ctx.waybillNo || ctx.customerOrderNo || '';
}
export function getWaybillReturnPath(ctx?: WaybillContext | null): string {
if (ctx?.from === 'waybillManage') return '/order/waybillManage';
if (ctx?.from === 'h5Orders') {
return ctx.orderId ? `/h5/orders/${ctx.orderId}` : '/h5/orders';
}
if (ctx?.from === 'myOrders') return '/order/myOrders';
return '/order/myOrders';
}
export function buildAskAdvisorQuery(ctx: WaybillContext): Record<string, string> {
const query: Record<string, string> = {};
if (ctx.orderId) query.orderId = ctx.orderId;
if (ctx.waybillNo) query.waybillNo = ctx.waybillNo;
if (ctx.trackingNo) query.trackingNo = ctx.trackingNo;
if (ctx.customerOrderNo) query.customerOrderNo = ctx.customerOrderNo;
if (ctx.from) query.from = ctx.from;
if (ctx.orderStatus) query.orderStatus = ctx.orderStatus;
return query;
}
export function openAskAdvisor(router: Router, ctx: WaybillContext) {
const path = router.currentRoute.value.path || '';
// H5 仍用独立顾问页
if (path.startsWith('/h5')) {
router.push({
path: '/h5/assistant',
query: buildAskAdvisorQuery(ctx),
});
return;
}
// PC:打开全局大面板,不离开当前业务页
useEdiAdvisorPanel().open({ waybill: ctx });
}
export default function useAskAdvisor() {
return {
buildWaybillContextFromRow,
parseWaybillContextFromQuery,
getWaybillContextKey,
getWaybillDisplayNo,
getWaybillPrefillText,
getWaybillReturnPath,
buildAskAdvisorQuery,
openAskAdvisor,
};
}