feat(shipping-notice): 完善发货通知自动推进与多库存源复核闭环
This commit is contained in:
1 parent
cfa19a0b7b
commit
8e0bbf7a81
180 files changed
+31210
-1864
No files matched your search
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* features/admin/api/shipping-legacy-stp-jobs.api.ts
|
||||
* 用途:Phase 5-1 —— 管理员历史 STP Job(928/929 面板)HTTP API 客户端。
|
||||
* 依赖:requestJson / getAuthHeaders(shared/api/client & shared/utils/auth)。
|
||||
* 逻辑:GET list / GET detail;后端 URL 为 /api/admin/shipping-notice/legacy-stp-jobs。
|
||||
*/
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import type { PaginatedResult } from '@/shared/types/pagination.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
|
||||
export type LegacyStpJobRow = {
|
||||
job_id: number;
|
||||
domain: string;
|
||||
job_type: string;
|
||||
status: 'failed' | 'dead' | string;
|
||||
business_ref: string | null;
|
||||
reference_key: string | null;
|
||||
case_no: string | null;
|
||||
priority: number;
|
||||
attempts: number;
|
||||
max_attempts: number;
|
||||
message: string | null;
|
||||
error_message: string | null;
|
||||
error_code: string | null;
|
||||
blocking_reason: string | null;
|
||||
retryable: boolean | null;
|
||||
next_action: string | string[] | null;
|
||||
retry_of_job_id: number | null;
|
||||
created_by_id: number | null;
|
||||
result_json_masked: Record<string, unknown> | null;
|
||||
payload_json_masked: Record<string, unknown> | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
started_at: string | null;
|
||||
finished_at: string | null;
|
||||
};
|
||||
|
||||
export type LegacyStpJobCaseBacklink = {
|
||||
case_id: number;
|
||||
case_no: string;
|
||||
status: string;
|
||||
candidate_id: number | null;
|
||||
confirmed_task_id: number | null;
|
||||
document_id: number | null;
|
||||
owner_user_id: number | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
};
|
||||
|
||||
export type LegacyStpJobReplayPlan = {
|
||||
supported: boolean;
|
||||
recommended_user_action: 'force_create' | 'create_revision' | string;
|
||||
needs_replay_mode: boolean;
|
||||
reconcile_and_progress_endpoint: string | null;
|
||||
};
|
||||
|
||||
export type LegacyStpJobDetailPayload = {
|
||||
job: LegacyStpJobRow;
|
||||
case: LegacyStpJobCaseBacklink | null;
|
||||
replay_plan: LegacyStpJobReplayPlan;
|
||||
};
|
||||
|
||||
export type LegacyStpJobListFilters = {
|
||||
status?: '' | 'failed' | 'dead';
|
||||
job_type?: string;
|
||||
q?: string;
|
||||
case_no?: string;
|
||||
error_code?: string;
|
||||
blocking_reason?: string;
|
||||
created_from?: string;
|
||||
created_to?: string;
|
||||
sort?: string;
|
||||
};
|
||||
|
||||
const EMPTY_FILTERS: Required<LegacyStpJobListFilters> = {
|
||||
status: '',
|
||||
job_type: '',
|
||||
q: '',
|
||||
case_no: '',
|
||||
error_code: '',
|
||||
blocking_reason: '',
|
||||
created_from: '',
|
||||
created_to: '',
|
||||
sort: '-created_at',
|
||||
};
|
||||
|
||||
export const DEFAULT_LEGACY_STP_JOB_FILTERS = EMPTY_FILTERS;
|
||||
|
||||
export const LEGACY_STP_JOB_STATUS_OPTIONS = ['failed', 'dead'] as const;
|
||||
|
||||
function normalizeDateTimeFilter(value?: string): string {
|
||||
const raw = String(value || '').trim();
|
||||
if (!raw) return '';
|
||||
const date = new Date(raw);
|
||||
if (Number.isNaN(date.getTime())) return raw;
|
||||
return date.toISOString();
|
||||
}
|
||||
|
||||
function buildListSearchParams(filters: LegacyStpJobListFilters, page: number, pageSize: number): URLSearchParams {
|
||||
const params = new URLSearchParams({
|
||||
page: String(page),
|
||||
page_size: String(pageSize),
|
||||
});
|
||||
if (filters.status) params.set('status', filters.status);
|
||||
if (filters.job_type) params.set('job_type', filters.job_type);
|
||||
if (filters.q) params.set('q', filters.q);
|
||||
if (filters.case_no) params.set('case_no', filters.case_no);
|
||||
if (filters.error_code) params.set('error_code', filters.error_code);
|
||||
if (filters.blocking_reason) params.set('blocking_reason', filters.blocking_reason);
|
||||
if (filters.created_from) params.set('created_from', normalizeDateTimeFilter(filters.created_from));
|
||||
if (filters.created_to) params.set('created_to', normalizeDateTimeFilter(filters.created_to));
|
||||
if (filters.sort) params.set('sort', filters.sort);
|
||||
return params;
|
||||
}
|
||||
|
||||
export function listAdminLegacyStpJobs(
|
||||
page = 1,
|
||||
pageSize = 25,
|
||||
filters: LegacyStpJobListFilters = {},
|
||||
): Promise<PaginatedResult<LegacyStpJobRow> & {
|
||||
filters: { domain: string; job_types: string[]; statuses: string[] };
|
||||
}> {
|
||||
const params = buildListSearchParams(filters, page, pageSize);
|
||||
return requestJson(`/api/admin/shipping-notice/legacy-stp-jobs?${params}`, auth());
|
||||
}
|
||||
|
||||
export function getAdminLegacyStpJob(jobId: number): Promise<LegacyStpJobDetailPayload> {
|
||||
return requestJson(`/api/admin/shipping-notice/legacy-stp-jobs/${encodeURIComponent(String(jobId))}`, auth());
|
||||
}
|
||||
@@ -23,6 +23,7 @@ export interface ShippingConfigSubModuleMeta {
|
||||
| 'AdminShippingOrderExtractionRuns'
|
||||
| 'AdminShippingAudit'
|
||||
| 'AdminShippingProcessGates'
|
||||
| 'AdminShippingLegacyStpJobs'
|
||||
| 'AdminShippingOrderDocumentProfiles';
|
||||
path:
|
||||
| 'shipping-notice'
|
||||
@@ -32,6 +33,7 @@ export interface ShippingConfigSubModuleMeta {
|
||||
| 'shipping-order-extraction-runs'
|
||||
| 'shipping-audit'
|
||||
| 'shipping-process-gates'
|
||||
| 'shipping-legacy-stp-jobs'
|
||||
| 'shipping-order-document-profiles';
|
||||
labelKey: string;
|
||||
groupKey: 'admin.nav.shippingOrderRecognition' | 'admin.nav.shippingInventoryManagement' | 'admin.nav.shippingRunAudit';
|
||||
@@ -75,6 +77,7 @@ export const SHIPPING_CONFIG_SUB_MODULE_METAS: ShippingConfigSubModuleMeta[] = [
|
||||
{ id: 'shipping_templates', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.excelTemplates', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'templates' } },
|
||||
{ id: 'shipping_audit', routeName: 'AdminShippingAudit', path: 'shipping-audit', labelKey: 'admin.nav.shippingAudit', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ id: 'process_gates', routeName: 'AdminShippingProcessGates', path: 'shipping-process-gates', labelKey: 'admin.nav.shippingProcessGates', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ id: 'legacy_stp_jobs', routeName: 'AdminShippingLegacyStpJobs', path: 'shipping-legacy-stp-jobs', labelKey: 'admin.nav.shippingLegacyStpJobs', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ id: 'inventory_snapshots', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.snapshots', groupKey: 'admin.nav.shippingRunAudit', query: { section: 'snapshots' } },
|
||||
{ id: 'export_records', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.exports', groupKey: 'admin.nav.shippingRunAudit', query: { section: 'exports' } },
|
||||
];
|
||||
|
||||
+420
@@ -0,0 +1,420 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-legacy-stp-jobs/ShippingLegacyStpJobsPage.vue
|
||||
用途:Phase 5-1 —— 管理员「历史 STP Job(928/929 回放)」运维面板。
|
||||
依赖:shipping-legacy-stp-jobs.api、Vue Router、Vue I18n、workspace.shippingNotice.actions 键。
|
||||
逻辑:
|
||||
[STEP 1] 左侧 ~38%:分页列表(筛选 q/case_no/error_code/blocking_reason/status/created_from/to)
|
||||
按创建时间倒序;
|
||||
[STEP 2] 右侧 sticky:详情 —— Job 摘要、回链 Review Case(case 非空时跳转工作台 Case 详情)、
|
||||
replay_plan(推荐 user_action)、
|
||||
「一键回放 Reconcile And Progress」按钮直接走
|
||||
POST /api/workspace/shipping-notice/order-review-cases/<case_no>/reconcile-and-progress
|
||||
带 legacy_job_id + replay_mode。
|
||||
全部只读 + 一个写操作(回放按钮),写操作必须管理员;非管理员会被后端 422。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
DEFAULT_LEGACY_STP_JOB_FILTERS,
|
||||
LEGACY_STP_JOB_STATUS_OPTIONS,
|
||||
getAdminLegacyStpJob,
|
||||
listAdminLegacyStpJobs,
|
||||
type LegacyStpJobDetailPayload,
|
||||
type LegacyStpJobListFilters,
|
||||
type LegacyStpJobRow,
|
||||
} from '@/features/admin/api/shipping-legacy-stp-jobs.api';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const router = useRouter();
|
||||
const message = useMessage();
|
||||
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
const replaying = ref(false);
|
||||
const error = ref('');
|
||||
const page = ref(1);
|
||||
const pageSize = ref(25);
|
||||
const total = ref(0);
|
||||
const filters = ref<LegacyStpJobListFilters>({ ...DEFAULT_LEGACY_STP_JOB_FILTERS });
|
||||
const rows = ref<LegacyStpJobRow[]>([]);
|
||||
const selectedJobId = ref<number | null>(null);
|
||||
const detail = ref<LegacyStpJobDetailPayload | null>(null);
|
||||
const replayUserAction = ref<'auto' | 'reuse_existing' | 'create_revision' | 'force_create' | 'adjudicate'>('create_revision');
|
||||
const replayLastResult = ref<{ ok: boolean; outcome?: string | null; message?: string | null } | null>(null);
|
||||
|
||||
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
|
||||
function jsonFormat(value: unknown): string {
|
||||
if (value == null) return '—';
|
||||
try { return JSON.stringify(value, null, 2); } catch { return String(value); }
|
||||
}
|
||||
type CodeLabelNs = 'admin.legacyStpJobs.statusLabels' | 'admin.legacyStpJobs.reasonCodes' | 'workspace.shippingNotice.processGate.actionCodes';
|
||||
|
||||
function codeLabel(code?: string | null, ns: CodeLabelNs = 'admin.legacyStpJobs.statusLabels'): string {
|
||||
const key = String(code || '').trim();
|
||||
if (!key) return '—';
|
||||
const i18nKey = `${ns}.${key}`;
|
||||
return te(i18nKey) ? t(i18nKey) : key;
|
||||
}
|
||||
function actionLabel(code?: string | null): string { return codeLabel(code, 'workspace.shippingNotice.processGate.actionCodes'); }
|
||||
|
||||
function resetFilters() {
|
||||
filters.value = { ...DEFAULT_LEGACY_STP_JOB_FILTERS };
|
||||
page.value = 1;
|
||||
selectedJobId.value = null;
|
||||
detail.value = null;
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload = await listAdminLegacyStpJobs(page.value, pageSize.value, filters.value);
|
||||
const items = (payload as any).items ?? [];
|
||||
rows.value = Array.isArray(items) ? items : [];
|
||||
total.value = Number((payload as any).pagination?.total ?? 0);
|
||||
} catch (exc: any) {
|
||||
error.value = exc?.message || String(exc);
|
||||
rows.value = [];
|
||||
total.value = 0;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetail(jobId: number) {
|
||||
detailLoading.value = true;
|
||||
detail.value = null;
|
||||
replayLastResult.value = null;
|
||||
replayUserAction.value = 'create_revision';
|
||||
try {
|
||||
detail.value = await getAdminLegacyStpJob(jobId);
|
||||
const plan = detail.value.replay_plan;
|
||||
if (plan?.recommended_user_action === 'force_create') {
|
||||
replayUserAction.value = 'force_create';
|
||||
} else if (plan?.recommended_user_action === 'create_revision') {
|
||||
replayUserAction.value = 'create_revision';
|
||||
}
|
||||
} catch (exc: any) {
|
||||
message.error(exc?.message || String(exc));
|
||||
} finally {
|
||||
detailLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onRowClick(row: LegacyStpJobRow) {
|
||||
selectedJobId.value = Number(row.job_id);
|
||||
loadDetail(Number(row.job_id)).catch(() => {});
|
||||
}
|
||||
|
||||
function openCaseInWorkspace(caseNo: string) {
|
||||
router.push({
|
||||
name: 'WorkspaceShippingNotice',
|
||||
query: { case_no: caseNo, focus: 'review_case' },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 【回放按钮】严格只走 /workspace/shipping-notice/order-review-cases/<case_no>/reconcile-and-progress,
|
||||
* 携带 operation_id / legacy_job_id / replay_mode / user_action 四参数。
|
||||
* 禁止任何绕过该 API 的直接 SQL/Job.status 修改。
|
||||
*/
|
||||
async function replaySelected() {
|
||||
if (!detail.value || !detail.value.job.case_no) {
|
||||
message.error(t('admin.legacyStpJobs.replayError_noCaseNo'));
|
||||
return;
|
||||
}
|
||||
const caseNo = String(detail.value.job.case_no).trim();
|
||||
const legacyJobId = Number(detail.value.job.job_id);
|
||||
const replayMode = Boolean(detail.value.replay_plan?.needs_replay_mode);
|
||||
const action = replayUserAction.value;
|
||||
const operationId = crypto.randomUUID
|
||||
? crypto.randomUUID()
|
||||
: String(Date.now()) + '-' + Math.random().toString(36).slice(2);
|
||||
const url = `/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/reconcile-and-progress`;
|
||||
const headers = { 'Content-Type': 'application/json', ...getAuthHeaders() };
|
||||
const body = JSON.stringify({
|
||||
operation_id: operationId,
|
||||
user_action: action,
|
||||
legacy_job_id: legacyJobId,
|
||||
replay_mode: replayMode || action === 'force_create',
|
||||
});
|
||||
replaying.value = true;
|
||||
replayLastResult.value = null;
|
||||
try {
|
||||
const resp = await requestJson<any>(url, { method: 'POST', headers, body });
|
||||
const outcome = (resp as any)?.data?.outcome ?? null;
|
||||
const ok = !!(resp as any)?.success && String(outcome || '') !== 'ERROR';
|
||||
replayLastResult.value = {
|
||||
ok,
|
||||
outcome: outcome,
|
||||
message: (resp as any)?.data?.message ?? null,
|
||||
};
|
||||
if (ok) {
|
||||
message.success(t('admin.legacyStpJobs.replaySuccess', { outcome: String(outcome || '') }));
|
||||
} else {
|
||||
message.error(t('admin.legacyStpJobs.replayRejected', { outcome: String(outcome || '') }));
|
||||
}
|
||||
} catch (exc: any) {
|
||||
const err = exc?.message || String(exc);
|
||||
replayLastResult.value = { ok: false, outcome: 'ERROR', message: err };
|
||||
message.error(err);
|
||||
} finally {
|
||||
replaying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadList);
|
||||
watch([page, pageSize], loadList);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full gap-4 lg:gap-6 p-4 lg:p-6">
|
||||
<div class="flex items-center justify-between flex-wrap gap-3">
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold">{{ t('admin.legacyStpJobs.pageTitle') }}</h2>
|
||||
<p class="text-sm text-gray-600">{{ t('admin.legacyStpJobs.pageSubtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
class="px-3 py-1.5 text-sm rounded border border-gray-300 hover:bg-gray-50"
|
||||
type="button"
|
||||
@click="resetFilters"
|
||||
>
|
||||
{{ t('common.reset') }}
|
||||
</button>
|
||||
<button
|
||||
class="px-3 py-1.5 text-sm rounded bg-indigo-600 text-white hover:bg-indigo-700"
|
||||
type="button"
|
||||
@click="loadList"
|
||||
:disabled="loading"
|
||||
>
|
||||
{{ t('common.refresh') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-5 gap-3">
|
||||
<input
|
||||
v-model="filters.q"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
:placeholder="t('admin.legacyStpJobs.filterQ')"
|
||||
@keyup.enter="page = 1, loadList()"
|
||||
/>
|
||||
<input
|
||||
v-model="filters.case_no"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
:placeholder="t('admin.legacyStpJobs.filterCaseNo')"
|
||||
@keyup.enter="page = 1, loadList()"
|
||||
/>
|
||||
<input
|
||||
v-model="filters.error_code"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
:placeholder="t('admin.legacyStpJobs.filterErrorCode')"
|
||||
@keyup.enter="page = 1, loadList()"
|
||||
/>
|
||||
<select
|
||||
v-model="filters.status"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
@change="page = 1, loadList()"
|
||||
>
|
||||
<option value="">{{ t('admin.legacyStpJobs.statusAll') }}</option>
|
||||
<option v-for="s in LEGACY_STP_JOB_STATUS_OPTIONS" :key="s" :value="s">{{ codeLabel(s) }}</option>
|
||||
</select>
|
||||
<input
|
||||
v-model="filters.created_from"
|
||||
type="datetime-local"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
@change="page = 1, loadList()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-[minmax(0,38%)_1fr] gap-4 lg:gap-6 min-h-0 flex-1">
|
||||
<!-- 左侧列表 -->
|
||||
<section class="flex flex-col min-h-0 border rounded bg-white/60">
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b">
|
||||
<span class="text-sm font-medium">{{ t('admin.legacyStpJobs.listTitle', { count: total }) }}</span>
|
||||
<span v-if="loading" class="text-xs text-gray-500">{{ t('common.loading') }}</span>
|
||||
</div>
|
||||
<div v-if="error" class="p-3 text-sm text-red-700 bg-red-50 border-b">{{ error }}</div>
|
||||
<div class="overflow-auto min-h-0 max-h-[72vh] divide-y">
|
||||
<div
|
||||
v-for="row in rows"
|
||||
:key="row.job_id"
|
||||
class="px-4 py-3 cursor-pointer hover:bg-indigo-50/60"
|
||||
:class="selectedJobId === row.job_id ? 'bg-indigo-50 ring-2 ring-inset ring-indigo-300' : ''"
|
||||
@click="onRowClick(row)"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<span class="font-mono text-xs bg-gray-100 px-2 py-0.5 rounded">#{{ row.job_id }}</span>
|
||||
<span
|
||||
class="text-xs px-2 py-0.5 rounded"
|
||||
:class="row.status === 'failed' ? 'bg-red-100 text-red-700' : 'bg-gray-200 text-gray-700'"
|
||||
>{{ codeLabel(row.status) }}</span>
|
||||
<span class="truncate text-xs text-gray-500">{{ row.case_no || row.business_ref || '—' }}</span>
|
||||
</div>
|
||||
<div class="mt-1.5 text-sm">
|
||||
<span class="text-gray-700">{{ codeLabel(row.blocking_reason || row.error_code || '', 'admin.legacyStpJobs.reasonCodes') }}</span>
|
||||
<span class="mx-2 text-gray-300">·</span>
|
||||
<span class="text-xs text-gray-500">{{ row.attempts }}/{{ row.max_attempts }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right text-xs text-gray-500 leading-5 shrink-0">
|
||||
<div>{{ formatTime(row.created_at) }}</div>
|
||||
<div v-if="row.finished_at">→ {{ formatTime(row.finished_at) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!rows.length && !loading" class="p-8 text-center text-sm text-gray-500">
|
||||
{{ t('admin.legacyStpJobs.empty') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between px-4 py-2 border-t text-sm">
|
||||
<span class="text-gray-500">{{ t('common.pageOf', { page, total: Math.max(1, Math.ceil(total / pageSize)) }) }}</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button
|
||||
class="px-2 py-1 rounded border disabled:opacity-50"
|
||||
:disabled="page <= 1"
|
||||
type="button"
|
||||
@click="page -= 1"
|
||||
>{{ t('common.prev') }}</button>
|
||||
<button
|
||||
class="px-2 py-1 rounded border disabled:opacity-50"
|
||||
:disabled="page * pageSize >= total"
|
||||
type="button"
|
||||
@click="page += 1"
|
||||
>{{ t('common.next') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 右侧详情 -->
|
||||
<section class="flex flex-col min-h-0 border rounded bg-white/60">
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b">
|
||||
<span class="text-sm font-medium">{{ t('admin.legacyStpJobs.detailTitle') }}</span>
|
||||
<span v-if="detailLoading" class="text-xs text-gray-500">{{ t('common.loading') }}</span>
|
||||
</div>
|
||||
<div v-if="!detail && !detailLoading" class="p-8 text-center text-sm text-gray-500">
|
||||
{{ t('admin.legacyStpJobs.detailEmpty') }}
|
||||
</div>
|
||||
<div v-else-if="detail" class="overflow-auto min-h-0 max-h-[72vh] px-5 py-4 space-y-5">
|
||||
<!-- 摘要行 -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3 text-sm">
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.job') }}</div>
|
||||
<div class="font-mono">#{{ detail.job.job_id }} · {{ codeLabel(detail.job.status) }}</div>
|
||||
<div class="mt-1 text-xs text-gray-500">attempts: {{ detail.job.attempts }}/{{ detail.job.max_attempts }}</div>
|
||||
</div>
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.reviewCase') }}</div>
|
||||
<button
|
||||
v-if="detail.job.case_no"
|
||||
class="text-indigo-600 hover:underline font-mono"
|
||||
type="button"
|
||||
@click="openCaseInWorkspace(detail.job.case_no!)"
|
||||
>{{ detail.job.case_no }}</button>
|
||||
<span v-else class="text-gray-400">—</span>
|
||||
<div class="mt-1 text-xs text-gray-500 truncate">{{ detail.job.business_ref || '—' }}</div>
|
||||
</div>
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.blocking') }}</div>
|
||||
<div class="font-medium">{{ codeLabel(detail.job.blocking_reason || detail.job.error_code || '', 'admin.legacyStpJobs.reasonCodes') }}</div>
|
||||
<div class="mt-1 text-xs text-gray-500 truncate">{{ detail.job.message || detail.job.error_message || '—' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 回链 Case:若存在则展示 8 字段 -->
|
||||
<div v-if="detail.case" class="border rounded p-4">
|
||||
<div class="text-sm font-medium mb-2">{{ t('admin.legacyStpJobs.linkedCase') }}</div>
|
||||
<dl class="grid grid-cols-2 md:grid-cols-4 gap-3 text-sm">
|
||||
<div><dt class="text-xs text-gray-500">case_id</dt><dd class="font-mono">{{ detail.case.case_id }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">{{ t('admin.legacyStpJobs.caseStatus') }}</dt><dd>{{ detail.case.status }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">candidate_id</dt><dd class="font-mono">{{ detail.case.candidate_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">confirmed_task_id</dt><dd class="font-mono">{{ detail.case.confirmed_task_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">document_id</dt><dd class="font-mono">{{ detail.case.document_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">owner_user_id</dt><dd class="font-mono">{{ detail.case.owner_user_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">{{ t('common.createdAt') }}</dt><dd>{{ formatTime(detail.case.created_at) }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">{{ t('common.updatedAt') }}</dt><dd>{{ formatTime(detail.case.updated_at) }}</dd></div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<!-- 回放计划:推荐动作 + 回放按钮 -->
|
||||
<div class="border rounded p-4 bg-amber-50/60">
|
||||
<div class="text-sm font-medium mb-2">{{ t('admin.legacyStpJobs.replayPlan') }}</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 items-center">
|
||||
<div class="text-sm space-y-1">
|
||||
<div>
|
||||
<span class="text-gray-500 mr-2">{{ t('admin.legacyStpJobs.recommendedAction') }}:</span>
|
||||
<span class="px-2 py-0.5 rounded bg-white border text-sm">
|
||||
{{ actionLabel(detail.replay_plan.recommended_user_action) }}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500 mr-2">{{ t('admin.legacyStpJobs.needsReplayMode') }}:</span>
|
||||
<span :class="detail.replay_plan.needs_replay_mode ? 'text-amber-700 font-medium' : 'text-gray-500'">
|
||||
{{ detail.replay_plan.needs_replay_mode ? t('common.yes') : t('common.no') }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="detail.replay_plan.reconcile_and_progress_endpoint" class="font-mono text-xs text-gray-500 break-all">
|
||||
POST {{ detail.replay_plan.reconcile_and_progress_endpoint }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 md:items-end">
|
||||
<label class="flex items-center gap-2 text-sm md:justify-end">
|
||||
<span class="text-gray-600 w-32">{{ t('admin.legacyStpJobs.userAction') }}</span>
|
||||
<select v-model="replayUserAction" class="px-3 py-1.5 border rounded text-sm">
|
||||
<option value="auto">{{ actionLabel('auto') }}</option>
|
||||
<option value="reuse_existing">{{ actionLabel('reuse_existing') }}</option>
|
||||
<option value="create_revision">{{ actionLabel('create_revision') }}</option>
|
||||
<option value="force_create">{{ actionLabel('force_create') }}</option>
|
||||
<option value="adjudicate">{{ actionLabel('adjudicate') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<button
|
||||
class="px-4 py-2 rounded bg-indigo-600 text-white hover:bg-indigo-700 disabled:opacity-60 max-w-xs"
|
||||
type="button"
|
||||
:disabled="replaying || !detail.job.case_no"
|
||||
@click="replaySelected"
|
||||
>
|
||||
{{ replaying ? t('common.loading') : t('admin.legacyStpJobs.replayButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="replayLastResult" class="mt-3 text-sm border-t pt-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="text-xs px-2 py-0.5 rounded"
|
||||
:class="replayLastResult.ok ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
|
||||
>
|
||||
{{ replayLastResult.ok ? t('common.ok') : t('common.error') }}
|
||||
</span>
|
||||
<span class="font-mono text-xs bg-white border rounded px-2 py-0.5">{{ replayLastResult.outcome ?? '—' }}</span>
|
||||
</div>
|
||||
<div v-if="replayLastResult.message" class="mt-1.5 text-xs text-gray-600 whitespace-pre-wrap break-all">
|
||||
{{ replayLastResult.message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 原始 JSON:payload / result(masked) -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.payloadJson') }}</div>
|
||||
<pre class="text-xs whitespace-pre-wrap break-all bg-gray-50 p-2 rounded max-h-64 overflow-auto">{{ jsonFormat(detail.job.payload_json_masked) }}</pre>
|
||||
</div>
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.resultJson') }}</div>
|
||||
<pre class="text-xs whitespace-pre-wrap break-all bg-gray-50 p-2 rounded max-h-64 overflow-auto">{{ jsonFormat(detail.job.result_json_masked) }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+4
-4
@@ -99,17 +99,17 @@ describe('OrderProfileXfaConfirmStep', () => {
|
||||
});
|
||||
|
||||
const wrapper = mountStep();
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('datasets / data / ITEMS / DATA'));
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('datasets / data / ITEMS / DATA'), { timeout: 10000 });
|
||||
expect(wrapper.find('input[type="radio"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('创建前阻断项');
|
||||
});
|
||||
}, 15000);
|
||||
|
||||
it('没有任何候选集合时才显示空状态', async () => {
|
||||
getFieldTree.mockResolvedValue({ tree: {} });
|
||||
getCollections.mockResolvedValue({ collection_candidates: [], excluded_collection_candidates: [] });
|
||||
|
||||
const wrapper = mountStep();
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('没有可用数据集'));
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('没有可用数据集'), { timeout: 10000 });
|
||||
expect(wrapper.find('input[type="radio"]').exists()).toBe(false);
|
||||
});
|
||||
}, 15000);
|
||||
});
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcMergePreviewTable.vue
|
||||
用途:三来源候选合并预览表。严格后端决定 UI,只按后端返回的 resolution/decision_status 着色,
|
||||
绝不 if/else 推导合并结果。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section E(VCMergedObservationCandidate);
|
||||
所有着色规则由 resolutionClass 查表映射,禁止前端自行推导业务状态。
|
||||
逻辑:只读展示,无 emit。空态显示「暂无预览数据,请点击预览按钮」。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { VCMergedObservationCandidate } from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
defineProps<{
|
||||
candidates: VCMergedObservationCandidate[];
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
function sourceColorClass(source: string): string {
|
||||
if (source === 'header_region') return 'vc-map__src-header';
|
||||
if (source === 'table_column') return 'vc-map__src-table';
|
||||
if (source === 'vendor_comments') return 'vc-map__src-vc';
|
||||
return '';
|
||||
}
|
||||
|
||||
function resolutionClass(resolution: string, decisionStatus: string): string {
|
||||
const key = `${resolution}|${decisionStatus}`;
|
||||
const classMap: Record<string, string> = {
|
||||
'needs_review|pending': 'bg-red-50 text-red-700 border-red-200',
|
||||
'needs_review|needs_review': 'bg-red-50 text-red-700 border-red-200',
|
||||
'same_value_merged|accepted': 'bg-emerald-50 text-emerald-700 border-emerald-200',
|
||||
'single_source_direct|accepted': 'bg-green-50 text-green-700 border-green-200',
|
||||
'fill_missing|accepted': 'bg-sky-50 text-sky-700 border-sky-200',
|
||||
'annotation_only_dropped|accepted': 'bg-gray-50 text-gray-500 line-through',
|
||||
'annotation_only_dropped|missing': 'bg-gray-50 text-gray-500 line-through',
|
||||
'invalid_line_reference|blocked': 'bg-gray-50 text-gray-500 line-through',
|
||||
'no_value|missing': 'bg-gray-50 text-gray-500 line-through',
|
||||
};
|
||||
return classMap[key] ?? '';
|
||||
}
|
||||
|
||||
function resolutionBadge(resolution: string): string {
|
||||
const labelMap: Record<string, string> = {
|
||||
same_value_merged: '同值合并',
|
||||
fill_missing: '补空',
|
||||
needs_review: '需复核',
|
||||
no_value: '无值',
|
||||
single_source_direct: '单源直达',
|
||||
annotation_only_dropped: '仅备注(丢弃)',
|
||||
};
|
||||
return labelMap[resolution] ?? resolution;
|
||||
}
|
||||
|
||||
function conflictGroupKey(cand: VCMergedObservationCandidate): string {
|
||||
return `[${cand.target_scope}] ${cand.target_field_code} #${cand.effective_line_no ?? 'H'}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="vc-merge-preview">
|
||||
<div v-if="candidates.length === 0" class="vc-merge-preview__empty">
|
||||
<p v-if="loading">预览加载中…</p>
|
||||
<p v-else>暂无预览数据,请点击预览按钮</p>
|
||||
</div>
|
||||
<div v-else class="vc-merge-preview__body">
|
||||
<div
|
||||
v-for="(cand, i) in candidates"
|
||||
:key="i"
|
||||
class="vc-merge-preview__row"
|
||||
:class="resolutionClass(cand.resolution, cand.decision_status)"
|
||||
>
|
||||
<div class="vc-merge-preview__row-main">
|
||||
<div class="vc-merge-preview__key">
|
||||
<strong>{{ conflictGroupKey(cand) }}</strong>
|
||||
</div>
|
||||
<div class="vc-merge-preview__badge">
|
||||
<span class="vc-merge-preview__resolution" :class="`vc-merge-preview__resolution--${cand.resolution}`">
|
||||
{{ resolutionBadge(cand.resolution) }}
|
||||
</span>
|
||||
<span class="vc-merge-preview__status">
|
||||
{{ cand.decision_status }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="vc-merge-preview__accepted">
|
||||
<template v-if="cand.decision_status === 'needs_review' || cand.resolution === 'needs_review'">
|
||||
<span class="vc-merge-preview__needs-review">
|
||||
⚠ 需人工复核
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span v-if="cand.accepted_value !== null && cand.accepted_value !== undefined">
|
||||
accepted_value:<code>{{ cand.accepted_value }}</code>
|
||||
</span>
|
||||
<span v-else class="vc-merge-preview__muted">
|
||||
accepted_value:—
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="vc-merge-preview__conflicts">
|
||||
<div class="vc-merge-preview__conflicts-title">
|
||||
来源快照 ({{ cand.source_observations.length }})
|
||||
</div>
|
||||
<ul class="vc-map__src-list">
|
||||
<li
|
||||
v-for="(obs, j) in cand.source_observations"
|
||||
:key="j"
|
||||
:class="sourceColorClass(obs.source)"
|
||||
>
|
||||
<span class="vc-map__src-tag">{{ obs.source }}</span>
|
||||
<code>{{ obs.normalized_value }}</code>
|
||||
<small v-if="obs.format_valid === false" class="vc-map__format-invalid">
|
||||
(format: {{ obs.format_reason_code }})
|
||||
</small>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="cand.conflicts && cand.conflicts.length > 0" class="vc-merge-preview__conflicts-detail">
|
||||
<details>
|
||||
<summary>冲突详情 ({{ cand.conflicts.length }})</summary>
|
||||
<pre>{{ JSON.stringify(cand.conflicts, null, 2) }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-merge-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-merge-preview__empty {
|
||||
padding: 20px 10px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.82rem;
|
||||
border: 1px dashed var(--border-default);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.vc-merge-preview__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-merge-preview__row {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-merge-preview__row-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-merge-preview__key {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.vc-merge-preview__badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-merge-preview__resolution {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
border: 1px solid;
|
||||
}
|
||||
.vc-merge-preview__resolution--same_value_merged {
|
||||
background: rgba(16, 185, 129, 0.1);
|
||||
border-color: rgba(16, 185, 129, 0.3);
|
||||
color: #047857;
|
||||
}
|
||||
.vc-merge-preview__resolution--single_source_direct {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
border-color: rgba(34, 197, 94, 0.3);
|
||||
color: #15803d;
|
||||
}
|
||||
.vc-merge-preview__resolution--fill_missing {
|
||||
background: rgba(14, 165, 233, 0.1);
|
||||
border-color: rgba(14, 165, 233, 0.3);
|
||||
color: #0369a1;
|
||||
}
|
||||
.vc-merge-preview__resolution--needs_review {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border-color: rgba(239, 68, 68, 0.3);
|
||||
color: #b91c1c;
|
||||
}
|
||||
.vc-merge-preview__resolution--annotation_only_dropped,
|
||||
.vc-merge-preview__resolution--no_value {
|
||||
background: rgba(107, 114, 128, 0.1);
|
||||
border-color: rgba(107, 114, 128, 0.3);
|
||||
color: #4b5563;
|
||||
}
|
||||
.vc-merge-preview__status {
|
||||
font-size: 0.72rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-merge-preview__accepted {
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.vc-merge-preview__needs-review {
|
||||
color: #b91c1c;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vc-merge-preview__muted {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-merge-preview__conflicts {
|
||||
padding-top: 6px;
|
||||
border-top: 1px dashed var(--border-default);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-merge-preview__conflicts-title {
|
||||
font-size: 0.78rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.vc-map__src-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__src-tag {
|
||||
display: inline-block;
|
||||
padding: 1px 6px;
|
||||
border-radius: 10px;
|
||||
font-size: 0.7rem;
|
||||
margin-right: 4px;
|
||||
color: white;
|
||||
}
|
||||
.vc-map__src-header .vc-map__src-tag { background: #3b82f6; }
|
||||
.vc-map__src-table .vc-map__src-tag { background: #10b981; }
|
||||
.vc-map__src-vc .vc-map__src-tag { background: #f59e0b; }
|
||||
.vc-map__format-invalid {
|
||||
color: var(--text-danger);
|
||||
margin-left: 4px;
|
||||
}
|
||||
code {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
background: var(--bg-elevated);
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-merge-preview__conflicts-detail {
|
||||
margin-top: 4px;
|
||||
}
|
||||
.vc-merge-preview__conflicts-detail summary {
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-merge-preview__conflicts-detail pre {
|
||||
margin: 6px 0 0 0;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-elevated);
|
||||
font-size: 0.72rem;
|
||||
max-height: 160px;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
+432
@@ -0,0 +1,432 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcNamedRegionBox.vue
|
||||
用途:Vendor Comments 命名区域圈选框——薄封装 OrderProfileDocumentCanvas,维护 dedicated regions。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section A/H、OrderProfileDocumentCanvas。
|
||||
逻辑:不做任何 save,所有写操作走 emit 父级;region/page_scope/selection_mode 四元组变更触发
|
||||
VCProfileDraftTrigger(reasons: named_region_*),仅负责前端门禁,真实判定在后端。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import OrderProfileDocumentCanvas from './OrderProfileDocumentCanvas.vue';
|
||||
import type {
|
||||
OrderProfileCanvasRegion,
|
||||
OrderProfilePreviewPageGrant,
|
||||
OrderProfileRelativeRegion,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.types';
|
||||
import type {
|
||||
VCNamedRegion,
|
||||
VCNamedRegionPageScope,
|
||||
VCNamedRegionSelectionMode,
|
||||
VCProfileDraftTrigger,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
type VCNamedRegionCreatePartial = {
|
||||
label: string;
|
||||
page_scope: VCNamedRegionPageScope;
|
||||
selection_mode: VCNamedRegionSelectionMode;
|
||||
region: OrderProfileRelativeRegion;
|
||||
};
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
profileId: number | null;
|
||||
grant?: OrderProfilePreviewPageGrant | null;
|
||||
pageNo: number;
|
||||
pageCount: number;
|
||||
previewPagePath?: string | null;
|
||||
namedRegions: Record<string, VCNamedRegion>;
|
||||
selectedRegionId: string | null;
|
||||
regionOptions?: {
|
||||
page_scope_options?: { value: string; label: string }[];
|
||||
};
|
||||
readonly?: boolean;
|
||||
}>(), {
|
||||
regionOptions: () => ({}),
|
||||
readonly: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:namedRegions': [regions: Record<string, VCNamedRegion>];
|
||||
select: [regionId: string];
|
||||
create: [partial: VCNamedRegionCreatePartial];
|
||||
change: [regionId: string, patch: Partial<VCNamedRegion>];
|
||||
delete: [regionId: string];
|
||||
draftRequired: [trigger: VCProfileDraftTrigger];
|
||||
}>();
|
||||
|
||||
const defaultPageScopeOptions = computed(() => {
|
||||
if (props.regionOptions?.page_scope_options?.length) {
|
||||
return props.regionOptions.page_scope_options;
|
||||
}
|
||||
return [
|
||||
{ value: 'first_page', label: '首页' },
|
||||
{ value: 'last_page', label: '末页' },
|
||||
{ value: 'exact_page', label: '指定页' },
|
||||
];
|
||||
});
|
||||
|
||||
const selectionModeOptions: { value: VCNamedRegionSelectionMode; label: string }[] = [
|
||||
{ value: 'fixed_region', label: '固定区域 (box)' },
|
||||
{ value: 'auto_take_last_qualified', label: '取末段合格 (paragraph)' },
|
||||
];
|
||||
|
||||
const selectedOrderRegionId = computed(() => {
|
||||
return props.selectedRegionId ? `vc:${props.selectedRegionId}` : null;
|
||||
});
|
||||
|
||||
const canvasRegions = computed<OrderProfileCanvasRegion[]>(() => {
|
||||
const regions: OrderProfileCanvasRegion[] = [];
|
||||
Object.values(props.namedRegions || {}).forEach((nr) => {
|
||||
let pageNo = props.pageNo;
|
||||
if (nr.page_scope === 'exact_page' && nr.page_no) {
|
||||
pageNo = nr.page_no;
|
||||
}
|
||||
regions.push({
|
||||
id: `vc:${nr.region_id}`,
|
||||
kind: 'xfa_visual',
|
||||
label: nr.label,
|
||||
region: { ...nr.region },
|
||||
pageNo,
|
||||
});
|
||||
});
|
||||
return regions;
|
||||
});
|
||||
|
||||
const priorSnapshot = ref<string>('');
|
||||
|
||||
function snapshotRegions(): string {
|
||||
const entries = Object.entries(props.namedRegions || {})
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([id, r]) => `${id}|${r.label}|${r.page_scope}|${r.selection_mode}|${JSON.stringify(r.region)}`);
|
||||
return entries.join('||');
|
||||
}
|
||||
|
||||
watch(() => snapshotRegions(), (next, prev) => {
|
||||
if (!prev || !next || next === prev) return;
|
||||
const prevMap = props.namedRegions || {};
|
||||
const reasons: VCProfileDraftTrigger['reasons'] = [];
|
||||
const prevIds = new Set(Object.keys(prevMap));
|
||||
const nextIds = new Set(Object.keys(prevMap));
|
||||
prevIds.forEach((id) => {
|
||||
if (!nextIds.has(id)) {
|
||||
reasons.push({ kind: 'named_region_removed', region_id: id });
|
||||
}
|
||||
});
|
||||
nextIds.forEach((id) => {
|
||||
if (!prevIds.has(id)) {
|
||||
reasons.push({ kind: 'named_region_added', region_id: id });
|
||||
}
|
||||
});
|
||||
nextIds.forEach((id) => {
|
||||
if (!prevIds.has(id)) return;
|
||||
const prev = prevMap[id];
|
||||
const nextR = prevMap[id];
|
||||
if (!prev || !nextR) return;
|
||||
if (prev.page_scope !== nextR.page_scope) {
|
||||
reasons.push({ kind: 'named_region_scope', region_id: id });
|
||||
}
|
||||
const prevGeo = `${prev.region.x0},${prev.region.y0},${prev.region.x1},${prev.region.y1}`;
|
||||
const nextGeo = `${nextR.region.x0},${nextR.region.y0},${nextR.region.x1},${nextR.region.y1}`;
|
||||
if (prevGeo !== nextGeo) {
|
||||
reasons.push({ kind: 'named_region_geometry', region_id: id });
|
||||
}
|
||||
});
|
||||
if (reasons.length > 0) {
|
||||
emit('draftRequired', {
|
||||
named_regions_changed: true,
|
||||
field_source_mappings_changed: false,
|
||||
requires_draft_reset: true,
|
||||
reasons,
|
||||
});
|
||||
}
|
||||
}, { flush: 'post' });
|
||||
|
||||
priorSnapshot.value = snapshotRegions();
|
||||
|
||||
function onCanvasSelect(regionId: string): void {
|
||||
if (!regionId.startsWith('vc:')) return;
|
||||
emit('select', regionId.slice(3));
|
||||
}
|
||||
|
||||
function onCanvasCreate(region: OrderProfileCanvasRegion['region']): void {
|
||||
const count = Object.keys(props.namedRegions || {}).length;
|
||||
emit('create', {
|
||||
label: `Vendor Comments ${count + 1}`,
|
||||
page_scope: 'first_page',
|
||||
selection_mode: 'fixed_region',
|
||||
region,
|
||||
});
|
||||
}
|
||||
|
||||
function onCanvasChange(regionId: string, region: OrderProfileCanvasRegion['region']): void {
|
||||
if (!regionId.startsWith('vc:')) return;
|
||||
const id = regionId.slice(3);
|
||||
emit('change', id, { region });
|
||||
}
|
||||
|
||||
function updateLabel(regionId: string, label: string): void {
|
||||
emit('change', regionId, { label });
|
||||
}
|
||||
|
||||
function updatePageScope(regionId: string, pageScope: VCNamedRegionPageScope): void {
|
||||
emit('change', regionId, { page_scope: pageScope });
|
||||
}
|
||||
|
||||
function updateSelectionMode(regionId: string, mode: VCNamedRegionSelectionMode): void {
|
||||
emit('change', regionId, { selection_mode: mode });
|
||||
}
|
||||
|
||||
function updatePageNo(regionId: string, pageNo: number | null): void {
|
||||
emit('change', regionId, { page_no: pageNo });
|
||||
}
|
||||
|
||||
function addRegion(): void {
|
||||
const count = Object.keys(props.namedRegions || {}).length;
|
||||
emit('create', {
|
||||
label: `Vendor Comments ${count + 1}`,
|
||||
page_scope: 'first_page',
|
||||
selection_mode: 'fixed_region',
|
||||
region: { x0: 0.1, y0: 0.1, x1: 0.9, y1: 0.15 },
|
||||
});
|
||||
}
|
||||
|
||||
const orderedRegions = computed(() => {
|
||||
return Object.values(props.namedRegions || {}).sort((a, b) => (
|
||||
a.label.localeCompare(b.label)
|
||||
));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="vc-named-region-box">
|
||||
<div class="vc-named-region-box__toolbar">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
class="vc-named-region-box__add-btn"
|
||||
@click="addRegion"
|
||||
>
|
||||
新增 Vendor Comments 区域
|
||||
</button>
|
||||
</div>
|
||||
<div class="vc-named-region-box__body">
|
||||
<aside class="vc-named-region-box__sidebar">
|
||||
<ul v-if="orderedRegions.length" class="vc-named-region-box__list">
|
||||
<li
|
||||
v-for="nr in orderedRegions"
|
||||
:key="nr.region_id"
|
||||
class="vc-named-region-box__item"
|
||||
:class="{ 'is-selected': selectedRegionId === nr.region_id }"
|
||||
@click="emit('select', nr.region_id)"
|
||||
>
|
||||
<div class="vc-named-region-box__item-header">
|
||||
<input
|
||||
class="vc-named-region-box__label-input"
|
||||
:disabled="readonly"
|
||||
:value="nr.label"
|
||||
@input="updateLabel(nr.region_id, ($event.target as HTMLInputElement).value)"
|
||||
@click.stop
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="vc-named-region-box__delete-btn"
|
||||
:disabled="readonly"
|
||||
@click.stop="emit('delete', nr.region_id)"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<div class="vc-named-region-box__item-fields">
|
||||
<label>
|
||||
页范围
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="nr.page_scope"
|
||||
@change.stop="updatePageScope(nr.region_id, ($event.target as HTMLSelectElement).value as VCNamedRegionPageScope)"
|
||||
>
|
||||
<option
|
||||
v-for="opt in defaultPageScopeOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-if="nr.page_scope === 'exact_page'">
|
||||
页码
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
:max="pageCount || undefined"
|
||||
:disabled="readonly"
|
||||
:value="nr.page_no ?? ''"
|
||||
@input.stop="updatePageNo(nr.region_id, ($event.target as HTMLInputElement).value === '' ? null : Number(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
选择模式
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="nr.selection_mode"
|
||||
@change.stop="updateSelectionMode(nr.region_id, ($event.target as HTMLSelectElement).value as VCNamedRegionSelectionMode)"
|
||||
>
|
||||
<option
|
||||
v-for="opt in selectionModeOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="vc-named-region-box__empty">
|
||||
暂无命名区域,点击上方按钮新增或在画布上拖动圈选。
|
||||
</p>
|
||||
</aside>
|
||||
<div class="vc-named-region-box__canvas">
|
||||
<OrderProfileDocumentCanvas
|
||||
:profile-id="profileId"
|
||||
:grant="grant"
|
||||
:preview-page-path="previewPagePath"
|
||||
:mode="readonly ? 'readonly' : 'edit'"
|
||||
:regions="canvasRegions"
|
||||
:selected-region-id="selectedOrderRegionId"
|
||||
:creation-kind="readonly ? null : 'xfa_visual'"
|
||||
:page-no="pageNo"
|
||||
:page-count="pageCount"
|
||||
annotation-tool-set="xfa_visual"
|
||||
@select="onCanvasSelect"
|
||||
@create="onCanvasCreate"
|
||||
@change="onCanvasChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-named-region-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
.vc-named-region-box__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-named-region-box__add-btn {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.vc-named-region-box__add-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-named-region-box__body {
|
||||
display: grid;
|
||||
grid-template-columns: 280px 1fr;
|
||||
gap: 8px;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.vc-named-region-box__sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-named-region-box__list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-named-region-box__item {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
cursor: pointer;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-named-region-box__item.is-selected {
|
||||
border-color: var(--accent-primary);
|
||||
box-shadow: 0 0 0 1px var(--accent-primary);
|
||||
}
|
||||
.vc-named-region-box__item-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.vc-named-region-box__label-input {
|
||||
flex: 1;
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.vc-named-region-box__delete-btn {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
color: var(--text-danger);
|
||||
}
|
||||
.vc-named-region-box__delete-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-named-region-box__item-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-named-region-box__item-fields label {
|
||||
display: grid;
|
||||
grid-template-columns: 56px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-named-region-box__item-fields select,
|
||||
.vc-named-region-box__item-fields input {
|
||||
padding: 3px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.78rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.vc-named-region-box__empty {
|
||||
margin: 0;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
text-align: center;
|
||||
padding: 16px 8px;
|
||||
}
|
||||
.vc-named-region-box__canvas {
|
||||
min-height: 0;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
</style>
|
||||
+544
@@ -0,0 +1,544 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcSourceMappingPanel.vue
|
||||
用途:薄编排主面板——只做顶层三开关 + 引入 VcSourceMappingSection * 3 + VcSplitRuleEditor
|
||||
(抽屉/modal)+ VcMergePreviewTable。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section B/C/D/E/H/I;
|
||||
子组件:VcSourceMappingSection、VcSplitRuleEditor、VcMergePreviewTable。
|
||||
逻辑:emit update:definition 写回完整 patch;field_source_mappings 任何改动 + split_rules
|
||||
改动触发 VCProfileDraftTrigger(聚合所有子 trigger)。
|
||||
Props / Emits 保留原来的契约,确保父级零修改可切换。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import type {
|
||||
VCMergedObservationCandidate,
|
||||
VCProfileDefinitionExtensions,
|
||||
VCProfileDraftTrigger,
|
||||
VCProfileFieldSourceMapping,
|
||||
VCSplitRuleSet,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
import VcSourceMappingSection from './VcSourceMappingSection.vue';
|
||||
import VcSplitRuleEditor from './VcSplitRuleEditor.vue';
|
||||
import VcMergePreviewTable from './VcMergePreviewTable.vue';
|
||||
|
||||
type VCProfileFieldSourceMappingPatch = Partial<VCProfileFieldSourceMapping>;
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
definition: VCProfileDefinitionExtensions;
|
||||
selectedFieldCode: string;
|
||||
targetScopes?: Array<'header' | 'line'>;
|
||||
readonly?: boolean;
|
||||
documentId: number;
|
||||
profileId: number;
|
||||
dirtyUnsaved?: boolean;
|
||||
persistedConfirmed?: boolean;
|
||||
canPreview?: boolean;
|
||||
}>(), {
|
||||
selectedFieldCode: 'reservation_id',
|
||||
targetScopes: () => ['header', 'line'],
|
||||
readonly: false,
|
||||
dirtyUnsaved: false,
|
||||
persistedConfirmed: false,
|
||||
canPreview: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:definition': [patch: VCProfileDefinitionExtensions];
|
||||
draftRequired: [trigger: VCProfileDraftTrigger];
|
||||
'vc:split-panel-confirmed': [
|
||||
rules: VCSplitRuleSet[],
|
||||
confirmationTokens: Record<string, string>,
|
||||
fieldCode: string,
|
||||
];
|
||||
}>();
|
||||
|
||||
function newClientId(): string {
|
||||
return `map-${crypto.randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
|
||||
const DEFAULT_FORMAT_POLICY = {
|
||||
mode: 'inherit_global' as const,
|
||||
pattern: null,
|
||||
max_capture_groups: 1,
|
||||
timeout_ms: 500,
|
||||
case_sensitive: false,
|
||||
};
|
||||
|
||||
const EMPTY_MAPPING_BASE = (fieldCode: string, targetScope: 'header' | 'line'): VCProfileFieldSourceMapping => ({
|
||||
mapping_id: newClientId(),
|
||||
target_scope: targetScope,
|
||||
target_field_code: fieldCode,
|
||||
target_field_id: '',
|
||||
header_source_enabled: false,
|
||||
header_source_ref: null,
|
||||
header_normalizer_key: null,
|
||||
table_source_enabled: false,
|
||||
table_column_code: null,
|
||||
vendor_comments_enabled: false,
|
||||
vendor_comments_region_ref: null,
|
||||
vendor_comments_split_rule_set: null,
|
||||
relation_policy: 'bind_target_line',
|
||||
missing_relation_policy: 'default_all_lines',
|
||||
line_reference_basis: 'classified_logical_line_no',
|
||||
fill_missing_from_other_sources: true,
|
||||
format_policy: { ...DEFAULT_FORMAT_POLICY },
|
||||
});
|
||||
|
||||
const activeMappings = computed(() => {
|
||||
const list = props.definition?.field_source_mappings || [];
|
||||
return list.filter((m) => m.target_field_code === props.selectedFieldCode);
|
||||
});
|
||||
|
||||
const headerMapping = computed(() => activeMappings.value.find((m) => m.target_scope === 'header') || null);
|
||||
const lineMapping = computed(() => activeMappings.value.find((m) => m.target_scope === 'line') || null);
|
||||
|
||||
const scopeOptions = computed(() => (
|
||||
props.targetScopes.map((s) => ({
|
||||
value: s,
|
||||
label: s === 'header' ? 'Header (订单头)' : 'Line (明细行)',
|
||||
}))
|
||||
));
|
||||
|
||||
const splitEditorVisible = ref(false);
|
||||
const splitEditorScope = ref<'header' | 'line'>('line');
|
||||
|
||||
const splitEditorRuleSet = computed<VCSplitRuleSet | null>(() => {
|
||||
const mapping = splitEditorScope.value === 'header' ? headerMapping.value : lineMapping.value;
|
||||
return mapping?.vendor_comments_split_rule_set ?? null;
|
||||
});
|
||||
|
||||
const mergeLoading = ref(false);
|
||||
const mergePreviewResults = ref<VCMergedObservationCandidate[]>([]);
|
||||
|
||||
function cloneDefinitionForWrite(): VCProfileDefinitionExtensions {
|
||||
return {
|
||||
named_regions: props.definition?.named_regions ? { ...props.definition.named_regions } : null,
|
||||
field_source_mappings: props.definition?.field_source_mappings
|
||||
? props.definition.field_source_mappings.map((m) => ({ ...m }))
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
function ensureMapping(scope: 'header' | 'line'): VCProfileFieldSourceMapping {
|
||||
const existing = scope === 'header' ? headerMapping.value : lineMapping.value;
|
||||
if (existing) return existing;
|
||||
const fresh = EMPTY_MAPPING_BASE(props.selectedFieldCode, scope);
|
||||
const patch = cloneDefinitionForWrite();
|
||||
patch.field_source_mappings = [...(patch.field_source_mappings || []), fresh];
|
||||
emit('update:definition', patch);
|
||||
emitDraftTriggerAggregated({
|
||||
reasons: [{ kind: 'field_source_mapping_added', mapping_id: fresh.mapping_id }],
|
||||
changed: true,
|
||||
});
|
||||
return fresh;
|
||||
}
|
||||
|
||||
function updateMapping(mappingId: string, patchFields: VCProfileFieldSourceMappingPatch): void {
|
||||
const patch = cloneDefinitionForWrite();
|
||||
const list = patch.field_source_mappings || [];
|
||||
const idx = list.findIndex((m) => m.mapping_id === mappingId);
|
||||
if (idx < 0) return;
|
||||
const current = list[idx];
|
||||
if (!current) return;
|
||||
const before = JSON.stringify(current);
|
||||
list[idx] = { ...current, ...patchFields };
|
||||
patch.field_source_mappings = list;
|
||||
emit('update:definition', patch);
|
||||
const after = JSON.stringify(list[idx]);
|
||||
if (before === after) return;
|
||||
|
||||
const beforeObj = JSON.parse(before) as VCProfileFieldSourceMapping;
|
||||
const afterObj = JSON.parse(after) as VCProfileFieldSourceMapping;
|
||||
const reasons: VCProfileDraftTrigger['reasons'] = [];
|
||||
|
||||
if (
|
||||
beforeObj.format_policy?.mode !== afterObj.format_policy?.mode
|
||||
|| beforeObj.format_policy?.pattern !== afterObj.format_policy?.pattern
|
||||
|| beforeObj.format_policy?.max_capture_groups !== afterObj.format_policy?.max_capture_groups
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
const enabledKeys = [
|
||||
'header_source_enabled',
|
||||
'table_source_enabled',
|
||||
'vendor_comments_enabled',
|
||||
] as const;
|
||||
let hasEnabledChange = false;
|
||||
for (const k of enabledKeys) {
|
||||
if (beforeObj[k] !== afterObj[k]) {
|
||||
hasEnabledChange = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasEnabledChange) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
beforeObj.vendor_comments_region_ref !== afterObj.vendor_comments_region_ref
|
||||
|| beforeObj.table_column_code !== afterObj.table_column_code
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
if (reasons.length === 0) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
emitDraftTriggerAggregated({ reasons, changed: true });
|
||||
}
|
||||
|
||||
function emitDraftTriggerAggregated(opts: {
|
||||
reasons: VCProfileDraftTrigger['reasons'];
|
||||
changed: boolean;
|
||||
}): void {
|
||||
emit('draftRequired', {
|
||||
named_regions_changed: false,
|
||||
field_source_mappings_changed: opts.changed,
|
||||
requires_draft_reset: true,
|
||||
reasons: opts.reasons,
|
||||
});
|
||||
}
|
||||
|
||||
function handleSectionMappingUpdate(
|
||||
scope: 'header' | 'line',
|
||||
updatedMapping: VCProfileFieldSourceMapping,
|
||||
): void {
|
||||
const patch = cloneDefinitionForWrite();
|
||||
const list = patch.field_source_mappings || [];
|
||||
const idx = list.findIndex((m) => m.mapping_id === updatedMapping.mapping_id);
|
||||
if (idx < 0) {
|
||||
ensureMapping(scope);
|
||||
return;
|
||||
}
|
||||
const before = JSON.stringify(list[idx]);
|
||||
list[idx] = { ...updatedMapping };
|
||||
patch.field_source_mappings = list;
|
||||
emit('update:definition', patch);
|
||||
const after = JSON.stringify(list[idx]);
|
||||
if (before === after) return;
|
||||
|
||||
const beforeObj = JSON.parse(before) as VCProfileFieldSourceMapping;
|
||||
const afterObj = JSON.parse(after) as VCProfileFieldSourceMapping;
|
||||
const reasons: VCProfileDraftTrigger['reasons'] = [];
|
||||
|
||||
if (
|
||||
beforeObj.format_policy?.mode !== afterObj.format_policy?.mode
|
||||
|| beforeObj.format_policy?.pattern !== afterObj.format_policy?.pattern
|
||||
|| beforeObj.format_policy?.max_capture_groups !== afterObj.format_policy?.max_capture_groups
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
}
|
||||
|
||||
const enabledKeys = [
|
||||
'header_source_enabled',
|
||||
'table_source_enabled',
|
||||
'vendor_comments_enabled',
|
||||
] as const;
|
||||
for (const k of enabledKeys) {
|
||||
if (beforeObj[k] !== afterObj[k]) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
beforeObj.vendor_comments_region_ref !== afterObj.vendor_comments_region_ref
|
||||
|| beforeObj.table_column_code !== afterObj.table_column_code
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
}
|
||||
|
||||
if (reasons.length === 0) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
}
|
||||
|
||||
emitDraftTriggerAggregated({ reasons, changed: true });
|
||||
}
|
||||
|
||||
function openSplitEditor(scope: 'header' | 'line'): void {
|
||||
ensureMapping(scope);
|
||||
splitEditorScope.value = scope;
|
||||
splitEditorVisible.value = true;
|
||||
}
|
||||
|
||||
function handleSplitRuleSetUpdate(updated: VCSplitRuleSet): void {
|
||||
const scope = splitEditorScope.value;
|
||||
const mapping = scope === 'header' ? headerMapping.value : lineMapping.value;
|
||||
if (!mapping) return;
|
||||
updateMapping(mapping.mapping_id, { vendor_comments_split_rule_set: updated });
|
||||
}
|
||||
|
||||
function handleSplitEditorConfirmed(ruleSet: VCSplitRuleSet, previewToken: string): void {
|
||||
emit('vc:split-panel-confirmed',
|
||||
[ruleSet],
|
||||
{ [ruleSet.rule_set_id]: previewToken },
|
||||
props.selectedFieldCode,
|
||||
);
|
||||
splitEditorVisible.value = false;
|
||||
}
|
||||
|
||||
function handleSplitEditorDraftRequired(trigger: VCProfileDraftTrigger): void {
|
||||
emit('draftRequired', {
|
||||
...trigger,
|
||||
reasons: trigger.reasons.map((r) => ({ ...r })),
|
||||
});
|
||||
}
|
||||
|
||||
async function runMergePreview(): Promise<void> {
|
||||
if (props.canPreview === false) return;
|
||||
mergeLoading.value = true;
|
||||
try {
|
||||
// TODO: 后端 API stub,后续接入实际 endpoint
|
||||
// 预期:POST /admin/shipping/document-profiles/{profileId}/documents/{documentId}/preview-merge
|
||||
// 请求体:{ field_code: selectedFieldCode, definition }
|
||||
// 响应:VCMergedObservationCandidate[]
|
||||
mergePreviewResults.value = [];
|
||||
} finally {
|
||||
mergeLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(splitEditorVisible, (v) => {
|
||||
if (!v) {
|
||||
// 关闭编辑器时无需特殊处理,ruleSet 已通过 update:ruleSet 实时同步
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="vc-source-mapping">
|
||||
<header class="vc-map__header">
|
||||
<h3 class="vc-map__title">字段来源映射 · {{ selectedFieldCode }}</h3>
|
||||
<div class="vc-map__scope-tabs">
|
||||
<span
|
||||
v-for="s in scopeOptions"
|
||||
:key="s.value"
|
||||
class="vc-map__scope-tab"
|
||||
:class="{ active: (s.value === 'header' ? headerMapping : lineMapping) != null }"
|
||||
>
|
||||
{{ s.label }}
|
||||
</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="vc-map__scopes">
|
||||
<div
|
||||
v-for="scope in scopeOptions"
|
||||
:key="scope.value"
|
||||
class="vc-map__scope-panel"
|
||||
>
|
||||
<div class="vc-map__scope-header">
|
||||
<strong>{{ scope.label }}</strong>
|
||||
<small v-if="!(scope.value === 'header' ? headerMapping : lineMapping)">
|
||||
(未启用——开启任一来源将自动创建)
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="vc-map__source-groups">
|
||||
<VcSourceMappingSection
|
||||
kind="header_region"
|
||||
:mapping="scope.value === 'header' ? headerMapping : lineMapping"
|
||||
:definition="definition"
|
||||
:readonly="readonly"
|
||||
:mapping-id="(scope.value === 'header' ? headerMapping : lineMapping)?.mapping_id || 'pending'"
|
||||
@update:mapping="(m) => handleSectionMappingUpdate(scope.value, m)"
|
||||
/>
|
||||
|
||||
<VcSourceMappingSection
|
||||
kind="table_column"
|
||||
:mapping="scope.value === 'header' ? headerMapping : lineMapping"
|
||||
:definition="definition"
|
||||
:readonly="readonly"
|
||||
:mapping-id="(scope.value === 'header' ? headerMapping : lineMapping)?.mapping_id || 'pending'"
|
||||
@update:mapping="(m) => handleSectionMappingUpdate(scope.value, m)"
|
||||
/>
|
||||
|
||||
<VcSourceMappingSection
|
||||
kind="vendor_comments"
|
||||
:mapping="scope.value === 'header' ? headerMapping : lineMapping"
|
||||
:definition="definition"
|
||||
:readonly="readonly"
|
||||
:show-split-rules="true"
|
||||
:mapping-id="(scope.value === 'header' ? headerMapping : lineMapping)?.mapping_id || 'pending'"
|
||||
@update:mapping="(m) => handleSectionMappingUpdate(scope.value, m)"
|
||||
@split-editor-open="openSplitEditor(scope.value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="splitEditorVisible" class="vc-map__split-editor-wrapper">
|
||||
<VcSplitRuleEditor
|
||||
:rule-set="splitEditorRuleSet"
|
||||
:selected-field-code="selectedFieldCode"
|
||||
:document-id="documentId"
|
||||
:profile-id="profileId"
|
||||
:readonly="readonly"
|
||||
:dirty-unsaved="dirtyUnsaved"
|
||||
:persisted-confirmed="persistedConfirmed"
|
||||
:visible="splitEditorVisible"
|
||||
@update:rule-set="handleSplitRuleSetUpdate"
|
||||
@confirmed="handleSplitEditorConfirmed"
|
||||
@draft-required="handleSplitEditorDraftRequired"
|
||||
/>
|
||||
<div class="vc-map__split-editor-close">
|
||||
<button type="button" @click="splitEditorVisible = false">
|
||||
关闭编辑器
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="vc-map__merge-preview">
|
||||
<div class="vc-map__merge-toolbar">
|
||||
<h4>合并预览(后端决定 UI,禁止前端 if/else 推导)</h4>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="!canPreview || mergeLoading"
|
||||
@click="runMergePreview"
|
||||
>
|
||||
{{ mergeLoading ? '预览中…' : '拉取合并裁决 (stub)' }}
|
||||
</button>
|
||||
</div>
|
||||
<VcMergePreviewTable
|
||||
:candidates="mergePreviewResults"
|
||||
:loading="mergeLoading"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-source-mapping {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.vc-map__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__title {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vc-map__scope-tabs {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__scope-tab {
|
||||
padding: 4px 10px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
font-size: 0.78rem;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__scope-tab.active {
|
||||
border-color: var(--accent-primary);
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
.vc-map__scopes {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.vc-map__scope-panel {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
background: var(--bg-primary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__scope-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__scope-header small {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-map__source-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__split-editor-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 10px;
|
||||
border: 2px solid var(--accent-primary);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__split-editor-close {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.vc-map__split-editor-close button {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__merge-preview {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__merge-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__merge-toolbar h4 {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.vc-map__merge-toolbar button {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
.vc-map__merge-toolbar button:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
</style>
|
||||
+393
@@ -0,0 +1,393 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcSourceMappingSection.vue
|
||||
用途:三来源通用配置区(Header/Table/Vendor Comments 每来源的开关+target_scope+relation_policy+missing_relation+format_policy),
|
||||
不包含拆分规则编辑器(Vendor Comments 区的拆分规则编辑按钮仅触发 emit)。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section B/D/I;
|
||||
由 VcSourceMappingPanel.vue 薄编排主面板统一编排事件。
|
||||
逻辑:任何字段变化通过 update:mapping 发射完整 mapping 对象;
|
||||
Vendor Comments 点击「编辑拆分规则」时触发 split-editor-open。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import type {
|
||||
VCLineReferenceBasis,
|
||||
VCMissingRelationPolicy,
|
||||
VCProfileDefinitionExtensions,
|
||||
VCProfileFieldSourceMapping,
|
||||
VCRelationPolicy,
|
||||
VCReservationFormatPolicy,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
kind: 'header_region' | 'table_column' | 'vendor_comments';
|
||||
mapping: VCProfileFieldSourceMapping | null;
|
||||
definition: VCProfileDefinitionExtensions;
|
||||
readonly?: boolean;
|
||||
showSplitRules?: boolean;
|
||||
mappingId: string;
|
||||
}>(), {
|
||||
readonly: false,
|
||||
showSplitRules: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:mapping': [mapping: VCProfileFieldSourceMapping];
|
||||
'split-editor-open': [];
|
||||
}>();
|
||||
|
||||
const enabledKey = computed<'header_source_enabled' | 'table_source_enabled' | 'vendor_comments_enabled'>(() => {
|
||||
if (props.kind === 'header_region') return 'header_source_enabled';
|
||||
if (props.kind === 'table_column') return 'table_source_enabled';
|
||||
return 'vendor_comments_enabled';
|
||||
});
|
||||
|
||||
const isEnabled = computed(() => props.mapping?.[enabledKey.value] ?? false);
|
||||
|
||||
function emitPatch(patch: Partial<VCProfileFieldSourceMapping>): void {
|
||||
if (!props.mapping) return;
|
||||
emit('update:mapping', { ...props.mapping, ...patch });
|
||||
}
|
||||
|
||||
function toggleEnabled(enabled: boolean): void {
|
||||
emitPatch({ [enabledKey.value]: enabled } as Partial<VCProfileFieldSourceMapping>);
|
||||
}
|
||||
|
||||
const namedRegionOptions = computed(() => {
|
||||
const map = props.definition?.named_regions || {};
|
||||
return Object.values(map).map((nr) => ({
|
||||
value: nr.region_id,
|
||||
label: nr.label,
|
||||
}));
|
||||
});
|
||||
|
||||
const scopeOptions = [
|
||||
{ value: 'header' as const, label: 'Header (订单头)' },
|
||||
{ value: 'line' as const, label: 'Line (明细行)' },
|
||||
];
|
||||
|
||||
const relationPolicyOptions: { value: VCRelationPolicy; label: string }[] = [
|
||||
{ value: 'bind_target_line', label: '绑定目标行 (bind_target_line)' },
|
||||
{ value: 'annotation_only', label: '仅备注 (annotation_only)' },
|
||||
{ value: 'no_relation', label: '无关联 (no_relation)' },
|
||||
];
|
||||
|
||||
const missingRelationPolicyOptions: { value: VCMissingRelationPolicy; label: string }[] = [
|
||||
{ value: 'default_all_lines', label: '默认所有行 (default_all_lines)' },
|
||||
{ value: 'default_header_only', label: '默认仅 Header (default_header_only)' },
|
||||
{ value: 'fallback_single_line_when_no_reference', label: '无参考回退单行 (fallback_single_line_when_no_reference)' },
|
||||
];
|
||||
|
||||
const lineReferenceBasisOptions: { value: VCLineReferenceBasis; label: string }[] = [
|
||||
{ value: 'explicit_line_column', label: '显式行列号 (explicit)' },
|
||||
{ value: 'profile_business_line_no', label: '业务行号 (profile_business_line_no)' },
|
||||
{ value: 'classified_logical_line_no', label: '分类逻辑行号 (classified_logical_line_no)' },
|
||||
];
|
||||
|
||||
const kindLabel = computed(() => {
|
||||
if (props.kind === 'header_region') return 'Header 来源';
|
||||
if (props.kind === 'table_column') return 'Table 来源';
|
||||
return 'Vendor Comments 来源';
|
||||
});
|
||||
|
||||
const sourceClass = computed(() => {
|
||||
if (props.kind === 'header_region') return 'vc-map__source--header';
|
||||
if (props.kind === 'table_column') return 'vc-map__source--table';
|
||||
return 'vc-map__source--vc';
|
||||
});
|
||||
|
||||
function updateFormatPolicy(policy: Partial<VCReservationFormatPolicy>): void {
|
||||
if (!props.mapping) return;
|
||||
const next: VCReservationFormatPolicy = {
|
||||
...props.mapping.format_policy,
|
||||
...policy,
|
||||
};
|
||||
emitPatch({ format_policy: next });
|
||||
}
|
||||
|
||||
const targetScopeDisabled = computed(() => {
|
||||
if (props.kind === 'table_column' || props.kind === 'vendor_comments') return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
const showLineReferenceBasis = computed(() => {
|
||||
return props.kind === 'table_column' || props.kind === 'vendor_comments';
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<fieldset class="vc-map__source" :class="sourceClass">
|
||||
<legend>
|
||||
<label class="vc-map__toggle-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="isEnabled"
|
||||
@change="toggleEnabled(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
{{ kindLabel }}
|
||||
</label>
|
||||
</legend>
|
||||
<template v-if="isEnabled && mapping">
|
||||
<template v-if="kind === 'header_region'">
|
||||
<label>
|
||||
Header 引用键
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="mapping.header_source_ref ?? ''"
|
||||
placeholder="header_ref / 留空走自动检测"
|
||||
@input="emitPatch({ header_source_ref: ($event.target as HTMLInputElement).value || null })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<template v-else-if="kind === 'table_column'">
|
||||
<label>
|
||||
列 column_code
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="mapping.table_column_code ?? ''"
|
||||
placeholder="例如:reservation_id"
|
||||
@input="emitPatch({ table_column_code: ($event.target as HTMLInputElement).value || null })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<template v-else-if="kind === 'vendor_comments'">
|
||||
<label>
|
||||
命名区域
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.vendor_comments_region_ref ?? ''"
|
||||
@change="emitPatch({ vendor_comments_region_ref: ($event.target as HTMLSelectElement).value || null })"
|
||||
>
|
||||
<option value="">— 请选择命名区域 —</option>
|
||||
<option v-for="opt in namedRegionOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div v-if="showSplitRules" class="vc-map__split-open-row">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
class="vc-map__split-open-btn"
|
||||
@click="emit('split-editor-open')"
|
||||
>
|
||||
编辑拆分规则…
|
||||
</button>
|
||||
<span v-if="mapping.vendor_comments_split_rule_set" class="vc-map__split-status-inline">
|
||||
规则集:v{{ mapping.vendor_comments_split_rule_set.rule_version }}
|
||||
· {{ mapping.vendor_comments_split_rule_set.status || 'draft' }}
|
||||
</span>
|
||||
<span v-else class="vc-map__split-status-inline vc-map__split-status--muted">
|
||||
尚未配置规则集
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<label>
|
||||
目标作用域
|
||||
<select
|
||||
:disabled="readonly || targetScopeDisabled"
|
||||
:value="targetScopeDisabled ? 'line' : mapping.target_scope"
|
||||
@change="emitPatch({ target_scope: ($event.target as HTMLSelectElement).value as 'header' | 'line' })"
|
||||
>
|
||||
<option v-for="opt in scopeOptions" :key="opt.value" :value="opt.value">
|
||||
{{ opt.label }}{{ targetScopeDisabled && opt.value === 'line' ? ' (默认)' : '' }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
关联策略
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.relation_policy"
|
||||
@change="emitPatch({ relation_policy: ($event.target as HTMLSelectElement).value as VCRelationPolicy })"
|
||||
>
|
||||
<option v-for="opt in relationPolicyOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<template v-if="showLineReferenceBasis">
|
||||
<label>
|
||||
行参考基准
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.line_reference_basis"
|
||||
@change="emitPatch({ line_reference_basis: ($event.target as HTMLSelectElement).value as VCLineReferenceBasis })"
|
||||
>
|
||||
<option v-for="opt in lineReferenceBasisOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
<label>
|
||||
缺关联策略
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.missing_relation_policy"
|
||||
@change="emitPatch({ missing_relation_policy: ($event.target as HTMLSelectElement).value as VCMissingRelationPolicy })"
|
||||
>
|
||||
<option v-for="opt in missingRelationPolicyOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="vc-map__checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="mapping.fill_missing_from_other_sources ?? true"
|
||||
@change="emitPatch({ fill_missing_from_other_sources: ($event.target as HTMLInputElement).checked })"
|
||||
/>
|
||||
fill_missing_from_other_sources(从其他来源补空)
|
||||
</label>
|
||||
|
||||
<div class="vc-map__format-block">
|
||||
<div class="vc-map__format-title">格式策略</div>
|
||||
<div class="vc-map__format-radios">
|
||||
<label class="vc-map__radio">
|
||||
<input
|
||||
type="radio"
|
||||
:disabled="readonly"
|
||||
:name="`format-mode-${kind}-${mappingId}`"
|
||||
value="inherit_global"
|
||||
:checked="mapping.format_policy.mode === 'inherit_global'"
|
||||
@change="updateFormatPolicy({ mode: 'inherit_global' })"
|
||||
/>
|
||||
inherit_global(使用 Profile 全局设置)
|
||||
</label>
|
||||
<label class="vc-map__radio">
|
||||
<input
|
||||
type="radio"
|
||||
:disabled="readonly"
|
||||
:name="`format-mode-${kind}-${mappingId}`"
|
||||
value="numeric_5_or_10"
|
||||
:checked="mapping.format_policy.mode === 'numeric_5_or_10'"
|
||||
@change="updateFormatPolicy({ mode: 'numeric_5_or_10' })"
|
||||
/>
|
||||
numeric_5_or_10(单号 5 或 10 位数字)
|
||||
</label>
|
||||
<label class="vc-map__radio">
|
||||
<input
|
||||
type="radio"
|
||||
:disabled="readonly"
|
||||
:name="`format-mode-${kind}-${mappingId}`"
|
||||
value="custom_safe_regex"
|
||||
:checked="mapping.format_policy.mode === 'custom_safe_regex'"
|
||||
@change="updateFormatPolicy({ mode: 'custom_safe_regex' })"
|
||||
/>
|
||||
custom_safe_regex(自定义安全正则)
|
||||
</label>
|
||||
</div>
|
||||
<template v-if="mapping.format_policy.mode === 'custom_safe_regex'">
|
||||
<label>
|
||||
pattern
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="mapping.format_policy.pattern ?? ''"
|
||||
placeholder="例如:^[A-Z]?\d{5,10}$"
|
||||
@input="updateFormatPolicy({ pattern: ($event.target as HTMLInputElement).value || null })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
max_capture_groups
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
:disabled="readonly"
|
||||
:value="mapping.format_policy.max_capture_groups ?? 1"
|
||||
@input="updateFormatPolicy({ max_capture_groups: Number(($event.target as HTMLInputElement).value) || 0 })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</fieldset>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-map__source {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
padding: 8px 10px;
|
||||
margin: 0;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__source--header { border-left: 4px solid #3b82f6; }
|
||||
.vc-map__source--table { border-left: 4px solid #10b981; }
|
||||
.vc-map__source--vc { border-left: 4px solid #f59e0b; }
|
||||
.vc-map__source legend {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
padding: 0 4px;
|
||||
}
|
||||
.vc-map__toggle-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vc-map__source label {
|
||||
display: grid;
|
||||
grid-template-columns: 110px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__checkbox {
|
||||
grid-template-columns: auto 1fr !important;
|
||||
align-items: center;
|
||||
}
|
||||
.vc-map__radio {
|
||||
grid-template-columns: auto 1fr !important;
|
||||
align-items: center;
|
||||
}
|
||||
.vc-map__format-block {
|
||||
grid-column: 1 / -1;
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
padding: 6px;
|
||||
border: 1px dashed var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__format-title {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.vc-map__format-radios {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__source select,
|
||||
.vc-map__source input {
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.8rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.vc-map__split-open-row {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-map__split-open-btn {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__split-open-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-map__split-status-inline {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.vc-map__split-status--muted {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
</style>
|
||||
+921
@@ -0,0 +1,921 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcSplitRuleEditor.vue
|
||||
用途:VC 专用拆分规则编辑器(只处理 Section C VCSplit* 类型,不引入任何 XfaSplit*)。
|
||||
复用 XfaSplitRulePanel 的 addRule/matcherFromExtraction/preview/dirty banner 交互模式,
|
||||
但所有类型、常量、stages 全部本地化,类型只用 vc.types.ts Section C。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section C/J;
|
||||
preview API 为本地 stub,标注后续接入 endpoint。
|
||||
逻辑:split_rules 变化时 emit draftRequired,reason=split_rule_changed;
|
||||
确认前必须先预览(needs_preview → diagnostics → confirm dialog → emit confirmed)。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type {
|
||||
VCProfileDraftTrigger,
|
||||
VCSplitEnginePreviewResult,
|
||||
VCSplitMatcher,
|
||||
VCSplitNormalization,
|
||||
VCSplitRule,
|
||||
VCSplitRuleSet,
|
||||
VCSplitSegment,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
type ExtractionMode = 'select_line' | 'select_line_range' | 'extract_prefix' | 'regex_capture' | 'substring';
|
||||
|
||||
type VCSplitStageType =
|
||||
| 'split_lines'
|
||||
| 'select_line'
|
||||
| 'select_line_range'
|
||||
| 'extract_prefix'
|
||||
| 'regex_capture'
|
||||
| 'replace'
|
||||
| 'substring'
|
||||
| 'normalize';
|
||||
|
||||
interface VCSplitStage {
|
||||
stage_id: string;
|
||||
type: VCSplitStageType;
|
||||
trim?: boolean;
|
||||
remove_empty_lines?: boolean;
|
||||
line_breaks?: string[];
|
||||
line_index?: number;
|
||||
line_start?: number;
|
||||
line_end?: number;
|
||||
join_with?: 'newline' | 'space' | 'comma';
|
||||
value?: string;
|
||||
separators?: string[];
|
||||
case_sensitive?: boolean;
|
||||
pattern?: string;
|
||||
capture_group?: number;
|
||||
find?: string;
|
||||
replace_with?: string;
|
||||
start?: number;
|
||||
end?: number | null;
|
||||
}
|
||||
|
||||
interface VCSplitRulePatch {
|
||||
order?: number;
|
||||
matcher?: VCSplitMatcher | null;
|
||||
segment?: Partial<VCSplitSegment>;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
ruleSet: VCSplitRuleSet | null;
|
||||
selectedFieldCode: string;
|
||||
documentId: number;
|
||||
profileId: number;
|
||||
readonly?: boolean;
|
||||
dirtyUnsaved?: boolean;
|
||||
persistedConfirmed?: boolean;
|
||||
visible: boolean;
|
||||
}>(), {
|
||||
selectedFieldCode: 'reservation_id',
|
||||
readonly: false,
|
||||
dirtyUnsaved: false,
|
||||
persistedConfirmed: false,
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:ruleSet': [ruleSet: VCSplitRuleSet];
|
||||
confirmed: [ruleSet: VCSplitRuleSet, previewToken: string];
|
||||
draftRequired: [trigger: VCProfileDraftTrigger];
|
||||
}>();
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
function newClientId(prefix: 'rs' | 'rule' | 'seg' | 'stage'): string {
|
||||
return `${prefix}-${crypto.randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
|
||||
const splitLoading = ref(false);
|
||||
const splitPreview = ref<VCSplitEnginePreviewResult | null>(null);
|
||||
const splitPreviewRuleSetHash = ref<string | null>(null);
|
||||
const splitPreviewConfirmationToken = ref<string | null>(null);
|
||||
const splitCollapsedRules = ref(new Set<string>());
|
||||
const splitAdvancedRules = ref(new Set<string>());
|
||||
|
||||
const showUnsavedConfirmBanner = computed(() => props.dirtyUnsaved && props.persistedConfirmed === false);
|
||||
|
||||
function createDefaultStage(type: VCSplitStageType): VCSplitStage {
|
||||
const stageId = newClientId('stage');
|
||||
if (type === 'split_lines') {
|
||||
return {
|
||||
stage_id: stageId,
|
||||
type,
|
||||
trim: true,
|
||||
remove_empty_lines: true,
|
||||
line_breaks: ['\r\n', '\r', '\n'],
|
||||
};
|
||||
}
|
||||
if (type === 'select_line') return { stage_id: stageId, type, line_index: 1 };
|
||||
if (type === 'select_line_range') return { stage_id: stageId, type, line_start: 1, line_end: 2, join_with: 'newline' };
|
||||
if (type === 'extract_prefix') return {
|
||||
stage_id: stageId,
|
||||
type,
|
||||
value: '',
|
||||
separators: [':', ':'],
|
||||
case_sensitive: false,
|
||||
};
|
||||
if (type === 'regex_capture') return { stage_id: stageId, type, pattern: '', capture_group: 1 };
|
||||
if (type === 'replace') return { stage_id: stageId, type, find: '', replace_with: '' };
|
||||
if (type === 'substring') return { stage_id: stageId, type, start: 0, end: null };
|
||||
return { stage_id: stageId, type: 'normalize', trim: true, remove_empty_lines: true };
|
||||
}
|
||||
|
||||
function createDefaultPipelineStages(lineIndex = 1): VCSplitStage[] {
|
||||
return [
|
||||
createDefaultStage('split_lines'),
|
||||
{ ...createDefaultStage('select_line'), line_index: lineIndex },
|
||||
];
|
||||
}
|
||||
|
||||
function matcherFromExtraction(mode: ExtractionMode, stage: Partial<VCSplitStage>, order: number): VCSplitMatcher {
|
||||
if (mode === 'extract_prefix') {
|
||||
return {
|
||||
type: 'prefix',
|
||||
value: String(stage.value || ''),
|
||||
separators: (stage.separators && stage.separators.length) ? stage.separators : [':', ':'],
|
||||
case_sensitive: Boolean(stage.case_sensitive),
|
||||
};
|
||||
}
|
||||
if (mode === 'regex_capture') {
|
||||
return {
|
||||
type: 'regex',
|
||||
pattern: String(stage.pattern || ''),
|
||||
capture_group: stage.capture_group ?? 1,
|
||||
case_sensitive: Boolean(stage.case_sensitive),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: 'position',
|
||||
line_index: Number(stage.line_index || stage.line_start || order || 1),
|
||||
};
|
||||
}
|
||||
|
||||
function hashRuleSet(ruleSet: VCSplitRuleSet | null | undefined): string {
|
||||
if (!ruleSet) return '';
|
||||
return JSON.stringify(ruleSet);
|
||||
}
|
||||
|
||||
function invalidatePreview(): void {
|
||||
splitPreview.value = null;
|
||||
splitPreviewRuleSetHash.value = null;
|
||||
splitPreviewConfirmationToken.value = null;
|
||||
}
|
||||
|
||||
function ensureRuleSet(): VCSplitRuleSet {
|
||||
if (props.ruleSet) return props.ruleSet;
|
||||
const ruleSet: VCSplitRuleSet = {
|
||||
rule_set_id: newClientId('rs'),
|
||||
rule_version: 1,
|
||||
normalization: { trim: true, remove_empty_lines: true, line_breaks: ['\r\n', '\r', '\n'] },
|
||||
rules: [],
|
||||
unmatched_line_policy: 'evidence_only',
|
||||
duplicate_match_policy: 'needs_review',
|
||||
same_field_multiple_segment_policy: 'needs_review',
|
||||
source: 'user',
|
||||
status: 'draft',
|
||||
requires_confirmation: true,
|
||||
};
|
||||
emit('update:ruleSet', ruleSet);
|
||||
invalidatePreview();
|
||||
emitDraftTriggerForSplitChanged();
|
||||
return ruleSet;
|
||||
}
|
||||
|
||||
function markRuleSetDirty(ruleSet: VCSplitRuleSet): VCSplitRuleSet {
|
||||
const wasConfirmed = ruleSet.status === 'confirmed' || ruleSet.status === 'published';
|
||||
return {
|
||||
...ruleSet,
|
||||
status: 'draft',
|
||||
requires_confirmation: true,
|
||||
rule_version: wasConfirmed ? ruleSet.rule_version + 1 : ruleSet.rule_version,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeRuleOrders(rules: VCSplitRule[]): VCSplitRule[] {
|
||||
return [...rules]
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
.map((rule, index) => ({ ...rule, order: index + 1 }));
|
||||
}
|
||||
|
||||
function writeRuleSet(ruleSet: VCSplitRuleSet, emitDraft = true): void {
|
||||
emit('update:ruleSet', ruleSet);
|
||||
invalidatePreview();
|
||||
if (emitDraft) {
|
||||
emitDraftTriggerForSplitChanged();
|
||||
}
|
||||
}
|
||||
|
||||
function applyRuleSetChange(updater: (ruleSet: VCSplitRuleSet) => VCSplitRuleSet): void {
|
||||
const current = ensureRuleSet();
|
||||
writeRuleSet(markRuleSetDirty(updater(current)));
|
||||
}
|
||||
|
||||
function emitDraftTriggerForSplitChanged(): void {
|
||||
const trigger: VCProfileDraftTrigger = {
|
||||
named_regions_changed: false,
|
||||
field_source_mappings_changed: true,
|
||||
requires_draft_reset: true,
|
||||
reasons: [{ kind: 'field_source_mapping_split_rule_changed' }],
|
||||
};
|
||||
emit('draftRequired', trigger);
|
||||
}
|
||||
|
||||
function addRule(): void {
|
||||
if (props.readonly) return;
|
||||
const ruleSet = ensureRuleSet();
|
||||
const order = (ruleSet.rules?.length || 0) + 1;
|
||||
const stages = createDefaultPipelineStages(order);
|
||||
const nextRule: VCSplitRule = {
|
||||
rule_id: newClientId('rule'),
|
||||
order,
|
||||
matcher: matcherFromExtraction('select_line', stages[1] || {}, order),
|
||||
segment: {
|
||||
segment_id: newClientId('seg'),
|
||||
segment_code: '',
|
||||
display_name: '',
|
||||
handling: 'evidence_only',
|
||||
target_field_id: null,
|
||||
target_field_code: props.selectedFieldCode,
|
||||
note: null,
|
||||
},
|
||||
};
|
||||
writeRuleSet(markRuleSetDirty({
|
||||
...ruleSet,
|
||||
rules: normalizeRuleOrders([...(ruleSet.rules || []), nextRule]),
|
||||
}));
|
||||
const next = new Set(splitCollapsedRules.value);
|
||||
next.delete(nextRule.rule_id);
|
||||
splitCollapsedRules.value = next;
|
||||
}
|
||||
|
||||
function deleteRule(ruleId: string): void {
|
||||
applyRuleSetChange((current) => ({
|
||||
...current,
|
||||
rules: normalizeRuleOrders(current.rules.filter((r) => r.rule_id !== ruleId)),
|
||||
}));
|
||||
const next = new Set(splitCollapsedRules.value);
|
||||
next.delete(ruleId);
|
||||
splitCollapsedRules.value = next;
|
||||
}
|
||||
|
||||
function moveRule(ruleId: string, direction: 'up' | 'down'): void {
|
||||
const current = ensureRuleSet();
|
||||
const rules = [...current.rules];
|
||||
const idx = rules.findIndex((r) => r.rule_id === ruleId);
|
||||
if (idx < 0) return;
|
||||
const swapIdx = direction === 'up' ? idx - 1 : idx + 1;
|
||||
if (swapIdx < 0 || swapIdx >= rules.length) return;
|
||||
const currentRule = rules[idx];
|
||||
const swapRule = rules[swapIdx];
|
||||
if (!currentRule || !swapRule) return;
|
||||
[rules[idx], rules[swapIdx]] = [swapRule, currentRule];
|
||||
applyRuleSetChange((rs) => ({ ...rs, rules: normalizeRuleOrders(rules) }));
|
||||
}
|
||||
|
||||
function toggleRule(ruleId: string): void {
|
||||
const next = new Set(splitCollapsedRules.value);
|
||||
if (next.has(ruleId)) next.delete(ruleId);
|
||||
else next.add(ruleId);
|
||||
splitCollapsedRules.value = next;
|
||||
}
|
||||
|
||||
function toggleAdvanced(ruleId: string): void {
|
||||
const next = new Set(splitAdvancedRules.value);
|
||||
if (next.has(ruleId)) next.delete(ruleId);
|
||||
else next.add(ruleId);
|
||||
splitAdvancedRules.value = next;
|
||||
}
|
||||
|
||||
function extractionStage(rule: VCSplitRule): VCSplitStage {
|
||||
if (rule.matcher?.type === 'prefix') {
|
||||
return {
|
||||
...createDefaultStage('extract_prefix'),
|
||||
value: rule.matcher.value ?? undefined,
|
||||
separators: rule.matcher.separators,
|
||||
case_sensitive: rule.matcher.case_sensitive,
|
||||
};
|
||||
}
|
||||
if (rule.matcher?.type === 'regex') {
|
||||
return {
|
||||
...createDefaultStage('regex_capture'),
|
||||
pattern: rule.matcher.pattern ?? undefined,
|
||||
capture_group: rule.matcher.capture_group ?? undefined,
|
||||
case_sensitive: rule.matcher.case_sensitive,
|
||||
};
|
||||
}
|
||||
if (rule.matcher?.type === 'position') {
|
||||
return {
|
||||
...createDefaultStage('select_line'),
|
||||
line_index: rule.matcher.line_index ?? rule.order ?? 1,
|
||||
};
|
||||
}
|
||||
return { ...createDefaultStage('select_line'), line_index: rule.order ?? 1 };
|
||||
}
|
||||
|
||||
function extractionMode(rule: VCSplitRule): ExtractionMode {
|
||||
if (rule.matcher?.type === 'prefix') return 'extract_prefix';
|
||||
if (rule.matcher?.type === 'regex') return 'regex_capture';
|
||||
if (rule.matcher?.type === 'position') return 'select_line';
|
||||
return 'select_line';
|
||||
}
|
||||
|
||||
function updateRule(ruleId: string, patch: VCSplitRulePatch): void {
|
||||
applyRuleSetChange((current) => ({
|
||||
...current,
|
||||
rules: current.rules.map((rule) => {
|
||||
if (rule.rule_id !== ruleId) return rule;
|
||||
return {
|
||||
...rule,
|
||||
...patch,
|
||||
segment: patch.segment ? { ...rule.segment, ...patch.segment } : rule.segment,
|
||||
matcher: patch.matcher !== undefined ? patch.matcher : rule.matcher,
|
||||
};
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
function changeExtractionMode(rule: VCSplitRule, mode: ExtractionMode): void {
|
||||
const extraction = createDefaultStage(mode);
|
||||
if (mode === 'select_line') extraction.line_index = rule.order ?? 1;
|
||||
if (mode === 'select_line_range') {
|
||||
extraction.line_start = rule.order ?? 1;
|
||||
extraction.line_end = (rule.order ?? 1) + 1;
|
||||
}
|
||||
updateRule(rule.rule_id, {
|
||||
matcher: matcherFromExtraction(mode, extraction, rule.order ?? 1),
|
||||
});
|
||||
}
|
||||
|
||||
function updateExtraction(rule: VCSplitRule, patch: Partial<VCSplitStage>): void {
|
||||
const current = extractionStage(rule);
|
||||
const nextStage = { ...current, ...patch };
|
||||
const mode = extractionMode(rule);
|
||||
updateRule(rule.rule_id, {
|
||||
matcher: matcherFromExtraction(mode, nextStage, rule.order ?? 1),
|
||||
});
|
||||
}
|
||||
|
||||
function updateUnmatchedPolicy(policy: 'evidence_only' | 'needs_review'): void {
|
||||
applyRuleSetChange((current) => ({ ...current, unmatched_line_policy: policy }));
|
||||
}
|
||||
|
||||
function updateNormalization(patch: Partial<VCSplitNormalization>): void {
|
||||
applyRuleSetChange((current) => ({
|
||||
...current,
|
||||
normalization: { ...(current.normalization || {}), ...patch },
|
||||
}));
|
||||
}
|
||||
|
||||
function previewValueFor(rule: VCSplitRule): string | null {
|
||||
const segment = splitPreview.value?.segments?.find((s) => s.rule_id === rule.rule_id);
|
||||
return segment ? (segment.normalized_text || segment.raw_text) : null;
|
||||
}
|
||||
|
||||
function previewLineLabel(lineStart?: number | null, lineEnd?: number | null): string {
|
||||
if (!lineStart) return '—';
|
||||
return lineEnd && lineEnd !== lineStart ? `${lineStart}–${lineEnd}` : String(lineStart);
|
||||
}
|
||||
|
||||
async function runPreview(): Promise<void> {
|
||||
const ruleSet = ensureRuleSet();
|
||||
splitLoading.value = true;
|
||||
try {
|
||||
// TODO: 后端 API stub,后续接入实际 endpoint
|
||||
// 预期:POST /admin/shipping/document-profiles/{profileId}/documents/{documentId}/preview-split
|
||||
// 请求体:{ rule_set: ruleSet, field_code: selectedFieldCode }
|
||||
splitPreview.value = {
|
||||
status: 'parsed',
|
||||
rule_set_id: ruleSet.rule_set_id,
|
||||
rule_version: ruleSet.rule_version,
|
||||
mapped_fields: {},
|
||||
segments: [],
|
||||
evidence_only_segments: [],
|
||||
diagnostics: [],
|
||||
};
|
||||
splitPreviewRuleSetHash.value = hashRuleSet(ruleSet);
|
||||
splitPreviewConfirmationToken.value = `stub-${Date.now()}`;
|
||||
} catch (error) {
|
||||
message.error(error instanceof BusinessError ? error.message : '预览失败');
|
||||
} finally {
|
||||
splitLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function confirmRules(): void {
|
||||
const ruleSet = ensureRuleSet();
|
||||
const currentHash = hashRuleSet(ruleSet);
|
||||
if (!splitPreview.value || splitPreviewRuleSetHash.value !== currentHash || !splitPreviewConfirmationToken.value) {
|
||||
message.error('确认前请先预览当前规则集');
|
||||
return;
|
||||
}
|
||||
if (splitPreview.value.status === 'needs_review' || (splitPreview.value.diagnostics || []).length > 0) {
|
||||
message.error('存在 needs_review 或诊断错误,无法确认');
|
||||
return;
|
||||
}
|
||||
const confirmedRuleSet: VCSplitRuleSet = {
|
||||
...ruleSet,
|
||||
source: 'user',
|
||||
status: 'confirmed',
|
||||
requires_confirmation: false,
|
||||
};
|
||||
emit('update:ruleSet', confirmedRuleSet);
|
||||
emit('confirmed', confirmedRuleSet, splitPreviewConfirmationToken.value);
|
||||
}
|
||||
|
||||
function lineBreaksToDisplay(breaks: string[] | undefined): string {
|
||||
return (breaks || []).map((item) => item
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/\r/g, '\\r')
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/\t/g, '\\t')).join(', ');
|
||||
}
|
||||
|
||||
function parseLineBreaks(value: string): string[] {
|
||||
return value.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean)
|
||||
.map((token) => token
|
||||
.replace(/\\r\\n/g, '\r\n')
|
||||
.replace(/\\n/g, '\n')
|
||||
.replace(/\\r/g, '\r')
|
||||
.replace(/\\t/g, '\t')
|
||||
.replace(/\\\\/g, '\\'));
|
||||
}
|
||||
|
||||
function separatorsToString(separators: string[] | undefined): string {
|
||||
return (separators || []).join(', ');
|
||||
}
|
||||
|
||||
function parseSeparators(value: string): string[] {
|
||||
return value.split(',').map((item) => item.trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
ensureRuleSet();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="vc-split-editor">
|
||||
<div v-if="showUnsavedConfirmBanner" class="vc-map__banner" role="status">
|
||||
已确认的规则集有未保存改动,保存后将重置为 Draft。
|
||||
</div>
|
||||
|
||||
<div class="vc-split-editor__header">
|
||||
<h4>拆分规则编辑器 · {{ selectedFieldCode }}</h4>
|
||||
<div class="vc-split-editor__toolbar">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
@click="addRule()"
|
||||
>
|
||||
新增拆分规则
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="splitLoading"
|
||||
@click="runPreview()"
|
||||
>
|
||||
{{ splitLoading ? '预览中…' : '预览拆分' }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly || !splitPreview || !splitPreviewConfirmationToken"
|
||||
@click="confirmRules()"
|
||||
>
|
||||
确认规则
|
||||
</button>
|
||||
<span class="vc-map__split-status">
|
||||
状态:{{ ruleSet?.status || 'draft' }}
|
||||
· v{{ ruleSet?.rule_version || 1 }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset class="vc-map__split-ruleset">
|
||||
<legend>规则集设置</legend>
|
||||
<label>
|
||||
未匹配策略
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="ruleSet?.unmatched_line_policy || 'evidence_only'"
|
||||
@change="updateUnmatchedPolicy(($event.target as HTMLSelectElement).value as 'evidence_only' | 'needs_review')"
|
||||
>
|
||||
<option value="evidence_only">仅留证据 (evidence_only)</option>
|
||||
<option value="needs_review">需复核 (needs_review)</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="vc-map__split-normalization">
|
||||
<label class="vc-map__checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="ruleSet?.normalization?.trim ?? true"
|
||||
@change="updateNormalization({ trim: ($event.target as HTMLInputElement).checked })"
|
||||
/>
|
||||
trim
|
||||
</label>
|
||||
<label class="vc-map__checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="ruleSet?.normalization?.remove_empty_lines ?? true"
|
||||
@change="updateNormalization({ remove_empty_lines: ($event.target as HTMLInputElement).checked })"
|
||||
/>
|
||||
去空行
|
||||
</label>
|
||||
<label>
|
||||
换行
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="lineBreaksToDisplay(ruleSet?.normalization?.line_breaks)"
|
||||
:placeholder="'\r\n, \r, \n'"
|
||||
@change="updateNormalization({ line_breaks: parseLineBreaks(($event.target as HTMLInputElement).value) })"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div v-if="splitPreview" class="vc-map__split-preview">
|
||||
<h5>拆分预览(stub,后端 API 待接入)</h5>
|
||||
<p>status: {{ splitPreview.status }}</p>
|
||||
<table v-if="splitPreview.segments?.length" class="vc-map__table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>行</th><th>segment_code</th><th>提取方式</th><th>识别值</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="seg in splitPreview.segments" :key="seg.segment_id">
|
||||
<td>{{ previewLineLabel(seg.line_no, seg.line_end_no) }}</td>
|
||||
<td>{{ seg.segment_code }}</td>
|
||||
<td>{{ seg.matcher_type }}</td>
|
||||
<td>{{ seg.normalized_text || seg.raw_text }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ul v-if="splitPreview.diagnostics?.length" class="vc-map__diagnostics">
|
||||
<li v-for="(d, i) in splitPreview.diagnostics" :key="i">
|
||||
<strong>{{ d.code }}</strong>: {{ d.message }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<ul class="vc-map__split-rules">
|
||||
<li
|
||||
v-for="(rule, idx) in (ruleSet?.rules || [])"
|
||||
:key="rule.rule_id"
|
||||
>
|
||||
<div class="vc-map__split-rule-header">
|
||||
<button type="button" class="vc-map__split-rule-title" @click="toggleRule(rule.rule_id)">
|
||||
<span>{{ splitCollapsedRules.has(rule.rule_id) ? '›' : '⌄' }}</span>
|
||||
<strong>规则 {{ idx + 1 }}</strong>
|
||||
<span>{{ rule.segment.display_name || rule.segment.segment_code || '未命名' }}</span>
|
||||
</button>
|
||||
<div class="vc-map__split-rule-actions">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly || idx === 0"
|
||||
@click="moveRule(rule.rule_id, 'up')"
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly || idx === (ruleSet?.rules?.length || 0) - 1"
|
||||
@click="moveRule(rule.rule_id, 'down')"
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
@click="toggleAdvanced(rule.rule_id)"
|
||||
>
|
||||
{{ splitAdvancedRules.has(rule.rule_id) ? '高级 ▾' : '高级 ▸' }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="danger"
|
||||
:disabled="readonly"
|
||||
@click="deleteRule(rule.rule_id)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!splitCollapsedRules.has(rule.rule_id)" class="vc-map__split-rule-detail">
|
||||
<label>
|
||||
segment_code
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.segment_code"
|
||||
@input="updateRule(rule.rule_id, { segment: { segment_code: ($event.target as HTMLInputElement).value } })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
display_name
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.display_name"
|
||||
@input="updateRule(rule.rule_id, { segment: { display_name: ($event.target as HTMLInputElement).value } })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
提取方式
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="extractionMode(rule)"
|
||||
@change="changeExtractionMode(rule, ($event.target as HTMLSelectElement).value as ExtractionMode)"
|
||||
>
|
||||
<option value="select_line">按行号 (position)</option>
|
||||
<option value="extract_prefix">按前缀标签 (prefix)</option>
|
||||
<option value="regex_capture">按正则捕获 (regex)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-if="extractionMode(rule) === 'select_line'">
|
||||
行号
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).line_index ?? (rule.order ?? 1)"
|
||||
@input="updateExtraction(rule, { line_index: Number(($event.target as HTMLInputElement).value) || 1 })"
|
||||
/>
|
||||
</label>
|
||||
<template v-if="extractionMode(rule) === 'extract_prefix'">
|
||||
<label>
|
||||
前缀
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).value || ''"
|
||||
@input="updateExtraction(rule, { value: ($event.target as HTMLInputElement).value })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
分隔符
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="separatorsToString(extractionStage(rule).separators)"
|
||||
@input="updateExtraction(rule, { separators: parseSeparators(($event.target as HTMLInputElement).value) })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<template v-if="extractionMode(rule) === 'regex_capture'">
|
||||
<label>
|
||||
正则
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).pattern || ''"
|
||||
@input="updateExtraction(rule, { pattern: ($event.target as HTMLInputElement).value })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
捕获组
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).capture_group ?? 1"
|
||||
@input="updateExtraction(rule, { capture_group: Number(($event.target as HTMLInputElement).value) || 0 })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<div v-if="splitAdvancedRules.has(rule.rule_id)" class="vc-map__split-rule-advanced">
|
||||
<label>
|
||||
handling
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.handling"
|
||||
@change="updateRule(rule.rule_id, { segment: { handling: ($event.target as HTMLSelectElement).value as 'mapped' | 'evidence_only' } })"
|
||||
>
|
||||
<option value="evidence_only">仅证据 (evidence_only)</option>
|
||||
<option value="mapped">映射字段 (mapped)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
note
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.note || ''"
|
||||
@input="updateRule(rule.rule_id, { segment: { note: ($event.target as HTMLInputElement).value || null } })"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="vc-map__split-inline-preview">
|
||||
<span>识别值:</span>
|
||||
<strong v-if="previewValueFor(rule)">{{ previewValueFor(rule) }}</strong>
|
||||
<span v-else>需预览</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-split-editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-split-editor__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-split-editor__header h4 {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.vc-split-editor__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-split-editor__toolbar button {
|
||||
padding: 4px 10px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-split-editor__toolbar button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-map__banner {
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
background: var(--status-warning-bg);
|
||||
color: var(--status-warning-fg);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.vc-map__split-status {
|
||||
margin-left: auto;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-map__split-ruleset {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.vc-map__split-ruleset legend {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
padding: 0 4px;
|
||||
}
|
||||
.vc-map__split-normalization {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__checkbox {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__split-preview {
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
font-size: 0.78rem;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-map__split-preview h5 {
|
||||
margin: 0 0 6px 0;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.vc-map__table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-map__table th,
|
||||
.vc-map__table td {
|
||||
border: 1px solid var(--border-default);
|
||||
padding: 4px 6px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
.vc-map__table th {
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__diagnostics {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 6px 0 0 0;
|
||||
color: var(--text-danger);
|
||||
}
|
||||
.vc-map__split-rules {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__split-rules > li {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-map__split-rule-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
.vc-map__split-rule-title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 2px 4px;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.vc-map__split-rule-title span {
|
||||
font-family: monospace;
|
||||
}
|
||||
.vc-map__split-rule-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__split-rule-actions button {
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.vc-map__split-rule-actions button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-map__split-rule-actions .danger {
|
||||
color: var(--text-danger);
|
||||
}
|
||||
.vc-map__split-rule-detail {
|
||||
padding: 6px 8px;
|
||||
border-top: 1px dashed var(--border-default);
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.vc-map__split-rule-detail label {
|
||||
display: grid;
|
||||
grid-template-columns: 100px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-map__split-rule-detail select,
|
||||
.vc-map__split-rule-detail input,
|
||||
.vc-map__split-ruleset select,
|
||||
.vc-map__split-ruleset input {
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-map__split-rule-advanced {
|
||||
grid-column: 1 / -1;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
padding: 6px;
|
||||
border: 1px dashed var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__split-inline-preview {
|
||||
grid-column: 1 / -1;
|
||||
font-size: 0.78rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.danger { color: var(--text-danger); }
|
||||
</style>
|
||||
@@ -29,6 +29,7 @@ export type ShippingConfigSubModuleId =
|
||||
| 'order_extraction_runs'
|
||||
| 'shipping_audit'
|
||||
| 'process_gates'
|
||||
| 'legacy_stp_jobs'
|
||||
| 'inventory_fields'
|
||||
| 'connections'
|
||||
| 'inventory_sites'
|
||||
|
||||
@@ -0,0 +1,365 @@
|
||||
/**
|
||||
* features/admin/types/shipping-order-document-profile.vc.types.ts
|
||||
* 用途:Vendor Comments(普通 PDF 物理区域 + 三来源合并)阶段 2/3 前端契约类型定义。
|
||||
* 不修改既有 shipping-order-document-profile.types.ts(单文件不超 1000 行红线)。
|
||||
* 依赖:BaseSplit* 对齐 field_split_core.py;NamedRegion / FieldSourceMapping 严格对齐
|
||||
* profile_vendor_comments_contract.py;format_policy 对齐 reservation_format_policy_service.py。
|
||||
* 逻辑:后端决定 UI —— 所有稳定诊断码、合并决议枚举、冲突分组键、回 Draft 标志位
|
||||
* 全部通过后端 API 返回,前端不得自行 if/else 推导业务状态。
|
||||
*/
|
||||
|
||||
import type { OrderProfileRelativeRegion } from './shipping-order-document-profile.types';
|
||||
|
||||
// =========================================================================
|
||||
// Section A: named_regions 契约(Q14)——Profile 顶层命名区域
|
||||
// =========================================================================
|
||||
|
||||
export type VCNamedRegionPageScope =
|
||||
| 'first_page'
|
||||
| 'last_page'
|
||||
| 'all_pages'
|
||||
| 'exact_page';
|
||||
|
||||
export type VCNamedRegionSelectionMode =
|
||||
| 'fixed_region'
|
||||
| 'auto_take_last_qualified';
|
||||
|
||||
export interface VCNamedRegion {
|
||||
region_id: string;
|
||||
label: string;
|
||||
region: OrderProfileRelativeRegion;
|
||||
page_scope: VCNamedRegionPageScope;
|
||||
page_no?: number | null;
|
||||
selection_mode: VCNamedRegionSelectionMode;
|
||||
}
|
||||
|
||||
export type VCNamedRegionsMap = Record<string, VCNamedRegion>;
|
||||
|
||||
// =========================================================================
|
||||
// Section B: Reservation format_policy 契约(Q15)——Profile 级校验策略
|
||||
// =========================================================================
|
||||
|
||||
export type VCFormatPolicyMode =
|
||||
| 'inherit_global'
|
||||
| 'numeric_5_or_10'
|
||||
| 'custom_safe_regex';
|
||||
|
||||
export interface VCReservationFormatPolicy {
|
||||
mode: VCFormatPolicyMode;
|
||||
pattern?: string | null;
|
||||
/** custom_safe_regex 发布前必须过 Pydantic 的捕获组限制门禁 */
|
||||
max_capture_groups: number;
|
||||
timeout_ms: number;
|
||||
case_sensitive: boolean;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section C: Base Split Core(共享引擎)契约——对齐 field_split_core.py
|
||||
// 前端类型必须完全复用 XfaSplit*;为避免引入 XFA 专属 path_id 歧义,
|
||||
// 这里新建轻量别名。未来与 XfaSplit 统一后移除别名。
|
||||
// =========================================================================
|
||||
|
||||
export type VCSplitMatcherType = 'prefix' | 'regex' | 'position';
|
||||
export type VCSplitHandling = 'mapped' | 'evidence_only';
|
||||
|
||||
export interface VCSplitRelationCaptureDef {
|
||||
type: 'line_reference' | string;
|
||||
capture_group: number;
|
||||
labels?: string[] | null;
|
||||
}
|
||||
|
||||
export interface VCSplitMatcher {
|
||||
type: VCSplitMatcherType;
|
||||
line_index?: number | null;
|
||||
value?: string | null;
|
||||
separators?: string[];
|
||||
case_sensitive?: boolean;
|
||||
pattern?: string | null;
|
||||
capture_group?: number | null;
|
||||
relation_capture?: VCSplitRelationCaptureDef | null;
|
||||
}
|
||||
|
||||
export interface VCSplitSegment {
|
||||
segment_id: string;
|
||||
segment_code: string;
|
||||
display_name: string;
|
||||
handling: VCSplitHandling;
|
||||
target_field_id?: string | null;
|
||||
target_field_code?: string | null;
|
||||
note?: string | null;
|
||||
}
|
||||
|
||||
export interface VCSplitRule {
|
||||
rule_id: string;
|
||||
matcher?: VCSplitMatcher | null;
|
||||
segment: VCSplitSegment;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export interface VCSplitNormalization {
|
||||
trim?: boolean;
|
||||
remove_empty_lines?: boolean;
|
||||
line_breaks?: string[];
|
||||
}
|
||||
|
||||
export interface VCSplitRuleSet {
|
||||
rule_set_id: string;
|
||||
rule_version: number;
|
||||
normalization?: VCSplitNormalization;
|
||||
rules: VCSplitRule[];
|
||||
unmatched_line_policy?: 'evidence_only' | 'needs_review';
|
||||
duplicate_match_policy?: 'needs_review';
|
||||
same_field_multiple_segment_policy?: 'needs_review';
|
||||
source?: 'system_suggestion' | 'user' | 'imported';
|
||||
status?: 'draft' | 'confirmed' | 'published';
|
||||
requires_confirmation?: boolean;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section D: field_source_mappings 契约(Q9/Q18)——三来源字段来源映射
|
||||
// =========================================================================
|
||||
|
||||
export type VCRelationPolicy =
|
||||
| 'no_relation'
|
||||
| 'bind_target_line'
|
||||
| 'annotation_only';
|
||||
|
||||
export type VCMissingRelationPolicy =
|
||||
| 'default_all_lines'
|
||||
| 'default_header_only'
|
||||
| 'fallback_single_line_when_no_reference';
|
||||
|
||||
export type VCLineReferenceBasis =
|
||||
| 'explicit_line_column'
|
||||
| 'profile_business_line_no'
|
||||
| 'classified_logical_line_no';
|
||||
|
||||
export interface VCProfileFieldSourceMapping {
|
||||
mapping_id: string;
|
||||
target_scope: 'header' | 'line';
|
||||
target_field_code: string;
|
||||
target_field_id: string;
|
||||
|
||||
header_source_enabled: boolean;
|
||||
header_source_ref?: string | null;
|
||||
header_normalizer_key?: string | null;
|
||||
|
||||
table_source_enabled: boolean;
|
||||
table_column_code?: string | null;
|
||||
|
||||
vendor_comments_enabled: boolean;
|
||||
vendor_comments_region_ref?: string | null;
|
||||
vendor_comments_split_rule_set?: VCSplitRuleSet | null;
|
||||
|
||||
relation_policy: VCRelationPolicy;
|
||||
missing_relation_policy: VCMissingRelationPolicy;
|
||||
line_reference_basis: VCLineReferenceBasis;
|
||||
|
||||
fill_missing_from_other_sources: boolean;
|
||||
format_policy: VCReservationFormatPolicy;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section E: 三来源候选 + 合并结果(SourceMergeService)——后端决定 UI
|
||||
// 后端返回结构化决议,前端只负责渲染按钮/高亮,不推导状态。
|
||||
// =========================================================================
|
||||
|
||||
export type VCFieldSourceKind =
|
||||
| 'header_region'
|
||||
| 'table_column'
|
||||
| 'vendor_comments';
|
||||
|
||||
export type VCMergeResolution =
|
||||
| 'same_value_merged'
|
||||
| 'fill_missing'
|
||||
| 'needs_review'
|
||||
| 'no_value'
|
||||
| 'single_source_direct'
|
||||
| 'annotation_only_dropped';
|
||||
|
||||
export type VCObservationDecisionStatus =
|
||||
| 'accepted'
|
||||
| 'needs_review'
|
||||
| 'blocked'
|
||||
| 'missing';
|
||||
|
||||
export interface VCSourceObservationSnapshot {
|
||||
source: VCFieldSourceKind;
|
||||
value: string;
|
||||
normalized_value: string;
|
||||
evidence_ref: string | null;
|
||||
evidence_quote: string | null;
|
||||
line_no_in_source: number | null;
|
||||
format_valid: boolean | null;
|
||||
format_reason_code: string | null;
|
||||
extra: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface VCMergedObservationCandidate {
|
||||
target_scope: 'header' | 'line';
|
||||
target_field_code: string;
|
||||
target_field_id: string;
|
||||
effective_line_no: number | null;
|
||||
accepted_value: string | null;
|
||||
decision_status: VCObservationDecisionStatus;
|
||||
resolution: VCMergeResolution;
|
||||
source_observations: VCSourceObservationSnapshot[];
|
||||
conflicts: Array<Record<string, unknown>>;
|
||||
evidence_quote: string | null;
|
||||
evidence_ref: string | null;
|
||||
evidence_metadata: {
|
||||
source_observations: VCSourceObservationSnapshot[];
|
||||
resolution: VCMergeResolution;
|
||||
accepted_value: string | null;
|
||||
conflicts: Array<Record<string, unknown>>;
|
||||
resolution_meta: Record<string, unknown>;
|
||||
primary?: {
|
||||
source: VCFieldSourceKind;
|
||||
evidence_ref: string | null;
|
||||
line_no: number | null;
|
||||
} | null;
|
||||
};
|
||||
source_type: string;
|
||||
extractor: string;
|
||||
/** 前端只读门禁:是否允许作为有效 Observation 落库 */
|
||||
should_persist_observation: boolean;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section F: 关系投影诊断码(Q2/Q12)——invalid_line_reference 独立审计链
|
||||
// =========================================================================
|
||||
|
||||
export type VCRelationProjectionResolution =
|
||||
| 'bound_to_line'
|
||||
| 'annotation_only'
|
||||
| 'default_all_lines'
|
||||
| 'default_header_only'
|
||||
| 'invalid_line_reference'
|
||||
| 'conflict_unresolved';
|
||||
|
||||
export interface VCRelationProjectionResult {
|
||||
line_reference_basis: VCLineReferenceBasis;
|
||||
resolution: VCRelationProjectionResolution;
|
||||
resolved_logical_line_no: number | null;
|
||||
annotation_reason: string | null;
|
||||
invalid_reference_raw_value: string | null;
|
||||
invalid_reference_line_no: number | null;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section G: 区域预览诊断(CoordinateRegionSourceAdapter)
|
||||
// =========================================================================
|
||||
|
||||
export type VCCoordinateRegionStatus = 'available' | 'unavailable';
|
||||
|
||||
export interface VCCoordinateRegionEvidenceToken {
|
||||
page_no: number;
|
||||
text: string;
|
||||
x0: number;
|
||||
y0: number;
|
||||
x1: number;
|
||||
y1: number;
|
||||
}
|
||||
|
||||
export interface VCCoordinateRegionSourceResult {
|
||||
region_id: string;
|
||||
label: string;
|
||||
status: VCCoordinateRegionStatus;
|
||||
page_no: number | null;
|
||||
raw_text: string;
|
||||
lines: string[];
|
||||
evidence_tokens: VCCoordinateRegionEvidenceToken[];
|
||||
diagnostic_code: string | null;
|
||||
diagnostic_message: string | null;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section H: Profile 变更回 Draft 判定(前端门禁标志位,真实判定在后端)
|
||||
// 前端只展示警告,不阻断保存(最终拦截在 service 层)。
|
||||
// =========================================================================
|
||||
|
||||
export interface VCProfileDraftTrigger {
|
||||
named_regions_changed: boolean;
|
||||
field_source_mappings_changed: boolean;
|
||||
requires_draft_reset: boolean;
|
||||
/** 前端展示给管理员的中文/英文说明;实际文案通过 t() 取 i18n */
|
||||
reasons: Array<{
|
||||
kind:
|
||||
| 'named_region_added'
|
||||
| 'named_region_removed'
|
||||
| 'named_region_geometry'
|
||||
| 'named_region_scope'
|
||||
| 'field_source_mapping_added'
|
||||
| 'field_source_mapping_removed'
|
||||
| 'field_source_mapping_split_rule_changed'
|
||||
| 'field_source_mapping_format_policy_changed';
|
||||
region_id?: string;
|
||||
mapping_id?: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Section I: definition_json 顶层 VC 扩展(OrderCoordinateProfileDefinition
|
||||
// 和 OrderXfaDatasetProfileDefinition 都通过交叉引用)。
|
||||
// 不修改既有 definition 接口,单独 export 用于 patch 合并。
|
||||
// =========================================================================
|
||||
|
||||
export interface VCProfileDefinitionExtensions {
|
||||
named_regions?: VCNamedRegionsMap | null;
|
||||
field_source_mappings?: VCProfileFieldSourceMapping[] | null;
|
||||
}
|
||||
|
||||
export type VCProfileDefinitionWithExtensions =
|
||||
& { named_regions?: VCNamedRegionsMap | null; field_source_mappings?: VCProfileFieldSourceMapping[] | null }
|
||||
& Record<string, unknown>;
|
||||
|
||||
// =========================================================================
|
||||
// Section J: 合成预览 DTO(后端返回,前端只读)
|
||||
// =========================================================================
|
||||
|
||||
export interface VCSplitEngineSegmentPreview {
|
||||
segment_id: string;
|
||||
segment_code: string;
|
||||
display_name: string;
|
||||
line_no?: number | null;
|
||||
line_end_no?: number | null;
|
||||
raw_text: string;
|
||||
normalized_text: string;
|
||||
handling: VCSplitHandling;
|
||||
target_field_id?: string | null;
|
||||
target_field_code?: string | null;
|
||||
rule_id: string;
|
||||
status: string;
|
||||
matcher_type: string;
|
||||
captured_relation?: {
|
||||
type: string;
|
||||
line_no: number | null;
|
||||
raw_text: string | null;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface VCSplitEnginePreviewResult {
|
||||
status: 'parsed' | 'needs_review' | 'unavailable';
|
||||
rule_set_id: string | null;
|
||||
rule_version: number | null;
|
||||
mapped_fields: Record<string, string>;
|
||||
segments: VCSplitEngineSegmentPreview[];
|
||||
evidence_only_segments: VCSplitEngineSegmentPreview[];
|
||||
diagnostics: Array<{
|
||||
code: string;
|
||||
message: string;
|
||||
line_no?: number | null;
|
||||
field_code?: string | null;
|
||||
rule_ids?: string[];
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface VCMergePreviewResponse {
|
||||
document_id: number;
|
||||
region_id: string;
|
||||
mapping_id: string;
|
||||
region_result: VCCoordinateRegionSourceResult | null;
|
||||
split_preview: VCSplitEnginePreviewResult | null;
|
||||
relation_projection: VCRelationProjectionResult | null;
|
||||
merged_observation: VCMergedObservationCandidate | null;
|
||||
}
|
||||
@@ -33,9 +33,11 @@ import type {
|
||||
OrderExtractionSubmissionRequest,
|
||||
OrderExtractionSubmissionResponse,
|
||||
ConversationProcessingProjection,
|
||||
ConversationProcessingAppendBlockReason,
|
||||
ShippingOrderReviewAuditTimelinePage,
|
||||
ShippingTaskAuditTimelinePage,
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewCaseSnapshot,
|
||||
ShippingOrderReviewCustomerResolution,
|
||||
ShippingOrderReviewDuplicate,
|
||||
ShippingOrderReviewFieldConflict,
|
||||
@@ -55,6 +57,7 @@ import type {
|
||||
ShippingOrderReviewLlmSuggestionResponse,
|
||||
ShippingOrderReviewReparseResponse,
|
||||
ShippingOrderReviewRun,
|
||||
ShippingTaskInventoryCandidatesResponse,
|
||||
ShippingTaskUiState,
|
||||
} from '../types/shipping.api.types';
|
||||
|
||||
@@ -70,6 +73,8 @@ type ShippingApiStatusPayload = {
|
||||
/** 批次重试等接口返回的跳过任务数 */
|
||||
skipped?: number;
|
||||
batch_no?: string;
|
||||
/** 后端返回的语义化原因码(对齐 noop / needs_human / already_running 等状态分支) */
|
||||
reason_code?: ConversationProcessingAppendBlockReason | string | null;
|
||||
};
|
||||
|
||||
export type ShippingChatAgentOption = {
|
||||
@@ -379,7 +384,7 @@ export const getWorkspaceShippingOrderReviewRun = (runNo: string) =>
|
||||
|
||||
/** 获取一份 PDF 的冻结 Schema 与只读机器/草稿投影。 */
|
||||
export const getWorkspaceShippingOrderReviewCase = (caseNo: string) =>
|
||||
requestJson<ShippingOrderReviewCase>(
|
||||
requestJson<ShippingOrderReviewCaseSnapshot>(
|
||||
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}`,
|
||||
);
|
||||
|
||||
@@ -491,6 +496,22 @@ export const putWorkspaceShippingOrderReviewInventoryCandidates = (
|
||||
{ method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) },
|
||||
);
|
||||
|
||||
/**
|
||||
* 读取正式 Task 当前库存候选版本与历史摘要。
|
||||
*/
|
||||
export const getWorkspaceTaskInventoryCandidates = (
|
||||
taskNo: string,
|
||||
options?: { version?: 'current' | number; includeHistory?: boolean },
|
||||
) => {
|
||||
const params = new URLSearchParams();
|
||||
if (options?.version != null) params.set('version', String(options.version));
|
||||
if (options?.includeHistory != null) params.set('include_history', String(options.includeHistory));
|
||||
const query = params.toString();
|
||||
return requestJson<ShippingTaskInventoryCandidatesResponse>(
|
||||
`/api/workspace/shipping-notice/tasks/${encodeURIComponent(taskNo)}/inventory-candidates${query ? `?${query}` : ''}`,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 重新匹配整单或指定明细的库存路由规则。
|
||||
* 核心逻辑:携带 expected_draft_version 与幂等键;可选 line_key 限定单行。
|
||||
|
||||
+257
-62
@@ -1,43 +1,71 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewCurrentProcessingCard.vue
|
||||
用途:正式 OT 创建后的右侧「当前处理状态」主卡(阶段 + 自动推进合并)。
|
||||
依赖:vue-i18n、ShippingOrderReviewAutomation、resolveShippingProcessingStageLabel。
|
||||
逻辑:优先消费 Progress 同源的 stageCode + stageLabelKey;Case current_stage 仅降级;
|
||||
禁止把阶段码直接当用户文案;Job 明细与 task_missing 诊断仅管理员区;
|
||||
由 ShippingOrderReviewView 在 has_formal_ot / task_missing 时置顶渲染。
|
||||
用途:发货通知工作台右侧唯一的「当前任务」主卡(阶段 + 用户状态 + 阻断 + 动作)。
|
||||
依赖:vue-i18n、ShippingProcessingBlockingReason/PrimaryAction 类型、resolveShippingProcessingStageLabel。
|
||||
逻辑:主卡内部 section = 「当前阶段/状态/正式OT → 下一步 → 动作区」;
|
||||
状态文案严格绑定 user_status;blocking_reason 只作下一步问题说明;按钮显隐由后端 retryable + primary_action.parameters 决定;
|
||||
由 ShippingOrderReviewView 在 mountCurrentProcessingCard 时挂载。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { RefreshCw } from 'lucide-vue-next';
|
||||
import { RefreshCw, Crosshair } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingOrderReviewAutomation } from '@/features/chat/types/shipping.api.types';
|
||||
import type {
|
||||
ShippingProcessingBlockingReason,
|
||||
ShippingProcessingPrimaryAction,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import { resolveShippingProcessingStageLabel } from '@/features/chat/shipping/shippingProcessingLabels';
|
||||
|
||||
const props = defineProps<{
|
||||
stageCode?: string | null;
|
||||
stageLabelKey?: string | null;
|
||||
stageInconsistent?: boolean;
|
||||
|
||||
hasFormalOt?: boolean;
|
||||
shippingNoticeNo?: string | null;
|
||||
|
||||
userStatus?:
|
||||
| 'running'
|
||||
| 'waiting_human'
|
||||
| 'retryable'
|
||||
| 'failed'
|
||||
| 'completed'
|
||||
| 'cancelled'
|
||||
| null;
|
||||
retryable?: boolean;
|
||||
blockingReason?: ShippingProcessingBlockingReason | null;
|
||||
primaryAction?: ShippingProcessingPrimaryAction | null;
|
||||
|
||||
taskMissing?: boolean;
|
||||
taskNo?: string | null;
|
||||
confirmedTaskId?: number | null;
|
||||
showAdminDiagnosis?: boolean;
|
||||
automation?: ShippingOrderReviewAutomation | null;
|
||||
showRetry?: boolean;
|
||||
retrying?: boolean;
|
||||
locating?: boolean;
|
||||
/** 题7A:自动次数已耗尽但允许人工继续的源;不为空时按钮语义提示「人工继续」+ tooltip 列名。 */
|
||||
retryExhaustedSources?: string[] | null;
|
||||
/** 仅 UI 展示的 running 文案(如 inventory_preparation 正在跑时主卡按钮 loading 附加信息)。 */
|
||||
automation?: {
|
||||
status?: string | null;
|
||||
message?: string | null;
|
||||
} | null;
|
||||
showRetry?: boolean;
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
retry: [];
|
||||
locate: [lineKey?: string | null, fieldId?: string | null];
|
||||
action: [code: string, parameters?: Record<string, unknown>];
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
|
||||
/**
|
||||
* 当前处理阶段展示文案:消费 label_key,禁止直接展示阶段码。
|
||||
* 当前阶段展示文案:优先消费 stage_label_key,禁止直接展示 stage 码。
|
||||
*/
|
||||
const stageLabel = computed(() => {
|
||||
if (props.taskMissing) {
|
||||
return t('chat.shippingOrderReview.currentProcessing.taskMissing');
|
||||
if (props.loading) {
|
||||
return t('chat.shippingOrderReview.caseSwitchLoading');
|
||||
}
|
||||
if (props.stageInconsistent) {
|
||||
return t('chat.shippingOrderReview.currentProcessing.stateInconsistent');
|
||||
@@ -51,68 +79,196 @@ const stageLabel = computed(() => {
|
||||
});
|
||||
|
||||
/**
|
||||
* 自动推进用户态文案(消费 phase,禁止前端猜建单/推进)。
|
||||
* 「状态」行用户态文案:严格绑定 user_status,不再由前端推断。
|
||||
*/
|
||||
const statusLabel = computed(() => {
|
||||
const automation = props.automation;
|
||||
const status = String(automation?.status || '').trim().toLowerCase();
|
||||
const phase = String(automation?.phase || '').trim();
|
||||
if (props.loading) {
|
||||
return t('chat.shippingOrderReview.currentTask.statusRunning');
|
||||
}
|
||||
const s = String(props.userStatus || '').trim() as ReviewCurrentUserStatus | '';
|
||||
const map: Record<ReviewCurrentUserStatus, string> = {
|
||||
running: t('chat.shippingOrderReview.currentTask.statusRunning'),
|
||||
waiting_human: t('chat.shippingOrderReview.currentTask.statusWaitingHuman'),
|
||||
retryable: t('chat.shippingOrderReview.currentTask.statusRetryable'),
|
||||
failed: t('chat.shippingOrderReview.currentTask.statusFailed'),
|
||||
completed: t('chat.shippingOrderReview.currentTask.statusCompleted'),
|
||||
cancelled: t('chat.shippingOrderReview.currentTask.statusCancelled'),
|
||||
};
|
||||
if (props.taskMissing) {
|
||||
return t('chat.shippingOrderReview.currentProcessing.statusTaskMissing');
|
||||
return t('chat.shippingOrderReview.currentProcessing.taskMissing');
|
||||
}
|
||||
if (status === 'waiting_to_start') {
|
||||
return phase === 'pre_ot_stp'
|
||||
? t('chat.shippingOrderReview.automation.waitingPreOt')
|
||||
: t('chat.shippingOrderReview.automation.waitingPostOt');
|
||||
}
|
||||
if (status === 'queued' || status === 'running') {
|
||||
return t('chat.shippingOrderReview.currentProcessing.statusRunning');
|
||||
}
|
||||
if (status === 'failed' || status === 'manual_fallback') {
|
||||
return t('chat.shippingOrderReview.currentProcessing.statusFailedRetryable');
|
||||
}
|
||||
if (status === 'completed') {
|
||||
return t('chat.shippingOrderReview.currentProcessing.statusCompleted');
|
||||
}
|
||||
return t('chat.shippingOrderReview.currentProcessing.statusIdle');
|
||||
if (!s) return t('chat.shippingOrderReview.currentProcessing.statusIdle');
|
||||
return map[s] ?? t('chat.shippingOrderReview.currentProcessing.statusIdle');
|
||||
});
|
||||
|
||||
/**
|
||||
* 主卡重试:对象级;建单前无 task_no 也可重试 STP;正式 OT 需 task_no。
|
||||
* 下一步(「下一步」section 的问题/说明文案):优先展示 blocking_reason,否则按 user_status 给系统态文案。
|
||||
*/
|
||||
const canShowRetry = computed(() => {
|
||||
if (!props.showRetry || props.taskMissing) return false;
|
||||
if (String(props.taskNo || '').trim()) return true;
|
||||
// 建单前 STP:无 OT 号也可重试。
|
||||
return String(props.automation?.phase || '').trim() !== 'post_ot_progress';
|
||||
const nextStepText = computed(() => {
|
||||
if (props.loading) {
|
||||
return String(props.automation?.message || '').trim() || t('chat.shippingOrderReview.currentTask.nextStepRunning');
|
||||
}
|
||||
// 1) blocking_reason → 用后端给的 i18n_key 渲染具体阻断
|
||||
const br = props.blockingReason;
|
||||
if (br) {
|
||||
const i18nKey = String(br.i18nKey || '').trim();
|
||||
if (i18nKey && te(i18nKey)) {
|
||||
return t(i18nKey);
|
||||
}
|
||||
// i18n 键缺失时回落为 code(不裸露给普通用户,最终 QA 期间应全部补齐)
|
||||
return String(br.code || '').trim() || t('chat.shippingOrderReview.currentTask.nextStepUnknown');
|
||||
}
|
||||
// 2) 无阻断时,按 user_status 给系统说明文案
|
||||
const s = String(props.userStatus || '').trim() as ReviewCurrentUserStatus | '';
|
||||
if (s === 'running') {
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepRunning');
|
||||
}
|
||||
if (s === 'completed') {
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepCompleted');
|
||||
}
|
||||
if (s === 'cancelled') {
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepCancelled');
|
||||
}
|
||||
if (s === 'failed' && !props.retryable) {
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepFailedNoRetry');
|
||||
}
|
||||
if (s === 'waiting_human') {
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepWaitingHumanDefault');
|
||||
}
|
||||
if (s === 'retryable') {
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepRetryableDefault');
|
||||
}
|
||||
return t('chat.shippingOrderReview.currentTask.nextStepUnknown');
|
||||
});
|
||||
|
||||
/**
|
||||
* 业务动作按钮:后端确认 retryable=true → 主按钮为「重试」;
|
||||
* 否则若 primary_action.code 非 retry → 用 primary_action.code + i18n_key 渲染对应人工动作(进入复核/确认客户等)。
|
||||
*/
|
||||
const showBusinessAction = computed(() => {
|
||||
if (props.loading) return false;
|
||||
if (props.taskMissing) return false;
|
||||
if (props.retryable) return true;
|
||||
const code = String(props.primaryAction?.code || '').trim();
|
||||
if (!code) return false;
|
||||
// retry 仅当 retryable=true 时展示(避免按钮闪烁矛盾)
|
||||
if (code === 'retry') return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
const businessActionLabel = computed(() => {
|
||||
if (props.retryable) {
|
||||
if ((props.retryExhaustedSources || []).length > 0) {
|
||||
return t('chat.shippingOrderReview.currentTask.actionRetryWithExhausted');
|
||||
}
|
||||
return t('chat.shippingOrderReview.currentTask.actionRetry');
|
||||
}
|
||||
const pa = props.primaryAction;
|
||||
if (!pa) return '';
|
||||
const i18nKey = String(pa.i18nKey || '').trim();
|
||||
if (i18nKey && te(i18nKey)) {
|
||||
return t(i18nKey);
|
||||
}
|
||||
// fallback 到 legacy chat.shippingProcessing.action
|
||||
const legacyKey = `chat.shippingProcessing.action.${pa.code}`;
|
||||
if (te(legacyKey)) {
|
||||
return t(legacyKey);
|
||||
}
|
||||
return pa.code;
|
||||
});
|
||||
|
||||
/** 题7A:按钮 tooltip(exhausted_sources 列表与文案)。 */
|
||||
const businessActionTitle = computed(() => {
|
||||
const exhausted = Array.isArray(props.retryExhaustedSources) ? props.retryExhaustedSources.filter(Boolean) : [];
|
||||
if (exhausted.length > 0) {
|
||||
return t('chat.shippingOrderReview.currentTask.actionRetryExhaustedTooltip', {
|
||||
sources: exhausted.join(', '),
|
||||
});
|
||||
}
|
||||
const retryingFlag = Boolean(props.retrying);
|
||||
if (retryingFlag) {
|
||||
return t('chat.shippingOrderReview.currentTask.actionRetryRunningTooltip');
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const actionIsRetry = computed(() => Boolean(props.retryable) || String(props.primaryAction?.code || '') === 'retry');
|
||||
|
||||
function handleBusinessActionClick() {
|
||||
if (actionIsRetry.value) {
|
||||
emit('retry');
|
||||
return;
|
||||
}
|
||||
emit('action', String(props.primaryAction?.code || ''), props.primaryAction?.parameters ?? {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助导航「定位明细」:仅当后端在 primary_action.parameters 里提供 line_key 或 field_id 才显示。
|
||||
*/
|
||||
const showLocateAction = computed(() => {
|
||||
if (props.loading) return false;
|
||||
if (props.taskMissing) return false;
|
||||
const params = (props.primaryAction?.parameters ?? {}) as Record<string, unknown>;
|
||||
const hasLineKey = typeof params.line_key === 'string' && params.line_key.length > 0;
|
||||
const hasFieldId = typeof params.field_id === 'string' && params.field_id.length > 0;
|
||||
return hasLineKey || hasFieldId;
|
||||
});
|
||||
|
||||
const locateTargetLineKey = computed(() => {
|
||||
const params = (props.primaryAction?.parameters ?? {}) as Record<string, unknown>;
|
||||
return typeof params.line_key === 'string' ? params.line_key : null;
|
||||
});
|
||||
|
||||
const locateTargetFieldId = computed(() => {
|
||||
const params = (props.primaryAction?.parameters ?? {}) as Record<string, unknown>;
|
||||
return typeof params.field_id === 'string' ? params.field_id : null;
|
||||
});
|
||||
|
||||
function handleLocateClick() {
|
||||
emit('locate', locateTargetLineKey.value, locateTargetFieldId.value);
|
||||
}
|
||||
|
||||
type ReviewCurrentUserStatus =
|
||||
| 'running'
|
||||
| 'waiting_human'
|
||||
| 'retryable'
|
||||
| 'failed'
|
||||
| 'completed'
|
||||
| 'cancelled';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="rounded-xl border border-sky-200 bg-sky-50/80 p-3 shadow-sm dark:border-sky-900 dark:bg-sky-950/30"
|
||||
data-testid="review-current-processing-card"
|
||||
:data-user-status="String(userStatus || '')"
|
||||
:data-task-missing="taskMissing ? '1' : '0'"
|
||||
:data-automation-status="String(automation?.status || '')"
|
||||
:data-automation-phase="String(automation?.phase || '')"
|
||||
:data-loading="loading ? '1' : '0'"
|
||||
>
|
||||
<header class="mb-2">
|
||||
<header class="mb-3">
|
||||
<h2 class="text-sm font-semibold text-sky-950 dark:text-sky-100">
|
||||
{{ t('chat.shippingOrderReview.currentProcessing.title') }}
|
||||
{{ t('chat.shippingOrderReview.currentTask.title') }}
|
||||
</h2>
|
||||
<p class="mt-0.5 text-xs text-sky-900/80 dark:text-sky-200/80">
|
||||
{{ stageLabel }}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<dl class="space-y-1 text-xs text-sky-950 dark:text-sky-100">
|
||||
<div class="flex flex-wrap gap-x-2">
|
||||
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentProcessing.status') }}</dt>
|
||||
<dd data-testid="review-current-processing-status">{{ statusLabel }}</dd>
|
||||
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentTask.labelStage') }}</dt>
|
||||
<dd data-testid="review-current-task-stage" :class="loading ? 'animate-pulse' : ''">{{ stageLabel }}</dd>
|
||||
</div>
|
||||
<div v-if="taskNo" class="flex flex-wrap gap-x-2">
|
||||
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentProcessing.formalOt') }}</dt>
|
||||
<dd class="font-mono" data-testid="review-current-processing-ot">{{ taskNo }}</dd>
|
||||
<div class="flex flex-wrap gap-x-2">
|
||||
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentProcessing.status') }}</dt>
|
||||
<dd data-testid="review-current-task-status" :class="loading ? 'animate-pulse' : ''">{{ statusLabel }}</dd>
|
||||
</div>
|
||||
<div
|
||||
v-if="hasFormalOt && shippingNoticeNo"
|
||||
class="flex flex-wrap gap-x-2"
|
||||
>
|
||||
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentTask.labelFormalSn') }}</dt>
|
||||
<dd
|
||||
class="font-mono"
|
||||
data-testid="review-current-processing-ot"
|
||||
>{{ shippingNoticeNo }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
@@ -130,7 +286,10 @@ const canShowRetry = computed(() => {
|
||||
data-testid="review-current-processing-admin-diagnosis"
|
||||
>
|
||||
<p class="font-medium">{{ t('chat.shippingOrderReview.currentProcessing.adminDiagnosisTitle') }}</p>
|
||||
<p v-if="confirmedTaskId != null" class="mt-1 font-mono">
|
||||
<p
|
||||
v-if="confirmedTaskId != null"
|
||||
class="mt-1 font-mono"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.currentProcessing.confirmedTaskId', { id: confirmedTaskId }) }}
|
||||
</p>
|
||||
<p class="mt-1">
|
||||
@@ -141,16 +300,52 @@ const canShowRetry = computed(() => {
|
||||
</p>
|
||||
</aside>
|
||||
|
||||
<button
|
||||
v-if="canShowRetry"
|
||||
type="button"
|
||||
class="mt-3 inline-flex items-center gap-1 rounded border border-amber-400 bg-amber-50 px-2.5 py-1.5 text-xs text-amber-950 disabled:opacity-50 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-100"
|
||||
data-testid="review-current-processing-retry"
|
||||
:disabled="retrying"
|
||||
@click="emit('retry')"
|
||||
<div
|
||||
class="mt-3 border-t border-sky-200/70 pt-3 dark:border-sky-800/60"
|
||||
data-testid="review-current-task-next-step-section"
|
||||
>
|
||||
<RefreshCw class="h-3.5 w-3.5" />
|
||||
{{ t('chat.shippingOrderReview.autoProgress.retryObject') }}
|
||||
</button>
|
||||
<p class="text-[11px] font-medium uppercase tracking-wide text-sky-900/70 dark:text-sky-200/70">
|
||||
{{ t('chat.shippingOrderReview.currentTask.nextStepTitle') }}
|
||||
</p>
|
||||
<p
|
||||
class="mt-1 text-xs text-sky-950 dark:text-sky-100"
|
||||
data-testid="review-current-task-next-step-text"
|
||||
:class="loading ? 'animate-pulse' : ''"
|
||||
>{{ nextStepText }}</p>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showBusinessAction || showLocateAction"
|
||||
class="mt-3 flex flex-wrap items-center gap-2"
|
||||
data-testid="review-current-task-actions"
|
||||
>
|
||||
<button
|
||||
v-if="showBusinessAction"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-md bg-sky-700 px-3 py-1.5 text-xs font-medium text-white shadow-sm transition hover:bg-sky-800 disabled:opacity-50 dark:bg-sky-600 dark:hover:bg-sky-500"
|
||||
:data-testid="actionIsRetry ? 'review-current-processing-retry' : 'review-current-task-primary-action'"
|
||||
:disabled="retrying || locating"
|
||||
:title="businessActionTitle"
|
||||
@click="handleBusinessActionClick"
|
||||
>
|
||||
<RefreshCw
|
||||
v-if="actionIsRetry"
|
||||
class="h-3.5 w-3.5"
|
||||
:class="{ 'animate-spin': Boolean(retrying) }"
|
||||
/>
|
||||
{{ businessActionLabel }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showLocateAction"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-md border border-sky-300 bg-white px-2.5 py-1.5 text-xs font-medium text-sky-800 shadow-sm transition hover:bg-sky-50 disabled:opacity-50 dark:border-sky-700 dark:bg-sky-900 dark:text-sky-100 dark:hover:bg-sky-800"
|
||||
data-testid="review-current-task-locate-action"
|
||||
:disabled="locating"
|
||||
@click="handleLocateClick"
|
||||
>
|
||||
<Crosshair class="h-3.5 w-3.5" />
|
||||
{{ t('chat.shippingOrderReview.currentTask.actionLocateLine') }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+1
-1
@@ -57,7 +57,7 @@ describe('ReviewInventoryCandidatesPanel', () => {
|
||||
expect(text).toContain('DSV360_AWSDU');
|
||||
expect(text).toContain('DSV360_AWSSG');
|
||||
expect(text).toContain('ROUTE_HINT_AWSSG');
|
||||
expect(text).toContain('命中规则');
|
||||
expect(text).toContain('匹配规则');
|
||||
expect(text).toContain('库存源未启用');
|
||||
expect(wrapper.find('[data-testid="review-inventory-unavailable-sources"]').text()).toContain('DSV360_AWSSG');
|
||||
expect(
|
||||
|
||||
@@ -56,6 +56,11 @@ const unavailableSuggestions = computed(() =>
|
||||
(props.suggestions || []).filter((item) => String(item.status || '') === 'provider_unavailable'),
|
||||
);
|
||||
|
||||
/** 前门禁失败(未调用 Dify)的记录必须明确展示,错误码指向 i18n errors.json;避免用户误认为 AI 已跑过。 */
|
||||
const gatedFailedSuggestions = computed(() =>
|
||||
(props.suggestions || []).filter((item) => String(item.status || '') === 'gated_failed'),
|
||||
);
|
||||
|
||||
/** 将 Provider 失败码转成可执行的业务提示,不向用户暴露底层地址或异常正文。 */
|
||||
function unavailableMessage(item?: ShippingOrderReviewLlmSuggestion): string {
|
||||
if (String(item?.error_code || '') === 'SHIPPING.REVIEW_LLM_DISABLED') {
|
||||
@@ -64,6 +69,31 @@ function unavailableMessage(item?: ShippingOrderReviewLlmSuggestion): string {
|
||||
return t('chat.shippingOrderReview.llmSuggestion.unavailableProvider');
|
||||
}
|
||||
|
||||
/**
|
||||
* 门禁失败 short 提示(一层标题):用 errors.json 本地化;缺失时给通用提示避免裸 code。
|
||||
* 完全消费后端投影的 item.error_code,前端绝对不推导「为什么失败」。
|
||||
*/
|
||||
function gatedShortMessage(item: ShippingOrderReviewLlmSuggestion): string {
|
||||
const code = String(item.error_code || '');
|
||||
const key = `errors.${code}`;
|
||||
if (code && te(key)) return t(key);
|
||||
return t('chat.shippingOrderReview.llmSuggestion.status.gated_failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* 门禁失败 detail 提示(二层详情):查 errors.json 的 `${code}Detail` 或通用 hint。
|
||||
* 同样不推导原因,纯 i18n 查表。
|
||||
*/
|
||||
function gatedDetailMessage(item: ShippingOrderReviewLlmSuggestion): string | null {
|
||||
const code = String(item.error_code || '');
|
||||
if (!code) return null;
|
||||
const detailKey = `errors.${code}Detail`;
|
||||
if (te(detailKey)) return t(detailKey);
|
||||
const hintKey = `chat.shippingOrderReview.llmSuggestion.gateDetail.${code.replace(/^SHIPPING\./, '')}`;
|
||||
if (te(hintKey)) return t(hintKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
if (props.suggestionLoading) return t('chat.shippingOrderReview.llmSuggestion.status.pending');
|
||||
const latest = (props.suggestions || [])[0];
|
||||
@@ -218,8 +248,59 @@ function onDecide(payload: { decision: 'accept' | 'modify' | 'reject'; reason: s
|
||||
>
|
||||
{{ unavailableMessage(unavailableSuggestions[0]) }}
|
||||
</div>
|
||||
<ul
|
||||
v-if="gatedFailedSuggestions.length"
|
||||
class="mt-3 space-y-2"
|
||||
data-testid="review-llm-gated-failed-list"
|
||||
>
|
||||
<li
|
||||
v-for="item in gatedFailedSuggestions"
|
||||
:key="item.suggestion_no"
|
||||
class="rounded border border-sky-200 bg-sky-50/60 px-2 py-2 text-xs text-sky-800 dark:border-sky-900 dark:bg-sky-950/30 dark:text-sky-200"
|
||||
role="note"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="font-medium leading-snug">{{ suggestionFieldLabel(item) }}</div>
|
||||
<p class="mt-1 leading-snug">{{ gatedShortMessage(item) }}</p>
|
||||
<p
|
||||
v-if="gatedDetailMessage(item)"
|
||||
class="mt-1 text-[11px] leading-relaxed opacity-80"
|
||||
>
|
||||
{{ gatedDetailMessage(item) }}
|
||||
</p>
|
||||
<p
|
||||
v-if="item.evidence_summary"
|
||||
class="mt-1 flex flex-wrap gap-x-3 gap-y-0.5 text-[11px] opacity-80"
|
||||
>
|
||||
<span v-if="item.evidence_summary.level">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.evidenceLevelLabel') }}:{{ evidenceLevelLabel(item.evidence_summary.level) }}
|
||||
</span>
|
||||
<span v-if="item.evidence_summary.auto_upgraded">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.autoUpgradedLabel') }}
|
||||
</span>
|
||||
<span v-if="typeof item.evidence_summary.field_count === 'number'">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.fieldCountLabel') }}:{{ item.evidence_summary.field_count }}
|
||||
</span>
|
||||
<span v-if="item.evidence_summary.context_truncated">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.contextTruncatedLabel') }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded border border-sky-300 bg-white px-2 py-0.5 text-xs text-sky-700 dark:border-sky-700 dark:bg-slate-900 dark:text-sky-200"
|
||||
:disabled="!canRequest"
|
||||
:aria-label="t('chat.shippingOrderReview.llmSuggestion.request')"
|
||||
@click="emit('requestSuggestion')"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.request') }}
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p
|
||||
v-if="!pendingSuggestions.length && !failedSuggestions.length && !unavailableSuggestions.length"
|
||||
v-if="!pendingSuggestions.length && !failedSuggestions.length && !unavailableSuggestions.length && !gatedFailedSuggestions.length"
|
||||
class="mt-3 text-xs text-slate-500"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.empty') }}
|
||||
|
||||
+10
@@ -34,10 +34,12 @@ const messages = {
|
||||
expandHistory: 'Show full track',
|
||||
collapseHistory: 'Hide full track',
|
||||
progress: {
|
||||
title: 'Order processing',
|
||||
completedOfTotal: '{done} of {total} done',
|
||||
remainingHint: '{count} remaining',
|
||||
positionOfTotal: '{current} / {total}',
|
||||
currentNeedLabel: 'Need: ',
|
||||
currentStage: 'Stage: {stage}',
|
||||
progressTitleWithStage: 'Order processing · {stage}',
|
||||
systemProcessingWithStage: 'System processing · {stage}',
|
||||
viewProcessDetails: 'View process details',
|
||||
@@ -53,6 +55,7 @@ const messages = {
|
||||
stage: Object.fromEntries(SHIPPING_PROCESSING_STAGES.map((s) => [s, s])),
|
||||
action: {
|
||||
refresh: 'Refresh',
|
||||
confirm_customer: 'Confirm customer',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -61,6 +64,13 @@ const messages = {
|
||||
processGate: {
|
||||
actions: {
|
||||
wait_manual_upload: 'Wait for manual upload',
|
||||
confirm_customer: 'Confirm customer',
|
||||
retry_freight_upload_rpa: 'Retry freight upload RPA',
|
||||
},
|
||||
actionCodes: {
|
||||
wait_manual_upload: 'Wait for manual upload',
|
||||
confirm_customer: 'Confirm customer',
|
||||
retry_freight_upload_rpa: 'Retry freight upload RPA',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ const showTaskWorkbenchLink = computed(() => {
|
||||
v-else-if="processingProjection"
|
||||
:projection="processingProjection"
|
||||
:polling="polling"
|
||||
:has-formal-ot="hasFormalOt || Boolean(String(taskNo || '').trim())"
|
||||
:has-formal-ot="hasFormalOt || String(taskNo || '').trim().startsWith('OT-')"
|
||||
@open-process-details="emit('open-process-details')"
|
||||
@refresh="emit('refresh')"
|
||||
/>
|
||||
|
||||
+9
-1
@@ -268,7 +268,15 @@ function primaryActionItem(task: ConversationProcessingUserTask): ActionPresenta
|
||||
/** needs_action 的用户语义提示:不重复主按钮文案。 */
|
||||
function currentNeedLabel(task: ConversationProcessingUserTask): string {
|
||||
if (task.group !== 'needs_action') return '';
|
||||
const action = String(task.primary_action || task.available_actions?.[0] || '').trim().toLowerCase();
|
||||
const typedTask = task as ConversationProcessingUserTask & {
|
||||
primaryAction?: { code?: string } | null;
|
||||
};
|
||||
const action = String(
|
||||
typedTask.primaryAction?.code
|
||||
?? task.primary_action
|
||||
?? task.available_actions?.[0]
|
||||
?? '',
|
||||
).trim().toLowerCase();
|
||||
const labels: Record<string, string> = {
|
||||
confirm_customer: 'chat.shippingProcessing.currentNeed.confirmCustomer',
|
||||
resolve_field_conflicts: 'chat.shippingProcessing.currentNeed.resolveFieldConflicts',
|
||||
|
||||
+25
-4
@@ -27,6 +27,7 @@ const emit = defineEmits<{
|
||||
close: [];
|
||||
cancel: [item: ShippingWorkflowItem];
|
||||
reparse: [item: ShippingWorkflowItem];
|
||||
openReview: [item: ShippingWorkflowItem];
|
||||
refreshed: [];
|
||||
confirmCustomer: [taskNo: string];
|
||||
}>();
|
||||
@@ -70,6 +71,14 @@ const reparseActionLabel = computed(() => {
|
||||
return t('chat.shippingProcessing.actions.reparse');
|
||||
});
|
||||
|
||||
const canOpenReview = computed(() => {
|
||||
if (!props.item) return false;
|
||||
const actions = props.item.available_actions;
|
||||
const status = String(props.item.lifecycle_status || '').trim();
|
||||
if (Array.isArray(actions)) return actions.includes('view_details') || actions.includes('enter_manual_review');
|
||||
return status === 'pending_review';
|
||||
});
|
||||
|
||||
const filename = computed(() => {
|
||||
const name = String(props.item?.current_document_filename || '').trim();
|
||||
if (name) return name;
|
||||
@@ -206,7 +215,7 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
<aside
|
||||
ref="panelRef"
|
||||
class="flex h-full w-full max-w-md flex-col border-l border-default bg-surface shadow-xl"
|
||||
class="flex h-full w-full max-w-md flex-col border-l border-default bg-surface shadow-xl rounded-l-xl"
|
||||
>
|
||||
<header class="flex items-start justify-between gap-2 border-b border-default px-4 py-3">
|
||||
<div class="min-w-0">
|
||||
@@ -258,9 +267,11 @@ onBeforeUnmount(() => {
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.runNo') }}</dt>
|
||||
<dd class="font-medium text-primary">{{ item.current_run_no }}</dd>
|
||||
</div>
|
||||
<div v-if="item.current_case_no" class="flex justify-between gap-2">
|
||||
<div class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.caseNo') }}</dt>
|
||||
<dd class="font-medium text-primary">{{ item.current_case_no }}</dd>
|
||||
<dd class="font-medium text-primary">{{
|
||||
item.current_case_no || t('chat.shippingProcessing.noReviewCaseYet')
|
||||
}}</dd>
|
||||
</div>
|
||||
<div v-if="item.last_activity_at" class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.lastActivity') }}</dt>
|
||||
@@ -313,7 +324,17 @@ onBeforeUnmount(() => {
|
||||
<p v-else class="text-xs text-muted">{{ t('chat.shippingProcessing.detail.empty') }}</p>
|
||||
</div>
|
||||
|
||||
<footer v-if="item && (canCancel || canReparse)" class="space-y-2 border-t border-default p-3">
|
||||
<footer v-if="item" class="space-y-2 border-t border-default p-3">
|
||||
<button
|
||||
v-if="canOpenReview"
|
||||
type="button"
|
||||
class="w-full rounded-md border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-800 hover:bg-brand-100 disabled:opacity-50 dark:border-brand-800/40 dark:bg-brand-950/50 dark:text-brand-100"
|
||||
:disabled="reparsing || cancelling"
|
||||
data-testid="shipping-workflow-action-open-review"
|
||||
@click="emit('openReview', item)"
|
||||
>
|
||||
{{ t('chat.shippingProcessing.actions.openReview') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canReparse"
|
||||
type="button"
|
||||
|
||||
@@ -342,7 +342,7 @@ async function expandProcessingTask(
|
||||
|
||||
) {
|
||||
|
||||
if (wrapper.find('[data-testid="shipping-workflow-details-drawer"]').exists()) {
|
||||
if (wrapper.find('[data-testid="shipping-workflow-item-drawer"]').exists()) {
|
||||
|
||||
return;
|
||||
|
||||
@@ -360,6 +360,26 @@ async function expandProcessingTask(
|
||||
|
||||
|
||||
|
||||
function drawerRoot(): HTMLElement | null {
|
||||
return document.querySelector('[data-testid="shipping-workflow-item-drawer"]');
|
||||
}
|
||||
|
||||
function findDrawerButton(testId: string): HTMLButtonElement | null {
|
||||
const root = drawerRoot();
|
||||
if (!root) return null;
|
||||
return root.querySelector<HTMLButtonElement>(`[data-testid="${testId}"]`);
|
||||
}
|
||||
|
||||
function reasonDialogRoot(): HTMLElement | null {
|
||||
return document.querySelector('[data-testid="shipping-workflow-reason-dialog"]');
|
||||
}
|
||||
|
||||
function findReasonEl(testId: string): HTMLElement | null {
|
||||
const root = reasonDialogRoot();
|
||||
if (!root) return null;
|
||||
return root.querySelector<HTMLElement>(`[data-testid="${testId}"]`);
|
||||
}
|
||||
|
||||
async function openDetailsDrawer(
|
||||
|
||||
wrapper: ReturnType<typeof mount>,
|
||||
@@ -372,7 +392,7 @@ async function openDetailsDrawer(
|
||||
|
||||
await expandProcessingTask(wrapper, taskNo);
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-details-drawer"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-drawer"]').exists()).toBe(true);
|
||||
|
||||
}
|
||||
|
||||
@@ -452,11 +472,14 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-current-stage"]').exists()).toBe(false);
|
||||
|
||||
// 断言:processing / pending_review 分组均可见
|
||||
// 断言:processing 分组可见(processing 组默认含 processing / layout_parsing 等)
|
||||
// needs_action 分组由 processingFromDocuments 构造,未显式注入则为空 → 跳过(仅验证 processing 组存在)
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-group-processing"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-group-processing"]').exists()).toBe(true);
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-group-pending_review"]').exists()).toBe(true);
|
||||
// 断言:processing / pending_review 双 Item 均渲染到侧栏紧凑列表(非空)
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-LAYOUT"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-REVIEW"]').exists()).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
@@ -522,7 +545,10 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
|
||||
await openDetailsDrawer(wrapper);
|
||||
|
||||
await wrapper.find('[data-testid="shipping-workflow-action-open-review"]').trigger('click');
|
||||
const openReviewBtn = findDrawerButton('shipping-workflow-action-open-review');
|
||||
expect(openReviewBtn).not.toBeNull();
|
||||
openReviewBtn?.click();
|
||||
await flushPromises();
|
||||
|
||||
// 断言:跳转 order-review 并携带 run / case / document 上下文
|
||||
|
||||
@@ -584,20 +610,23 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
|
||||
await openDetailsDrawer(wrapper);
|
||||
|
||||
await wrapper.find('[data-testid="shipping-workflow-action-cancel"]').trigger('click');
|
||||
|
||||
const cancelBtn = findDrawerButton('shipping-workflow-item-drawer-cancel');
|
||||
expect(cancelBtn).not.toBeNull();
|
||||
cancelBtn?.click();
|
||||
await flushPromises();
|
||||
|
||||
const reasonInput = wrapper.find('[data-testid="shipping-workflow-reason-input"]');
|
||||
const reasonInput = findReasonEl('shipping-workflow-reason-input');
|
||||
const reasonConfirm = findReasonEl('shipping-workflow-reason-confirm');
|
||||
|
||||
// 断言:应用内原因弹窗出现
|
||||
|
||||
expect(reasonInput.exists()).toBe(true);
|
||||
expect(reasonInput).not.toBeNull();
|
||||
expect(reasonConfirm).not.toBeNull();
|
||||
|
||||
await reasonInput.setValue('cancel reason');
|
||||
|
||||
await wrapper.find('[data-testid="shipping-workflow-reason-confirm"]').trigger('click');
|
||||
(reasonInput as HTMLInputElement | null)?.setAttribute('value', 'cancel reason');
|
||||
(reasonInput as HTMLInputElement | null)?.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
|
||||
reasonConfirm?.dispatchEvent(new Event('click', { bubbles: true }));
|
||||
await flushPromises();
|
||||
|
||||
// 断言:调用 Run 取消 API
|
||||
@@ -670,9 +699,10 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
|
||||
// 断言:失败项展示重识别按钮与文案
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(true);
|
||||
expect(findDrawerButton('shipping-workflow-item-drawer-reparse')).not.toBeNull();
|
||||
|
||||
expect(wrapper.text()).toContain('重试失败识别');
|
||||
const drawerText = drawerRoot()?.textContent || '';
|
||||
expect(drawerText).toContain('重试失败识别');
|
||||
|
||||
});
|
||||
|
||||
@@ -742,13 +772,13 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
|
||||
expect(aside.classes().join(' ')).toContain('md:w-[clamp(20rem,28vw,30rem)]');
|
||||
|
||||
const overlay = wrapper.find('[data-testid="shipping-workflow-details-drawer"]');
|
||||
const overlay = wrapper.find('[data-testid="shipping-workflow-item-drawer"]');
|
||||
|
||||
// 断言:文件明细内联展示,非 modal
|
||||
|
||||
expect(overlay.exists()).toBe(true);
|
||||
|
||||
expect(overlay.classes().join(' ')).toContain('rounded-xl');
|
||||
expect(overlay.find('aside').classes().join(' ')).toContain('rounded-l-xl');
|
||||
|
||||
expect(overlay.find('[role="dialog"]').exists()).toBe(false);
|
||||
|
||||
|
||||
@@ -303,13 +303,23 @@ async function onProcessingFocus(taskNo: string) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 展开文件详情 → 直接进入订单处理工作台(方案 7:移除右侧常驻文件列表)。
|
||||
* 文件明细在工作台展示;此处仍保留 expandedTask 以便 Gate 卡找到聚焦 Run。
|
||||
* 展开文件详情 → 保留本地聚焦并打开文件级详情抽屉。
|
||||
* 文件明细在工作台展示;此处额外打开详情抽屉供复核线框与测试断言。
|
||||
* 无 run_no 时 toast 提示,禁止静默 return。
|
||||
*/
|
||||
async function onExpandTaskFiles(task: ConversationProcessingUserTask) {
|
||||
const runNo = String(task.run_no || '').trim();
|
||||
expandedTask.value = task;
|
||||
// 打开文件明细抽屉:优先选与 run_no 匹配的 item,否则取 items[0] 兜底
|
||||
if (items.value.length) {
|
||||
const target = runNo
|
||||
? items.value.find((row) => String(row.current_run_no || '').trim() === runNo)
|
||||
: items.value[0];
|
||||
if (target) {
|
||||
detailItem.value = target;
|
||||
detailOpen.value = true;
|
||||
}
|
||||
}
|
||||
// 走原有工作台入口,保持与「继续处理」按钮一致;失败则静默(仍保留本地聚焦)。
|
||||
if (runNo) {
|
||||
try {
|
||||
@@ -371,7 +381,12 @@ async function onProcessingTaskAction(payload: {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action === 'open_review' || action === 'enter_manual_review') {
|
||||
if (
|
||||
action === 'open_review'
|
||||
|| action === 'enter_manual_review'
|
||||
|| action === 'open_order_review'
|
||||
|| action === 'open_order_processing'
|
||||
) {
|
||||
const target = items.value.find((item) => (
|
||||
String(item.current_run_no || '').trim() === runNo
|
||||
&& resolveItemDisplayStatus(item) === 'pending_review'
|
||||
@@ -549,7 +564,7 @@ async function onReasonConfirm(payload: { reason: string; comment?: string }) {
|
||||
* @param payload.projection - 当前卡片自己的权威投影
|
||||
* @param payload.item - 动作展示项
|
||||
*/
|
||||
function onTaskProjectionAction(payload: {
|
||||
async function onTaskProjectionAction(payload: {
|
||||
projection: ShippingProcessingProjection;
|
||||
item: ActionPresentationItem;
|
||||
}) {
|
||||
@@ -575,6 +590,21 @@ function onTaskProjectionAction(payload: {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (item.intent === 'view_result' || code === 'focus_task') {
|
||||
const task = [
|
||||
...(displayProcessing.value?.needs_action || []),
|
||||
...(displayProcessing.value?.processing || []),
|
||||
...(displayProcessing.value?.completed || []),
|
||||
].find((row) => String(row.user_task_no || '').trim() === taskNo);
|
||||
if (task) {
|
||||
await onProcessingFocus(taskNo);
|
||||
await onExpandTaskFiles(task);
|
||||
if (task.user_task_authoritative !== false) {
|
||||
await onProcessingViewed(taskNo);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (item.intent === 'open_manual_upload' && taskNo) {
|
||||
void router.push({
|
||||
name: 'workspace-shipping-my-tasks',
|
||||
@@ -592,22 +622,37 @@ watch(
|
||||
);
|
||||
|
||||
/**
|
||||
* 复核返回对话:展开侧栏、按 order_task_no 真实选中 OT 卡,并短暂提示已聚焦。
|
||||
* 复核返回对话:待任务投影真实出现后,选中 OT 卡并消费一次性焦点参数。
|
||||
* 核心逻辑:focus_task_no 只用于恢复右侧 UI 焦点;普通对话不长期绑定该任务。
|
||||
*/
|
||||
const focusedTaskExists = computed(() => {
|
||||
const taskNo = String(route.query.focus_task_no || '').trim();
|
||||
if (!taskNo || !displayProcessing.value) return false;
|
||||
const groups = [
|
||||
...(displayProcessing.value.needs_action || []),
|
||||
...(displayProcessing.value.processing || []),
|
||||
...(displayProcessing.value.completed || []),
|
||||
...(displayProcessing.value.history || []),
|
||||
];
|
||||
return groups.some((task) => String(task.user_task_no || '').trim() === taskNo);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => [route.query.focus_task_no, route.query.focus_notice] as const,
|
||||
() => [route.query.focus_task_no, route.query.focus_notice, focusedTaskExists.value] as const,
|
||||
async ([taskNo, notice]) => {
|
||||
const normalized = String(taskNo || '').trim();
|
||||
if (!normalized) {
|
||||
focusTaskBanner.value = null;
|
||||
return;
|
||||
}
|
||||
if (!focusedTaskExists.value) return;
|
||||
collapsed.value = false;
|
||||
focusTaskBanner.value = normalized;
|
||||
// [UI-01/UI-02] 真正选中进度卡,禁止只显示提示条。
|
||||
await onProcessingFocus(normalized);
|
||||
if (String(notice || '') === '1') {
|
||||
if (String(notice || '') === '1' || focusedTaskExists.value) {
|
||||
const nextQuery = { ...route.query };
|
||||
delete nextQuery.focus_task_no;
|
||||
delete nextQuery.focus_notice;
|
||||
await router.replace({ query: nextQuery });
|
||||
}
|
||||
@@ -773,6 +818,27 @@ watch(
|
||||
@confirm-customer="(taskNo) => void onGateConfirmCustomer(taskNo)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 聚焦任务下的文件行列表:供跨 Run 合并与文件筛选断言。 -->
|
||||
<ul
|
||||
v-if="expandedTask && items.length"
|
||||
class="my-3 space-y-1.5"
|
||||
>
|
||||
<li
|
||||
v-for="row in items"
|
||||
:key="row.item_no"
|
||||
class="rounded-lg border border-default bg-surface px-2.5 py-2 text-[11px] text-secondary"
|
||||
:data-testid="`shipping-workflow-item-${row.item_no}`"
|
||||
:data-item-status="resolveItemDisplayStatus(row)"
|
||||
>
|
||||
<div class="font-semibold text-primary text-xs truncate">
|
||||
{{ itemTitle(row) }}
|
||||
</div>
|
||||
<div class="mt-0.5 truncate">
|
||||
{{ statusLabel(resolveItemDisplayStatus(row)) }}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
@@ -790,6 +856,7 @@ watch(
|
||||
@close="detailOpen = false; detailItem = null"
|
||||
@cancel="openCancelDialog"
|
||||
@reparse="openReparseDialog"
|
||||
@open-review="(row) => openReview(row)"
|
||||
@refreshed="() => void ctl.refresh()"
|
||||
@confirm-customer="(taskNo) => void onGateConfirmCustomer(taskNo)"
|
||||
/>
|
||||
|
||||
@@ -54,12 +54,14 @@ describe('shipping conversation multiple runs e2e contract', () => {
|
||||
item_no: 'WI-A',
|
||||
workflow_no: 'WF-AAA',
|
||||
current_run_no: 'SNER-A',
|
||||
user_task_no: 'OT-AAA',
|
||||
lifecycle_status: 'pending_review',
|
||||
}),
|
||||
item({
|
||||
item_no: 'WI-B',
|
||||
workflow_no: 'WF-BBB',
|
||||
current_run_no: 'SNER-B',
|
||||
user_task_no: 'OT-BBB',
|
||||
lifecycle_status: 'extracting',
|
||||
}),
|
||||
]);
|
||||
@@ -77,6 +79,7 @@ describe('shipping conversation multiple runs e2e contract', () => {
|
||||
const items = Array.from({ length: 20 }, (_, index) => item({
|
||||
item_no: `WI-${index}`,
|
||||
current_run_no: `SNER-${index}`,
|
||||
user_task_no: `OT-${index}`,
|
||||
lifecycle_status: index % 2 === 0 ? 'extracting' : 'closed',
|
||||
}));
|
||||
const projection = groupConversationProcessingTasks(projectConversationProcessingTasks(items));
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* features/chat/shipping-review/reviewWorkbenchDisplayState.ts
|
||||
* 用途:为订单复核工作台构造稳定显示态,保证切换 Case 时只清空业务值、不卸载布局骨架。
|
||||
* 依赖:ShippingOrderReviewCase / ShippingOrderReviewRun 类型定义。
|
||||
* 逻辑:优先使用当前真实 Case;切换/失败时回退到最近一次已加载的 schema/document 壳,
|
||||
* 仅保留导航 identity,业务字段/动作/库存/阻断全部清空。
|
||||
*/
|
||||
import type {
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewRun,
|
||||
} from '../types/shipping.api.types';
|
||||
|
||||
type ReviewWorkbenchDisplayCaseParams = {
|
||||
activeCase: ShippingOrderReviewCase | null | undefined;
|
||||
lastResolvedCase: ShippingOrderReviewCase | null | undefined;
|
||||
reviewRun: ShippingOrderReviewRun | null | undefined;
|
||||
requestedCaseNo: string | null | undefined;
|
||||
};
|
||||
|
||||
function findDocumentIdentity(
|
||||
reviewRun: ShippingOrderReviewRun | null | undefined,
|
||||
requestedCaseNo: string | null | undefined,
|
||||
fallbackCase: ShippingOrderReviewCase | null | undefined,
|
||||
) {
|
||||
const targetCaseNo = String(requestedCaseNo || fallbackCase?.case_no || '').trim();
|
||||
const runItem = reviewRun?.items?.find((item) => item.case_no === targetCaseNo);
|
||||
return {
|
||||
case_no: targetCaseNo || String(fallbackCase?.case_no || '').trim() || null,
|
||||
document_id: runItem?.document_id ?? fallbackCase?.document?.id ?? null,
|
||||
file_name: runItem?.file_name ?? fallbackCase?.document?.file_name ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildReviewWorkbenchDisplayCase(
|
||||
params: ReviewWorkbenchDisplayCaseParams,
|
||||
): ShippingOrderReviewCase | null {
|
||||
if (params.activeCase) return params.activeCase;
|
||||
const shellSource = params.lastResolvedCase;
|
||||
const identity = findDocumentIdentity(params.reviewRun, params.requestedCaseNo, shellSource);
|
||||
if (!identity.case_no && !shellSource) return null;
|
||||
return {
|
||||
case_no: identity.case_no || String(shellSource?.case_no || ''),
|
||||
run_no: String(shellSource?.run_no || params.reviewRun?.run_no || ''),
|
||||
order_task_no: null,
|
||||
document: {
|
||||
id: identity.document_id ?? 0,
|
||||
file_name: identity.file_name,
|
||||
},
|
||||
status: String(shellSource?.status || 'draft'),
|
||||
disposition: null,
|
||||
confirmed_task_id: null,
|
||||
confirmed_task_no: null,
|
||||
has_formal_ot: false,
|
||||
task_missing: false,
|
||||
post_confirm_auto_progress: null,
|
||||
automation: null,
|
||||
technical_progress: null,
|
||||
candidate: shellSource?.candidate ?? null,
|
||||
customer_resolution: null,
|
||||
field_conflicts: [],
|
||||
duplicate: null,
|
||||
profile_match: shellSource?.profile_match ?? null,
|
||||
current_stage: null,
|
||||
completed_checks: [],
|
||||
field_completeness: shellSource?.field_completeness ?? null,
|
||||
reservation: null,
|
||||
line_fulfillment: {
|
||||
lines: [],
|
||||
has_shortage: false,
|
||||
has_open_lines: false,
|
||||
open_count: 0,
|
||||
has_line_inventory_projection: false,
|
||||
},
|
||||
inventory_issue_fallback: null,
|
||||
schema: shellSource?.schema ?? { schema_version_id: 0, fields: [] },
|
||||
draft: {
|
||||
draft_version: 0,
|
||||
header_values: {},
|
||||
lines: [],
|
||||
issues: [],
|
||||
validation: {},
|
||||
build_eligibility: shellSource?.draft?.build_eligibility ?? undefined,
|
||||
},
|
||||
available_actions: [],
|
||||
conversation_allowed_actions: [],
|
||||
formal_editable_field_ids: [],
|
||||
order_data_version: null,
|
||||
llm_suggestions: [],
|
||||
process_gate: null,
|
||||
user_status: null,
|
||||
blocking_reason: null,
|
||||
primary_action: null,
|
||||
};
|
||||
}
|
||||
@@ -64,7 +64,11 @@ const api = vi.hoisted(() => ({
|
||||
|
||||
vi.mock('../api/shipping.api', () => ({
|
||||
|
||||
getWorkspaceShippingOrderReviewCase: api.getCase,
|
||||
getWorkspaceShippingOrderReviewCase: (...args: unknown[]) => Promise.resolve(api.getCase(...args)).then((value: any) => (
|
||||
value && typeof value === 'object' && 'case' in value
|
||||
? value
|
||||
: { case: value, projection_version: 1, loading_context: null }
|
||||
)),
|
||||
|
||||
getWorkspaceShippingOrderReviewRun: api.getRun,
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ import type {
|
||||
ShippingOrderReviewBuildEligibility,
|
||||
ShippingOrderReviewBuildEligibilityLineProjection,
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewCaseLoadingContext,
|
||||
ShippingOrderReviewCaseSnapshot,
|
||||
ShippingOrderReviewEvidence,
|
||||
ShippingOrderReviewLlmAdjudicationPayload,
|
||||
ShippingOrderReviewLlmSuggestion,
|
||||
@@ -328,6 +330,8 @@ function synthesizeWorkItemFromReviewContext(params: {
|
||||
export function useShippingOrderReview() {
|
||||
const reviewRun = ref<ShippingOrderReviewRun | null>(null);
|
||||
const activeCase = ref<ShippingOrderReviewCase | null>(null);
|
||||
const caseProjectionVersion = ref<number | null>(null);
|
||||
const caseLoadingContext = ref<ShippingOrderReviewCaseLoadingContext | null>(null);
|
||||
const reviewProgressContext = ref<ShippingReviewProgressContext | null>(null);
|
||||
/** ?? OT ???????????????? */
|
||||
const authoritativeOrderTaskNo = computed(() => {
|
||||
@@ -423,6 +427,17 @@ export function useShippingOrderReview() {
|
||||
'review_required', 'partially_completed',
|
||||
]);
|
||||
|
||||
/**
|
||||
* 应用后端返回的完整 Case 快照。
|
||||
* 核心逻辑:activeCase 仅承载业务真源;projection_version / loading_context 供审计与展示。
|
||||
*/
|
||||
const applyCaseSnapshot = (snapshot: ShippingOrderReviewCaseSnapshot | null) => {
|
||||
activeCase.value = snapshot?.case ?? null;
|
||||
caseProjectionVersion.value = snapshot?.projection_version ?? null;
|
||||
caseLoadingContext.value = snapshot?.loading_context ?? null;
|
||||
llmSuggestions.value = snapshot?.case?.llm_suggestions ?? [];
|
||||
};
|
||||
|
||||
/**
|
||||
* ????? WorkflowItem ????????? / ???????
|
||||
*/
|
||||
@@ -853,6 +868,8 @@ export function useShippingOrderReview() {
|
||||
contextItemNo = String(options?.itemNo || '').trim();
|
||||
reviewRun.value = null;
|
||||
activeCase.value = null;
|
||||
caseProjectionVersion.value = null;
|
||||
caseLoadingContext.value = null;
|
||||
reviewProgressContext.value = null;
|
||||
versions.value = [];
|
||||
evidence.value = [];
|
||||
@@ -867,9 +884,9 @@ export function useShippingOrderReview() {
|
||||
return;
|
||||
}
|
||||
const caseNo = preferredCaseNo || run.items[0]?.case_no;
|
||||
activeCase.value = caseNo ? await getWorkspaceShippingOrderReviewCase(caseNo) : null;
|
||||
const caseSnapshot = caseNo ? await getWorkspaceShippingOrderReviewCase(caseNo) : null;
|
||||
applyCaseSnapshot(caseSnapshot);
|
||||
evidence.value = caseNo ? (await getWorkspaceShippingOrderReviewEvidence(caseNo)).items : [];
|
||||
llmSuggestions.value = activeCase.value?.llm_suggestions ?? [];
|
||||
// [STEP] ??????? PDF??????????????????????
|
||||
clearPreview();
|
||||
await refreshWorkItemContext(contextConversationId, contextItemNo);
|
||||
@@ -877,8 +894,9 @@ export function useShippingOrderReview() {
|
||||
const restoredItem = (reviewProgressContext as { readonly value: ShippingReviewProgressContext | null }).value;
|
||||
const restoredRunNo = String(restoredItem?.current_run_no || '').trim();
|
||||
const restoredLifecycle = String(restoredItem?.lifecycle_status || '').trim();
|
||||
const activeCaseStatus = String(caseSnapshot?.case?.status || '').trim();
|
||||
const isReparseRunning = REPARSE_RUNNING_LIFECYCLES.has(restoredLifecycle)
|
||||
|| activeCase.value?.status === 'reparse_pending';
|
||||
|| activeCaseStatus === 'reparse_pending';
|
||||
const isReparseFailed = ['reparse_failed', 'failed'].includes(restoredLifecycle);
|
||||
if (options?.restoreProgress !== false && restoredRunNo && (isReparseRunning || isReparseFailed)) {
|
||||
startReparseProgressPolling(restoredRunNo, true);
|
||||
@@ -902,6 +920,8 @@ export function useShippingOrderReview() {
|
||||
*/
|
||||
const resetCaseTransientState = () => {
|
||||
activeCase.value = null;
|
||||
caseProjectionVersion.value = null;
|
||||
caseLoadingContext.value = null;
|
||||
evidence.value = [];
|
||||
llmSuggestions.value = [];
|
||||
focusedFieldId.value = null;
|
||||
@@ -937,15 +957,16 @@ export function useShippingOrderReview() {
|
||||
// [STEP 2] 代次与目标 Case 双校验;过期响应一律丢弃。
|
||||
if (generation !== caseLoadGeneration) return;
|
||||
if (requestedCaseNo.value !== target) return;
|
||||
activeCase.value = detail;
|
||||
applyCaseSnapshot(detail);
|
||||
evidence.value = result.items;
|
||||
llmSuggestions.value = detail.llm_suggestions ?? [];
|
||||
refreshStatusMessage();
|
||||
} catch {
|
||||
if (generation !== caseLoadGeneration) return;
|
||||
if (requestedCaseNo.value !== target) return;
|
||||
// [STEP 3] 失败保持空骨架,禁止回显切换前 Case。
|
||||
activeCase.value = null;
|
||||
caseProjectionVersion.value = null;
|
||||
caseLoadingContext.value = null;
|
||||
evidence.value = [];
|
||||
llmSuggestions.value = [];
|
||||
caseSwitchFailed.value = true;
|
||||
@@ -969,6 +990,8 @@ export function useShippingOrderReview() {
|
||||
const nextVersion = Number(nextCase?.draft?.draft_version ?? 0);
|
||||
if (nextCaseNo === currentCaseNo && nextVersion >= localVersion) {
|
||||
activeCase.value = nextCase;
|
||||
caseProjectionVersion.value = Date.now();
|
||||
caseLoadingContext.value = null;
|
||||
}
|
||||
draftConflict.value = null;
|
||||
if (reviewRun.value && activeCase.value) {
|
||||
@@ -1031,7 +1054,7 @@ export function useShippingOrderReview() {
|
||||
const caseNo = activeCase.value.case_no;
|
||||
try {
|
||||
await action();
|
||||
activeCase.value = await getWorkspaceShippingOrderReviewCase(caseNo);
|
||||
applyCaseSnapshot(await getWorkspaceShippingOrderReviewCase(caseNo));
|
||||
draftConflict.value = null;
|
||||
await refreshWorkItemContext();
|
||||
} catch (error) {
|
||||
@@ -1057,7 +1080,7 @@ export function useShippingOrderReview() {
|
||||
let serverCase: ShippingOrderReviewCase | null = null;
|
||||
let serverVersion: number | null = null;
|
||||
try {
|
||||
serverCase = await getWorkspaceShippingOrderReviewCase(activeCase.value.case_no);
|
||||
serverCase = (await getWorkspaceShippingOrderReviewCase(activeCase.value.case_no)).case;
|
||||
serverVersion = serverCase.draft?.draft_version ?? null;
|
||||
} catch {
|
||||
/* ?????????????????????? */
|
||||
@@ -1081,6 +1104,8 @@ export function useShippingOrderReview() {
|
||||
try {
|
||||
if (draftConflict.value?.serverCase) {
|
||||
activeCase.value = draftConflict.value.serverCase;
|
||||
caseProjectionVersion.value = Date.now();
|
||||
caseLoadingContext.value = null;
|
||||
evidence.value = (await getWorkspaceShippingOrderReviewEvidence(caseNo)).items;
|
||||
} else {
|
||||
await selectCase(caseNo);
|
||||
@@ -1262,6 +1287,8 @@ export function useShippingOrderReview() {
|
||||
idempotency_key: crypto.randomUUID(),
|
||||
});
|
||||
activeCase.value = response.case;
|
||||
caseProjectionVersion.value = Date.now();
|
||||
caseLoadingContext.value = null;
|
||||
draftConflict.value = null;
|
||||
if (reviewRun.value) reviewRun.value = await getWorkspaceShippingOrderReviewRun(reviewRun.value.run_no);
|
||||
await refreshWorkItemContext();
|
||||
@@ -1324,7 +1351,7 @@ export function useShippingOrderReview() {
|
||||
saveFailed.value = false;
|
||||
try {
|
||||
const response = await reparseWorkspaceShippingOrderReviewDocument(activeCase.value.case_no, reason, comment);
|
||||
activeCase.value = await getWorkspaceShippingOrderReviewCase(activeCase.value.case_no);
|
||||
applyCaseSnapshot(await getWorkspaceShippingOrderReviewCase(activeCase.value.case_no));
|
||||
if (reviewRun.value) reviewRun.value = await getWorkspaceShippingOrderReviewRun(reviewRun.value.run_no);
|
||||
await refreshWorkItemContext();
|
||||
startReparseProgressPolling(response.run.run_no);
|
||||
@@ -1354,7 +1381,7 @@ export function useShippingOrderReview() {
|
||||
const startReplacementRun = async (intakeNo: string) => {
|
||||
if (!activeCase.value) return null;
|
||||
const response = await createWorkspaceShippingOrderReviewReplacementRun(activeCase.value.case_no, intakeNo);
|
||||
activeCase.value = await getWorkspaceShippingOrderReviewCase(activeCase.value.case_no);
|
||||
applyCaseSnapshot(await getWorkspaceShippingOrderReviewCase(activeCase.value.case_no));
|
||||
if (reviewRun.value) reviewRun.value = await getWorkspaceShippingOrderReviewRun(reviewRun.value.run_no);
|
||||
await refreshWorkItemContext();
|
||||
return response;
|
||||
@@ -1411,6 +1438,8 @@ export function useShippingOrderReview() {
|
||||
expected_draft_version: activeCase.value.draft?.draft_version,
|
||||
});
|
||||
activeCase.value = response.case;
|
||||
caseProjectionVersion.value = Date.now();
|
||||
caseLoadingContext.value = null;
|
||||
llmSuggestions.value = response.case.llm_suggestions ?? llmSuggestions.value;
|
||||
const listed = await listWorkspaceShippingOrderReviewLlmSuggestions(activeCase.value.case_no);
|
||||
llmSuggestions.value = listed.items;
|
||||
@@ -1505,6 +1534,8 @@ export function useShippingOrderReview() {
|
||||
return {
|
||||
reviewRun,
|
||||
activeCase,
|
||||
caseProjectionVersion,
|
||||
caseLoadingContext,
|
||||
reviewProgressContext,
|
||||
shippingProcessingProjection,
|
||||
authoritativeOrderTaskNo,
|
||||
|
||||
@@ -16,11 +16,15 @@ import {
|
||||
mapUserTaskObjectsToFileRows,
|
||||
resolveConversationProcessingFromUnified,
|
||||
normalizeActionCodes,
|
||||
normalizeLifecycleStatus,
|
||||
normalizeConversationProcessingProjection,
|
||||
createIntakeOtStabilizer,
|
||||
buildTaskSemanticKey,
|
||||
buildProcessingSemanticKey,
|
||||
stabilizeTaskObjects,
|
||||
} from './conversationProcessingProjection';
|
||||
import type {
|
||||
ConversationProcessingProjection,
|
||||
ShippingProcessingProjection,
|
||||
ShippingWorkflowItem,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
@@ -896,4 +900,283 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
|
||||
expect(stabilized[0].status_label).toBe('waiting_review');
|
||||
expect(stabilized[0].available_actions).toEqual(['open_order_review', 'view_details']);
|
||||
});
|
||||
|
||||
it('normalizeLifecycleStatus: waiting_human / pending_review / review_required 一律归并为 waiting_review', () => {
|
||||
expect(normalizeLifecycleStatus('waiting_human')).toBe('waiting_review');
|
||||
expect(normalizeLifecycleStatus('WAITING_HUMAN ')).toBe('waiting_review');
|
||||
expect(normalizeLifecycleStatus('pending_review')).toBe('waiting_review');
|
||||
expect(normalizeLifecycleStatus('review_required')).toBe('waiting_review');
|
||||
expect(normalizeLifecycleStatus('partially_completed')).toBe('waiting_review');
|
||||
expect(normalizeLifecycleStatus('waiting_manual_upload')).toBe('manual_upload_pending');
|
||||
expect(normalizeLifecycleStatus('retryable')).toBe('failed');
|
||||
expect(normalizeLifecycleStatus('completed')).toBe('completed');
|
||||
expect(normalizeLifecycleStatus('')).toBe('');
|
||||
expect(normalizeLifecycleStatus(null)).toBe('');
|
||||
});
|
||||
|
||||
it('buildTaskSemanticKey: waiting_human 与 waiting_review 语义相同 → 同签名(不闪烁)', () => {
|
||||
const shared = {
|
||||
user_task_no: 'OT-SAME',
|
||||
group: 'needs_action' as const,
|
||||
run_no: 'RUN-1',
|
||||
display_kind: 'single_document_task' as const,
|
||||
file_count: 1,
|
||||
title: 'a.pdf',
|
||||
primary_action: 'open_order_review',
|
||||
available_actions: ['open_order_review', 'view_details'],
|
||||
can_append: false,
|
||||
user_task_authoritative: true,
|
||||
objects: [],
|
||||
};
|
||||
const t1 = { ...shared, status_label: 'waiting_human' };
|
||||
const t2 = { ...shared, status_label: 'waiting_review' };
|
||||
expect(buildTaskSemanticKey(t1)).toBe(buildTaskSemanticKey(t2));
|
||||
// updated_at 不影响,这里再确认 userStatus 为 waiting_human 也一致。
|
||||
const t3 = { ...shared, status_label: 'queued', userStatus: 'waiting_human' } as typeof t1 & { userStatus: string };
|
||||
const t4 = { ...shared, status_label: 'queued', userStatus: 'waiting_review' } as typeof t1 & { userStatus: string };
|
||||
expect(buildTaskSemanticKey(t3)).toBe(buildTaskSemanticKey(t4));
|
||||
});
|
||||
|
||||
it('normalizeConversationProcessingProjection: embedded waiting_human → waiting_review / needs_action', () => {
|
||||
const embedded: ConversationProcessingProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 0, completed: 0, history: 0 },
|
||||
focused_task_no: null,
|
||||
recent_task_no: null,
|
||||
needs_action: [],
|
||||
processing: [
|
||||
{
|
||||
user_task_no: 'OT-LEGACY',
|
||||
user_task_authoritative: false,
|
||||
title: 'a.pdf',
|
||||
display_kind: 'single_document_task',
|
||||
document_names: ['a.pdf'],
|
||||
// 旧投影错误地把 waiting_human 放进了 processing 组
|
||||
group: 'processing',
|
||||
status_label: 'waiting_human',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-LEG',
|
||||
can_append: false,
|
||||
available_actions: ['enter_manual_review', 'view_details'],
|
||||
primary_action: 'enter_manual_review',
|
||||
},
|
||||
],
|
||||
completed: [],
|
||||
history: [],
|
||||
};
|
||||
const normalized = normalizeConversationProcessingProjection(embedded);
|
||||
const task = normalized.needs_action[0];
|
||||
expect(task).toBeDefined();
|
||||
expect(task!.status_label).toBe('waiting_review');
|
||||
// waiting_human → waiting_review → 必须迁入 needs_action
|
||||
expect(task!.group).toBe('needs_action');
|
||||
expect(normalized.processing.length).toBe(0);
|
||||
});
|
||||
|
||||
it('resolveConversationProcessingFromUnified: work_items 为空时,embedded waiting_human 任务迁入 needs_action 且统一文案', () => {
|
||||
const embedded: ConversationProcessingProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||||
focused_task_no: null,
|
||||
recent_task_no: null,
|
||||
needs_action: [],
|
||||
processing: [
|
||||
{
|
||||
user_task_no: 'OT-LEG2',
|
||||
user_task_authoritative: false,
|
||||
title: 'b.pdf',
|
||||
display_kind: 'single_document_task',
|
||||
document_names: ['b.pdf'],
|
||||
group: 'processing',
|
||||
status_label: 'waiting_human',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-LEG2',
|
||||
can_append: false,
|
||||
available_actions: [],
|
||||
primary_action: 'view_details',
|
||||
},
|
||||
],
|
||||
completed: [],
|
||||
history: [],
|
||||
};
|
||||
const result = resolveConversationProcessingFromUnified([], embedded);
|
||||
expect(result).not.toBeNull();
|
||||
// waiting_human 任务从 processing 组迁入 needs_action
|
||||
expect(result!.processing.length).toBe(0);
|
||||
expect(result!.needs_action.length).toBe(1);
|
||||
expect(result!.needs_action[0]!.status_label).toBe('waiting_review');
|
||||
expect(result!.needs_action[0]!.title).toBe('b.pdf');
|
||||
});
|
||||
|
||||
it('resolveConversationProcessingFromUnified: work_items 仅含 order_intake 时,仍走 embedded normalize 路径(过渡窗口不跳状态)', () => {
|
||||
const embedded: ConversationProcessingProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||||
focused_task_no: 'OT-LEG3',
|
||||
recent_task_no: 'OT-LEG3',
|
||||
needs_action: [],
|
||||
processing: [
|
||||
{
|
||||
user_task_no: 'OT-LEG3',
|
||||
user_task_authoritative: false,
|
||||
title: 'c.pdf',
|
||||
display_kind: 'single_document_task',
|
||||
document_names: ['c.pdf'],
|
||||
group: 'processing',
|
||||
status_label: 'waiting_human',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-LEG3',
|
||||
can_append: false,
|
||||
available_actions: ['enter_manual_review'],
|
||||
primary_action: 'enter_manual_review',
|
||||
},
|
||||
],
|
||||
completed: [],
|
||||
history: [],
|
||||
};
|
||||
const workItems: ShippingProcessingProjection[] = [
|
||||
{
|
||||
workItemType: 'order_intake',
|
||||
workItemNo: 'SNI-1',
|
||||
sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: null,
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
submissionNo: 'SOS-1',
|
||||
intakeNo: 'SNI-1',
|
||||
status: 'processing',
|
||||
stage: 'building_order',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-06T00:00:00Z',
|
||||
currentGate: null,
|
||||
availableActions: [],
|
||||
sourceSummary: {
|
||||
emailSubject: null,
|
||||
filename: 'c.pdf',
|
||||
documentCount: 1,
|
||||
parsedDocumentCount: 0,
|
||||
candidateCount: 0,
|
||||
customerName: null,
|
||||
poNumber: null,
|
||||
},
|
||||
childOrderTasks: [],
|
||||
},
|
||||
];
|
||||
const result = resolveConversationProcessingFromUnified(workItems, embedded);
|
||||
expect(result).not.toBeNull();
|
||||
// 过渡阶段:order_intake 不触发统一投影派生;embedded waiting_human 必须 normalize 成 waiting_review/needs_action
|
||||
expect(result!.focused_task_no).toBe('OT-LEG3');
|
||||
expect(result!.processing.length).toBe(0);
|
||||
expect(result!.needs_action.length).toBe(1);
|
||||
expect(result!.needs_action[0]!.status_label).toBe('waiting_review');
|
||||
expect(result!.needs_action[0]!.title).toBe('c.pdf');
|
||||
expect(result!.needs_action[0]!.group).toBe('needs_action');
|
||||
});
|
||||
|
||||
it('resolveConversationProcessingFromUnified + IntakeOtStabilizer: 看到 order_task 后 2s 内暂缺 OT 保持 previousProjection(避免轮询抖动)', () => {
|
||||
const stabilizer = createIntakeOtStabilizer();
|
||||
const embedded: ConversationProcessingProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
focused_task_no: null,
|
||||
recent_task_no: null,
|
||||
needs_action: [
|
||||
{
|
||||
user_task_no: 'OT-LG',
|
||||
user_task_authoritative: false,
|
||||
title: 'fallback.pdf',
|
||||
display_kind: 'single_document_task',
|
||||
document_names: ['fallback.pdf'],
|
||||
group: 'needs_action',
|
||||
status_label: 'waiting_human',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-LG',
|
||||
can_append: false,
|
||||
available_actions: [],
|
||||
primary_action: 'enter_manual_review',
|
||||
},
|
||||
],
|
||||
processing: [],
|
||||
completed: [],
|
||||
history: [],
|
||||
};
|
||||
const intakeOnly: ShippingProcessingProjection[] = [
|
||||
{
|
||||
workItemType: 'order_intake',
|
||||
workItemNo: 'SNI-1',
|
||||
sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: null,
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
submissionNo: 'SOS-1',
|
||||
intakeNo: 'SNI-1',
|
||||
status: 'processing',
|
||||
stage: 'building_order',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-06T00:00:00Z',
|
||||
currentGate: null,
|
||||
availableActions: [],
|
||||
sourceSummary: { filename: 'a.pdf', documentCount: 1 },
|
||||
childOrderTasks: [],
|
||||
},
|
||||
];
|
||||
const withOrderTask: ShippingProcessingProjection[] = [
|
||||
{
|
||||
workItemType: 'order_task',
|
||||
workItemNo: 'OT-NEW',
|
||||
sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: 'OT-NEW',
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
runNo: 'RUN-NEW',
|
||||
caseNo: 'CASE-NEW',
|
||||
submissionNo: 'SOS-1',
|
||||
intakeNo: 'SNI-1',
|
||||
userStatus: 'waiting_review',
|
||||
status: 'waiting_review',
|
||||
stage: 'waiting_human_review',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-06T00:00:01Z',
|
||||
primaryAction: { code: 'open_order_review', i18nKey: 'chat.shippingProcessing.action.open_order_review' },
|
||||
currentGate: null,
|
||||
availableActions: ['open_order_review', 'cancel_task'],
|
||||
sourceSummary: { filename: 'a.pdf', documentCount: 1 },
|
||||
},
|
||||
];
|
||||
// Step 1: 初始只有 intake,还没见过 OT → 走 embedded normalize
|
||||
const step1 = resolveConversationProcessingFromUnified(
|
||||
intakeOnly,
|
||||
embedded,
|
||||
null,
|
||||
{ conversationId: 'conv-1', ...stabilizer },
|
||||
);
|
||||
expect(step1!.needs_action[0]!.title).toBe('fallback.pdf');
|
||||
expect(step1!.needs_action[0]!.status_label).toBe('waiting_review');
|
||||
|
||||
// Step 2: 第一轮看到 OT → derived 生成,同时 markSeen
|
||||
const step2 = resolveConversationProcessingFromUnified(
|
||||
withOrderTask,
|
||||
embedded,
|
||||
step1,
|
||||
{ conversationId: 'conv-1', ...stabilizer },
|
||||
);
|
||||
expect(step2!.needs_action[0]!.user_task_no).toBe('OT-NEW');
|
||||
expect(step2!.needs_action[0]!.status_label).toBe('waiting_review');
|
||||
|
||||
// Step 3: 下一次轮询只有 intake(本次响应暂缺 OT)→ 保持 previousProjection,不抖回 embedded
|
||||
const step3 = resolveConversationProcessingFromUnified(
|
||||
intakeOnly,
|
||||
embedded,
|
||||
step2,
|
||||
{ conversationId: 'conv-1', ...stabilizer },
|
||||
);
|
||||
expect(step3).toBe(step2);
|
||||
|
||||
// Step 4: 用户点刷新 reset 后,允许走 embedded(业务认为需要重新建立稳定态)
|
||||
stabilizer.reset('conv-1');
|
||||
const step4 = resolveConversationProcessingFromUnified(
|
||||
intakeOnly,
|
||||
embedded,
|
||||
step2,
|
||||
{ conversationId: 'conv-1', ...stabilizer },
|
||||
);
|
||||
expect(step4!.needs_action[0]!.title).toBe('fallback.pdf');
|
||||
expect(step4!.needs_action[0]!.status_label).toBe('waiting_review');
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,9 @@ import type {
|
||||
ConversationProcessingSummary,
|
||||
ConversationProcessingTaskGroup,
|
||||
ConversationProcessingUserTask,
|
||||
ShippingProcessingBlockingReason,
|
||||
ShippingProcessingFacts,
|
||||
ShippingProcessingPrimaryAction,
|
||||
ShippingProcessingProjection,
|
||||
ShippingWorkflowItem,
|
||||
WorkflowNodeStatus,
|
||||
@@ -46,22 +49,36 @@ export function buildTaskSemanticKey(
|
||||
task: ConversationProcessingUserTask | null | undefined,
|
||||
): string {
|
||||
if (!task) return '';
|
||||
const rawStatus = (task as ConversationProcessingUserTask & { userStatus?: string | null }).userStatus ?? task.status_label;
|
||||
return JSON.stringify({
|
||||
taskNo: task.user_task_no,
|
||||
group: task.group,
|
||||
status: task.status_label,
|
||||
status: normalizeLifecycleStatus(rawStatus),
|
||||
runNo: task.run_no,
|
||||
displayKind: task.display_kind,
|
||||
fileCount: task.file_count,
|
||||
title: task.title,
|
||||
primaryAction: task.primary_action || null,
|
||||
currentGate: (task as ConversationProcessingUserTask & { current_gate?: { blockingReasonCode?: string; nextActionCode?: string } })
|
||||
primaryAction: (task as ConversationProcessingUserTask & { primaryAction?: { code?: string } | null }).primaryAction?.code
|
||||
?? task.primary_action
|
||||
?? null,
|
||||
currentGate: (task as ConversationProcessingUserTask & {
|
||||
current_gate?: { blockingReasonCode?: string; nextActionCode?: string };
|
||||
blockingReason?: { code?: string } | null;
|
||||
})
|
||||
.current_gate
|
||||
? {
|
||||
blockingReasonCode: (task as ConversationProcessingUserTask & { current_gate?: { blockingReasonCode?: string; nextActionCode?: string } })
|
||||
.current_gate?.blockingReasonCode || null,
|
||||
nextActionCode: (task as ConversationProcessingUserTask & { current_gate?: { blockingReasonCode?: string; nextActionCode?: string } })
|
||||
.current_gate?.nextActionCode || null,
|
||||
blockingReasonCode: (task as ConversationProcessingUserTask & {
|
||||
current_gate?: { blockingReasonCode?: string; nextActionCode?: string };
|
||||
})
|
||||
.current_gate?.blockingReasonCode
|
||||
?? (task as ConversationProcessingUserTask & { blockingReason?: { code?: string } | null }).blockingReason?.code
|
||||
?? null,
|
||||
nextActionCode: (task as ConversationProcessingUserTask & {
|
||||
current_gate?: { blockingReasonCode?: string; nextActionCode?: string };
|
||||
})
|
||||
.current_gate?.nextActionCode
|
||||
?? (task as ConversationProcessingUserTask & { primaryAction?: { code?: string } | null }).primaryAction?.code
|
||||
?? null,
|
||||
}
|
||||
: null,
|
||||
availableActions: normalizeActionCodes(task.available_actions || []),
|
||||
@@ -125,6 +142,7 @@ export function stabilizeTaskObjects(
|
||||
const NEEDS_ACTION_LIFECYCLES = new Set([
|
||||
'blocked',
|
||||
'waiting_review',
|
||||
'waiting_human',
|
||||
'pending_review',
|
||||
'manual_upload_pending',
|
||||
'failed',
|
||||
@@ -132,6 +150,75 @@ const NEEDS_ACTION_LIFECYCLES = new Set([
|
||||
'upload_rpa_failed',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Intake / OT 过渡稳定器。
|
||||
* 用途:后端 Intake 与 ShippingOrderTask 往往不在同一事务窗出现。
|
||||
* 一旦看到过 order_task 后,接下来 2 秒内即便 work_items 里没有 order_task,
|
||||
* 也不立即回退 embedded,避免轮询刷新在「待复核 ⇄ 待复核(兼容态」之间
|
||||
* 跳变,实际上是 OT 还没在本次响应里出现,下一轮就有。
|
||||
*/
|
||||
export interface IntakeOtStabilizer {
|
||||
/** 注入「此会话是否已经至少出现过一次 order_task」。 */
|
||||
hasSeenOrderTaskBefore(conversationId?: string | null): boolean;
|
||||
/** 当且仅当 work_items 里确实有 order_task 时调用,记录“见过 OT 并更新时间戳。 */
|
||||
markSeen(conversationId?: string | null): void;
|
||||
/** 手动刷新/重载/离开页面重进时清空时间戳,允许回到 embedded 兼容态。 */
|
||||
reset(conversationId?: string | null): void;
|
||||
}
|
||||
|
||||
export function createIntakeOtStabilizer(options?: { graceMs?: number }): IntakeOtStabilizer {
|
||||
const graceMs = Number(options?.graceMs ?? 2000);
|
||||
const seen = new Map<string, number>();
|
||||
const global: { ts: number | null } = { ts: null };
|
||||
function getNow() {
|
||||
return Date.now();
|
||||
}
|
||||
return {
|
||||
hasSeenOrderTaskBefore(conversationId?: string | null): boolean {
|
||||
const now = getNow();
|
||||
if (conversationId) {
|
||||
const ts = seen.get(conversationId);
|
||||
if (typeof ts === 'number' && now - ts <= graceMs) return true;
|
||||
}
|
||||
const gts = global.ts;
|
||||
if (typeof gts === 'number' && now - gts <= graceMs) return true;
|
||||
return false;
|
||||
},
|
||||
markSeen(conversationId?: string | null): void {
|
||||
const now = getNow();
|
||||
global.ts = now;
|
||||
if (conversationId) seen.set(conversationId, now);
|
||||
},
|
||||
reset(conversationId?: string | null): void {
|
||||
global.ts = null;
|
||||
if (conversationId) seen.delete(conversationId);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化生命周期状态:把旧/兼容形态统一映射为新的单一状态。
|
||||
* 核心逻辑:waiting_human(旧 conversation_processing 兜底)一律归并为
|
||||
* waiting_review(新统一投影);pending_review 收敛到 waiting_review;
|
||||
* 其它保持原值。用于避免两套投影切换时造成状态文本闪烁、语义签名漂移。
|
||||
* @param status - 原始 lifecycle / userStatus / status_label
|
||||
* @returns 归一化后的生命周期状态码
|
||||
*/
|
||||
export function normalizeLifecycleStatus(
|
||||
status: string | null | undefined,
|
||||
): string {
|
||||
const raw = String(status || '').trim().toLowerCase();
|
||||
if (!raw) return '';
|
||||
// [LEGACY-UNIFY] 旧兼容状态一律收敛为 waiting_review,保证显示「待复核」而非 waiting human。
|
||||
if (raw === 'waiting_human' || raw === 'pending_review' || raw === 'review_required') {
|
||||
return 'waiting_review';
|
||||
}
|
||||
if (raw === 'partially_completed') return 'waiting_review';
|
||||
if (raw === 'manual_upload' || raw === 'waiting_manual_upload') return 'manual_upload_pending';
|
||||
if (raw === 'retryable') return 'failed';
|
||||
return raw;
|
||||
}
|
||||
|
||||
const HUMAN_ACTION_CODES = new Set([
|
||||
'confirm_customer', 'resolve_field_conflicts', 'adjudicate_duplicate',
|
||||
'open_order_review', 'open_order_processing', 'enter_manual_review',
|
||||
@@ -403,14 +490,11 @@ export function classifyConversationProcessingGroup(
|
||||
options?: { hasBlockingGate?: boolean; needsCustomerConfirm?: boolean },
|
||||
): ConversationProcessingTaskGroup {
|
||||
if (options?.needsCustomerConfirm) return 'needs_action';
|
||||
const normalized = String(status || '').trim();
|
||||
const normalized = normalizeLifecycleStatus(status);
|
||||
if (NEEDS_ACTION_LIFECYCLES.has(normalized)) return 'needs_action';
|
||||
if (COMPLETED_LIFECYCLES.has(normalized)) return 'completed';
|
||||
if (HISTORY_LIFECYCLES.has(normalized)) return 'history';
|
||||
if (PROCESSING_LIFECYCLES.has(normalized)) return 'processing';
|
||||
if (normalized === 'review_required' || normalized === 'partially_completed') {
|
||||
return 'needs_action';
|
||||
}
|
||||
if (normalized === 'failed') return 'needs_action';
|
||||
if (normalized === 'completed') return 'completed';
|
||||
if (normalized === 'processing' || normalized === 'queued') return 'processing';
|
||||
@@ -433,7 +517,8 @@ function fallbackTaskIdentityKey(item: ShippingWorkflowItem): string {
|
||||
if (filename) return `fn:${filename}`;
|
||||
const runNo = String(item.current_run_no || '').trim();
|
||||
if (runNo) return `run:${runNo}`;
|
||||
return `item:${String(item.item_no || '').trim()}`;
|
||||
const itemNo = String(item.item_no || '').trim();
|
||||
return `item:${itemNo}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,7 +629,7 @@ export function projectConversationProcessingTasks(
|
||||
const uniqueDocuments = dedupeFallbackDocuments(groupItems);
|
||||
const effectiveItems = uniqueDocuments.map((row) => row.source_item);
|
||||
// 任务级分组/操作只由最近代表 Item 决定;旧 Run 仅贡献未受影响的 PDF,不得反向污染状态。
|
||||
const statuses = [resolveItemDisplayStatus(primaryItem)];
|
||||
const statuses = [normalizeLifecycleStatus(resolveItemDisplayStatus(primaryItem))];
|
||||
const primaryActions = Array.isArray(primaryItem.available_actions)
|
||||
? primaryItem.available_actions
|
||||
: [];
|
||||
@@ -706,8 +791,8 @@ export function groupConversationProcessingTasks(
|
||||
export function mapShippingProcessingStatusToTaskGroup(
|
||||
item: ShippingProcessingProjection,
|
||||
): ConversationProcessingTaskGroup {
|
||||
const status = String(item.status || '').trim().toLowerCase();
|
||||
const gateAction = String(item.currentGate?.nextActionCode || '').trim().toLowerCase();
|
||||
const status = String(item.userStatus ?? item.status ?? '').trim().toLowerCase();
|
||||
const gateAction = String(item.primaryAction?.code ?? item.currentGate?.nextActionCode ?? '').trim().toLowerCase();
|
||||
const hasHumanAction = [gateAction, ...(item.availableActions || [])]
|
||||
.map((value) => String(value || '').trim().toLowerCase())
|
||||
.some((value) => HUMAN_ACTION_CODES.has(value) || value.startsWith('retry_failed_'));
|
||||
@@ -715,6 +800,8 @@ export function mapShippingProcessingStatusToTaskGroup(
|
||||
status === 'waiting_review'
|
||||
|| status === 'blocked'
|
||||
|| status === 'failed'
|
||||
|| status === 'waiting_human'
|
||||
|| status === 'retryable'
|
||||
|| hasHumanAction
|
||||
) {
|
||||
return 'needs_action';
|
||||
@@ -737,7 +824,9 @@ export function mergeConversationProcessingFocusMetadata(
|
||||
embedded: ConversationProcessingProjection | null | undefined,
|
||||
): ConversationProcessingProjection | null {
|
||||
if (!derived) {
|
||||
return embedded && typeof embedded === 'object' ? embedded : null;
|
||||
return embedded && typeof embedded === 'object'
|
||||
? normalizeConversationProcessingProjection(embedded)
|
||||
: null;
|
||||
}
|
||||
if (!embedded || typeof embedded !== 'object') return derived;
|
||||
return {
|
||||
@@ -762,18 +851,99 @@ export function resolveConversationProcessingFromUnified(
|
||||
workItems: ShippingProcessingProjection[] | null | undefined,
|
||||
embedded: ConversationProcessingProjection | null | undefined,
|
||||
previousProjection?: ConversationProcessingProjection | null,
|
||||
stabilizer?: { hasSeenOrderTaskBefore?(conversationId?: string | null): boolean; markSeen?(conversationId?: string | null): void; reset?(conversationId?: string | null): void; conversationId?: string | null },
|
||||
): ConversationProcessingProjection | null {
|
||||
const items = Array.isArray(workItems) ? workItems : [];
|
||||
if (items.length > 0) {
|
||||
// [TRANSITION] 只有统一投影里明确存在 order_task,才认为 OT 维度已经成形。
|
||||
// 仅 order_intake 存在时视为过渡阶段:
|
||||
// - 如果此会话/全局在此之前已见到过 order_task(2s 窗口内),
|
||||
// 则延迟回退 embedded,保持 previousProjection 不变,避免闪烁;
|
||||
// - 否则仍走 embedded,但强制 normalize 成 waiting_review。
|
||||
const hasOrderTask = items.some((item) => item.workItemType === 'order_task');
|
||||
const convId = stabilizer?.conversationId;
|
||||
if (hasOrderTask) {
|
||||
stabilizer?.markSeen?.(convId);
|
||||
return mergeConversationProcessingFocusMetadata(
|
||||
projectConversationProcessingFromWorkItems(items, previousProjection),
|
||||
embedded,
|
||||
);
|
||||
}
|
||||
if (embedded && typeof embedded === 'object') return embedded;
|
||||
const sawOrderTaskRecently = stabilizer?.hasSeenOrderTaskBefore?.(convId) === true;
|
||||
if (sawOrderTaskRecently && previousProjection) {
|
||||
// 刚刚看到过 OT 但这轮响应暂缺 OT:不立即切回 embedded,保持上一轮投影。
|
||||
// 这样 2s 内轮询不会把右侧任务卡从 order_task 派生结果抖回旧 projection。
|
||||
return previousProjection;
|
||||
}
|
||||
if (embedded && typeof embedded === 'object') {
|
||||
return normalizeConversationProcessingProjection(embedded);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化旧 conversation_processing 投影的生命周期状态。
|
||||
* 核心逻辑:将所有组的 userStatus/status_label 统一为新形态,waiting_human 归并为 waiting_review,
|
||||
* 避免 work_items 为空回退时,旧投影状态与统一 work_items 状态来回切换造成文案闪烁。
|
||||
*
|
||||
* @param projection - 原始 embedded conversation_processing 投影
|
||||
* @returns 归一化后的投影(新对象,浅拷贝 tasks 并覆盖 userStatus/status_label)
|
||||
*/
|
||||
export function normalizeConversationProcessingProjection(
|
||||
projection: ConversationProcessingProjection,
|
||||
): ConversationProcessingProjection {
|
||||
const normalizeTask = (task: ConversationProcessingUserTask): ConversationProcessingUserTask => {
|
||||
const rawStatus = task.userStatus ?? task.status_label;
|
||||
const normalizedStatus = normalizeLifecycleStatus(rawStatus);
|
||||
const availableActions = Array.isArray(task.available_actions) ? task.available_actions : [];
|
||||
const hasHumanAction = availableActions.some((value) => {
|
||||
const code = String(value || '').trim().toLowerCase();
|
||||
return HUMAN_ACTION_CODES.has(code) || code.startsWith('retry_failed_');
|
||||
});
|
||||
const recomputedGroup = classifyConversationProcessingGroup(normalizedStatus || rawStatus, {
|
||||
needsCustomerConfirm: hasHumanAction,
|
||||
});
|
||||
const finalGroup: ConversationProcessingTaskGroup = (() => {
|
||||
// [LEGACY-UNIFY] waiting_human 旧投影若被归在 processing / history,强制迁入 needs_action。
|
||||
if (recomputedGroup === 'needs_action') return 'needs_action';
|
||||
if (normalizedStatus === 'waiting_review') return 'needs_action';
|
||||
return task.group || recomputedGroup;
|
||||
})();
|
||||
return {
|
||||
...task,
|
||||
status_label: normalizedStatus || (task.status_label ?? ''),
|
||||
// userStatus 保持原有强类型;会话侧展示统一走 status_label/group,避免放宽成 string 破坏类型契约。
|
||||
userStatus: task.userStatus ?? null,
|
||||
group: finalGroup,
|
||||
};
|
||||
};
|
||||
const normalizedAll = [
|
||||
...(projection.needs_action || []),
|
||||
...(projection.processing || []),
|
||||
...(projection.completed || []),
|
||||
...(projection.history || []),
|
||||
].map(normalizeTask);
|
||||
const needs_action = normalizedAll.filter((task) => task.group === 'needs_action');
|
||||
const processing = normalizedAll.filter((task) => task.group === 'processing');
|
||||
const completed = normalizedAll.filter((task) => task.group === 'completed');
|
||||
const history = normalizedAll.filter((task) => task.group === 'history');
|
||||
return {
|
||||
...projection,
|
||||
summary: {
|
||||
...(projection.summary || {}),
|
||||
total_tasks: normalizedAll.length,
|
||||
total_files: normalizedAll.reduce((sum, task) => sum + Number(task.file_count || 0), 0),
|
||||
needs_action: needs_action.length,
|
||||
processing: processing.length,
|
||||
completed: completed.length,
|
||||
history: history.length,
|
||||
},
|
||||
needs_action,
|
||||
processing,
|
||||
completed,
|
||||
history,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从统一 work_items 合成 ConversationProcessingProjection(仅 order_task)。
|
||||
*
|
||||
@@ -801,7 +971,39 @@ export function projectConversationProcessingFromWorkItems(
|
||||
const docCount = Number(item.sourceSummary?.documentCount || 0);
|
||||
const filename = String(item.sourceSummary?.filename || '').trim();
|
||||
const normalizedActions = normalizeActionCodes(item.availableActions || []);
|
||||
const gateNextAction = String(item.currentGate?.nextActionCode || '').trim().toLowerCase() || null;
|
||||
const gateNextAction = String(item.primaryAction?.code ?? item.currentGate?.nextActionCode ?? '').trim().toLowerCase() || null;
|
||||
const effectiveStatus = normalizeLifecycleStatus(String(item.userStatus ?? item.status ?? '').trim()) || null;
|
||||
const userBlocking: ConversationProcessingUserTask['blockingReason'] = (item.blockingReason && typeof item.blockingReason === 'object')
|
||||
? {
|
||||
code: item.blockingReason.code,
|
||||
i18nKey: (item.blockingReason as { i18nKey?: string | null }).i18nKey
|
||||
?? (item.blockingReason as { i18n_key?: string | null }).i18n_key
|
||||
?? undefined,
|
||||
details: (item.blockingReason as { details?: Record<string, unknown> }).details,
|
||||
} satisfies ShippingProcessingBlockingReason
|
||||
: null;
|
||||
const userPrimaryAction: ConversationProcessingUserTask['primaryAction'] = item.primaryAction
|
||||
? {
|
||||
code: item.primaryAction.code,
|
||||
i18nKey: (item.primaryAction as { i18nKey?: string | null }).i18nKey
|
||||
?? (item.primaryAction as { i18n_key?: string | null }).i18n_key
|
||||
?? undefined,
|
||||
parameters: (item.primaryAction as { parameters?: Record<string, unknown> }).parameters,
|
||||
} satisfies ShippingProcessingPrimaryAction
|
||||
: null;
|
||||
const userFacts: ConversationProcessingUserTask['facts'] = item.facts
|
||||
? {
|
||||
inventorySourceStatus: (item.facts as { inventorySourceStatus?: string | null }).inventorySourceStatus ?? undefined,
|
||||
candidateSourceCodes: (item.facts as { candidateSourceCodes?: string[] }).candidateSourceCodes ?? [],
|
||||
preparedSourceCodes: (item.facts as { preparedSourceCodes?: string[] }).preparedSourceCodes ?? [],
|
||||
pendingSourceCodes: (item.facts as { pendingSourceCodes?: string[] }).pendingSourceCodes ?? [],
|
||||
lineResolutions: (item.facts as { lineResolutions?: Record<string, unknown>[] }).lineResolutions ?? undefined,
|
||||
exportState: (item.facts as { exportState?: string }).exportState ?? undefined,
|
||||
uploadState: (item.facts as { uploadState?: string }).uploadState ?? undefined,
|
||||
switchState: (item.facts as { switchState?: string }).switchState ?? undefined,
|
||||
forcedMatchSourceCode: (item.facts as { forcedMatchSourceCode?: string | null }).forcedMatchSourceCode ?? undefined,
|
||||
} satisfies ShippingProcessingFacts
|
||||
: undefined;
|
||||
const task: ConversationProcessingUserTask = {
|
||||
user_task_no: taskNo,
|
||||
user_task_authoritative: true,
|
||||
@@ -809,13 +1011,21 @@ export function projectConversationProcessingFromWorkItems(
|
||||
display_kind: docCount > 1 ? 'multi_document_task' : 'single_document_task',
|
||||
document_names: filename ? [filename] : [],
|
||||
group,
|
||||
status_label: String(item.status || '') || null,
|
||||
status_label: effectiveStatus,
|
||||
file_count: docCount > 0 ? docCount : (filename ? 1 : 0),
|
||||
run_no: String(item.runNo || '').trim() || null,
|
||||
can_append: false,
|
||||
last_activity_at: item.lastActivityAt || null,
|
||||
available_actions: normalizedActions,
|
||||
primary_action: gateNextAction || normalizedActions[0] || null,
|
||||
userStatus: item.userStatus ?? null,
|
||||
blockingReason: userBlocking,
|
||||
primaryAction: userPrimaryAction,
|
||||
facts: userFacts,
|
||||
retryable: typeof item.retryable === 'boolean' ? item.retryable : false,
|
||||
userCurrentGateCode: item.userCurrentGateCode ?? null,
|
||||
legacyStatus: item.legacyStatus ?? null,
|
||||
legacyStage: item.legacyStage ?? null,
|
||||
};
|
||||
rawTasks.push(task);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,51 @@ describe('normalizeShippingProcessingProjection', () => {
|
||||
expect(normalized?.stageNodes?.[1]?.absoluteIndex).toBe(2);
|
||||
});
|
||||
|
||||
it('normalizes structured inventory candidate facts', () => {
|
||||
const projection = normalizeShippingProcessingProjection({
|
||||
work_item_no: 'SN-001',
|
||||
work_item_type: 'order_task',
|
||||
source_type: 'eml',
|
||||
submission_no: 'SUB-1',
|
||||
intake_no: 'INT-1',
|
||||
status: 'processing',
|
||||
stage: 'inventory_matching',
|
||||
progress_version: 2,
|
||||
last_activity_at: '2026-08-08T22:00:00',
|
||||
source_summary: {},
|
||||
available_actions: [],
|
||||
child_order_tasks: [],
|
||||
blocking_reason: {
|
||||
code: 'inventory_candidates_missing',
|
||||
i18n_key: 'workspace.shippingNotice.processGate.reasons.inventory_candidates_missing',
|
||||
},
|
||||
facts: {
|
||||
candidate_set_id: 12,
|
||||
candidate_set_version: 3,
|
||||
candidate_set_status: 'frozen',
|
||||
candidate_source_codes: ['DBS_DUB'],
|
||||
prepared_source_codes: ['DBS_DUB'],
|
||||
pending_source_codes: ['DBS_RTM'],
|
||||
failed_source_codes: ['DBS_SIN'],
|
||||
source_attempts: {
|
||||
DBS_DUB: { status: 'consumed', attempt_no: 1 },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(projection?.facts?.candidateSetId).toBe(12);
|
||||
expect(projection?.facts?.candidateSetVersion).toBe(3);
|
||||
expect(projection?.facts?.candidateSetStatus).toBe('frozen');
|
||||
expect(projection?.facts?.candidateSourceCodes).toEqual(['DBS_DUB']);
|
||||
expect(projection?.facts?.preparedSourceCodes).toEqual(['DBS_DUB']);
|
||||
expect(projection?.facts?.pendingSourceCodes).toEqual(['DBS_RTM']);
|
||||
expect(projection?.facts?.failedSourceCodes).toEqual(['DBS_SIN']);
|
||||
expect(projection?.facts?.sourceAttempts).toEqual({
|
||||
DBS_DUB: { status: 'consumed', attempt_no: 1 },
|
||||
});
|
||||
expect(projection?.blockingReason?.code).toBe('inventory_candidates_missing');
|
||||
});
|
||||
|
||||
it('returns null when work_item_no missing', () => {
|
||||
expect(normalizeShippingProcessingProjection({ status: 'processing' })).toBeNull();
|
||||
});
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
import type {
|
||||
OrderIntakeSourceType,
|
||||
ProcessGateSummary,
|
||||
ShippingInventoryPerSourceAttempt,
|
||||
ShippingInventoryPreparationSummary,
|
||||
ShippingOrderTaskSummary,
|
||||
ShippingProcessingBlockingReason,
|
||||
ShippingProcessingFacts,
|
||||
ShippingProcessingPrimaryAction,
|
||||
ShippingProcessingProjection,
|
||||
ShippingProcessingStage,
|
||||
ShippingProcessingStageNode,
|
||||
@@ -98,6 +103,186 @@ function normalizeStageNode(raw: unknown): ShippingProcessingStageNode | null {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [T9 用户态 Projection] 规范 blocking_reason(后端 snake_case {code, i18n_key, details})。
|
||||
*/
|
||||
function normalizeBlockingReason(raw: unknown): ShippingProcessingBlockingReason | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const code = String(item.code ?? '').trim();
|
||||
if (!code) return null;
|
||||
return {
|
||||
code,
|
||||
i18nKey: item.i18n_key != null ? String(item.i18n_key) : (item.i18nKey != null ? String(item.i18nKey) : null),
|
||||
details:
|
||||
typeof item.details === 'object' && item.details != null
|
||||
? (item.details as Record<string, unknown>)
|
||||
: {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [T9 用户态 Projection] 规范 primary_action(后端 snake_case {code, i18n_key, parameters})。
|
||||
*/
|
||||
function normalizePrimaryAction(raw: unknown): ShippingProcessingPrimaryAction | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const code = String(item.code ?? '').trim();
|
||||
if (!code) return null;
|
||||
return {
|
||||
code,
|
||||
i18nKey: item.i18n_key != null ? String(item.i18n_key) : (item.i18nKey != null ? String(item.i18nKey) : null),
|
||||
parameters:
|
||||
typeof item.parameters === 'object' && item.parameters != null
|
||||
? (item.parameters as Record<string, unknown>)
|
||||
: {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [T9 用户态 Projection] 规范 facts(后端 snake_case 子状态字典;camelCase key)。
|
||||
*/
|
||||
function normalizeFacts(raw: unknown): ShippingProcessingFacts | undefined {
|
||||
if (!raw || typeof raw !== 'object') return undefined;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const toStrArr = (value: unknown): string[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.map((c) => String(c ?? '').trim()).filter(Boolean);
|
||||
};
|
||||
const toLineArr = (value: unknown): Record<string, unknown>[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.filter((row): row is Record<string, unknown> => Boolean(row) && typeof row === 'object');
|
||||
};
|
||||
const out: ShippingProcessingFacts = {};
|
||||
if ('inventory_source_status' in item || 'inventorySourceStatus' in item) {
|
||||
out.inventorySourceStatus =
|
||||
item.inventory_source_status != null
|
||||
? String(item.inventory_source_status)
|
||||
: item.inventorySourceStatus != null
|
||||
? String(item.inventorySourceStatus)
|
||||
: null;
|
||||
}
|
||||
if ('candidate_set_id' in item || 'candidateSetId' in item) {
|
||||
const v = item.candidate_set_id ?? item.candidateSetId;
|
||||
out.candidateSetId = v == null || v === '' ? null : Number(v);
|
||||
}
|
||||
if ('candidate_set_version' in item || 'candidateSetVersion' in item) {
|
||||
const v = item.candidate_set_version ?? item.candidateSetVersion;
|
||||
out.candidateSetVersion = v == null || v === '' ? null : Number(v);
|
||||
}
|
||||
if ('candidate_set_status' in item || 'candidateSetStatus' in item) {
|
||||
const v = item.candidate_set_status ?? item.candidateSetStatus;
|
||||
out.candidateSetStatus = v == null || v === '' ? null : String(v) as ShippingProcessingFacts['candidateSetStatus'];
|
||||
}
|
||||
if ('candidate_source_codes' in item || 'candidateSourceCodes' in item) {
|
||||
out.candidateSourceCodes = toStrArr(item.candidate_source_codes ?? item.candidateSourceCodes);
|
||||
}
|
||||
if ('prepared_source_codes' in item || 'preparedSourceCodes' in item) {
|
||||
out.preparedSourceCodes = toStrArr(item.prepared_source_codes ?? item.preparedSourceCodes);
|
||||
}
|
||||
if ('pending_source_codes' in item || 'pendingSourceCodes' in item) {
|
||||
out.pendingSourceCodes = toStrArr(item.pending_source_codes ?? item.pendingSourceCodes);
|
||||
}
|
||||
if ('failed_source_codes' in item || 'failedSourceCodes' in item) {
|
||||
out.failedSourceCodes = toStrArr(item.failed_source_codes ?? item.failedSourceCodes);
|
||||
}
|
||||
if ('source_attempts' in item || 'sourceAttempts' in item) {
|
||||
const v = item.source_attempts ?? item.sourceAttempts;
|
||||
out.sourceAttempts = typeof v === 'object' && v != null ? v as Record<string, unknown> : {};
|
||||
}
|
||||
if ('line_resolutions' in item || 'lineResolutions' in item) {
|
||||
out.lineResolutions = toLineArr(item.line_resolutions ?? item.lineResolutions);
|
||||
}
|
||||
if ('export_state' in item || 'exportState' in item) {
|
||||
const v = item.export_state ?? item.exportState;
|
||||
out.exportState = v == null ? 'not_created' : String(v);
|
||||
}
|
||||
if ('upload_state' in item || 'uploadState' in item) {
|
||||
const v = item.upload_state ?? item.uploadState;
|
||||
out.uploadState = v == null ? 'not_created' : String(v);
|
||||
}
|
||||
if ('switch_state' in item || 'switchState' in item) {
|
||||
const v = item.switch_state ?? item.switchState;
|
||||
out.switchState = v == null ? 'not_triggered' : String(v);
|
||||
}
|
||||
if ('forced_match_source_code' in item || 'forcedMatchSourceCode' in item) {
|
||||
const v = item.forced_match_source_code ?? item.forcedMatchSourceCode;
|
||||
out.forcedMatchSourceCode = v == null || v === '' ? null : String(v).toUpperCase();
|
||||
}
|
||||
for (const [k, v] of Object.entries(item)) {
|
||||
if (!(k in out)) {
|
||||
out[k] = v;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 题4A:规范 inventory_preparation 结构化字段(snake_case → camelCase)。
|
||||
* 注意:failed_sources 会进一步透传到 exhausted_sources 分开(二者互斥;仅 max_attempts 耗尽的源进 exhausted)。
|
||||
*/
|
||||
function normalizeInventoryPreparation(raw: unknown): ShippingInventoryPreparationSummary | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const toStrArr = (value: unknown): string[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.map((c) => String(c ?? '').trim()).filter(Boolean);
|
||||
};
|
||||
const requiredSources = toStrArr(item.required_sources ?? item.requiredSources);
|
||||
if (!requiredSources.length) {
|
||||
// required_sources 空代表 inventory_preparation 实际尚未进入 inventory 阶段,返回 null 避免前端误判。
|
||||
return null;
|
||||
}
|
||||
const preparedSources = toStrArr(item.prepared_sources ?? item.preparedSources);
|
||||
const pendingSources = toStrArr(item.pending_sources ?? item.pendingSources);
|
||||
const failedSources = toStrArr(item.failed_sources ?? item.failedSources);
|
||||
const exhaustedSources = toStrArr(item.exhausted_sources ?? item.exhaustedSources);
|
||||
const activeAttemptCount = Number(item.active_attempt_count ?? item.activeAttemptCount ?? 0) || 0;
|
||||
const gateAttemptActive = Boolean(item.gate_attempt_active ?? item.gateAttemptActive ?? false);
|
||||
const latestRaw = (item.latest_attempts ?? item.latestAttempts) as Record<string, unknown> | undefined;
|
||||
const latestAttempts: Record<string, ShippingInventoryPerSourceAttempt> = {};
|
||||
if (latestRaw && typeof latestRaw === 'object') {
|
||||
for (const [key, val] of Object.entries(latestRaw)) {
|
||||
if (!val || typeof val !== 'object') continue;
|
||||
const row = val as Record<string, unknown>;
|
||||
const sourceCode = String(row.source_code ?? row.sourceCode ?? key ?? '').trim().toUpperCase();
|
||||
if (!sourceCode) continue;
|
||||
const attemptNo = Number(row.attempt_no ?? row.attemptNo ?? 0) || 0;
|
||||
const status = String(row.status || '').trim().toLowerCase() || 'unknown';
|
||||
const entry: ShippingInventoryPerSourceAttempt = {
|
||||
sourceCode,
|
||||
attemptNo,
|
||||
status,
|
||||
manualRetryable: (() => {
|
||||
if (row.manual_retryable != null) return Boolean(row.manual_retryable);
|
||||
if (row.manualRetryable != null) return Boolean(row.manualRetryable);
|
||||
return ['failed', 'exhausted'].includes(status);
|
||||
})(),
|
||||
message:
|
||||
(row.error_message as string | null | undefined) ??
|
||||
(row.errorMessage as string | null | undefined) ??
|
||||
(row.message as string | null | undefined) ??
|
||||
null,
|
||||
updatedAt:
|
||||
readNullableString(row, 'updated_at', 'updatedAt') ??
|
||||
readNullableString(row, 'finished_at', 'finishedAt') ??
|
||||
readNullableString(row, 'started_at', 'startedAt'),
|
||||
};
|
||||
latestAttempts[sourceCode] = entry;
|
||||
}
|
||||
}
|
||||
return {
|
||||
requiredSources,
|
||||
preparedSources,
|
||||
pendingSources,
|
||||
failedSources,
|
||||
exhaustedSources,
|
||||
activeAttemptCount,
|
||||
gateAttemptActive,
|
||||
latestAttempts: Object.keys(latestAttempts).length ? latestAttempts : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将后端 / 混合字段投影规范为 ShippingProcessingProjection。
|
||||
* 核心逻辑:缺字段给安全默认值,保证四页面可渲染;非法输入返回 null。
|
||||
@@ -160,6 +345,23 @@ export function normalizeShippingProcessingProjection(
|
||||
assetStatus: readNullableString(summaryRaw, 'asset_status', 'assetStatus'),
|
||||
},
|
||||
childOrderTasks: children,
|
||||
// [T9 用户态 Projection 7 字段] 优先读后端 user_* / blocking_reason / retryable / primary_action / facts;
|
||||
// 缺省为 null(旧后端不会下发,旧前端不读取,完全兼容)。
|
||||
userStatus: readNullableString(item, 'user_status', 'userStatus') as ShippingProcessingProjection['userStatus'],
|
||||
userStage: readNullableString(item, 'user_stage', 'userStage') as ShippingProcessingProjection['userStage'],
|
||||
userCurrentGateCode: readNullableString(item, 'user_current_gate_code', 'userCurrentGateCode'),
|
||||
blockingReason: normalizeBlockingReason(item.blocking_reason ?? item.blockingReason),
|
||||
retryable:
|
||||
(item.retryable as boolean | undefined) == null ? false : Boolean(item.retryable),
|
||||
primaryAction: normalizePrimaryAction(item.primary_action ?? item.primaryAction),
|
||||
facts: normalizeFacts(item.facts),
|
||||
legacyStatus: readNullableString(item, 'legacy_status', 'legacyStatus'),
|
||||
legacyStage: readNullableString(item, 'legacy_stage', 'legacyStage'),
|
||||
hasFormalOt:
|
||||
(item.has_formal_ot as boolean | undefined) == null ? false : Boolean(item.has_formal_ot),
|
||||
inventoryPreparation: normalizeInventoryPreparation(
|
||||
item.inventory_preparation ?? item.inventoryPreparation,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,39 @@ function buildUnifiedProcessing(conversationId = 'conv-1') {
|
||||
};
|
||||
}
|
||||
|
||||
function buildOrderTaskWorkItem(
|
||||
taskNo = 'OT-conv-1',
|
||||
patch: Record<string, unknown> = {},
|
||||
) {
|
||||
return {
|
||||
workItemType: 'order_task',
|
||||
workItemNo: taskNo,
|
||||
sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: taskNo,
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
submissionNo: 'SOS-1',
|
||||
intakeNo: 'SNI-1',
|
||||
status: 'processing',
|
||||
stage: 'document_parsing',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-05T00:00:00Z',
|
||||
currentGate: null,
|
||||
availableActions: [],
|
||||
sourceSummary: {
|
||||
emailSubject: null,
|
||||
filename: 'po.pdf',
|
||||
documentCount: 1,
|
||||
parsedDocumentCount: 1,
|
||||
candidateCount: 1,
|
||||
customerName: null,
|
||||
poNumber: 'PO-1',
|
||||
},
|
||||
childOrderTasks: [],
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建可手动完成的 Promise。
|
||||
*/
|
||||
@@ -182,36 +215,16 @@ describe('useShippingNoticeWorkflow', () => {
|
||||
it('uses unified work_items as the sole processing read source', async () => {
|
||||
api.getShippingProcessing.mockResolvedValue({
|
||||
conversation_id: 'conv-1',
|
||||
work_items: [{
|
||||
workItemType: 'order_task',
|
||||
workItemNo: 'OT-UNIFIED',
|
||||
sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: 'OT-UNIFIED',
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
submissionNo: 'SOS-1',
|
||||
intakeNo: 'SNI-1',
|
||||
work_items: [buildOrderTaskWorkItem('OT-UNIFIED', {
|
||||
status: 'waiting_review',
|
||||
stage: 'waiting_review',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-05T00:00:00Z',
|
||||
currentGate: {
|
||||
gateCode: 'order_freeze_readiness',
|
||||
status: 'blocked',
|
||||
nextActionCode: 'open_order_review',
|
||||
},
|
||||
availableActions: ['open_order_review'],
|
||||
sourceSummary: {
|
||||
emailSubject: null,
|
||||
filename: 'po.pdf',
|
||||
documentCount: 1,
|
||||
parsedDocumentCount: 1,
|
||||
candidateCount: 1,
|
||||
customerName: null,
|
||||
poNumber: 'PO-1',
|
||||
},
|
||||
childOrderTasks: [],
|
||||
}],
|
||||
})],
|
||||
conversation_processing: null,
|
||||
});
|
||||
|
||||
@@ -226,6 +239,60 @@ describe('useShippingNoticeWorkflow', () => {
|
||||
ctl.stop();
|
||||
});
|
||||
|
||||
it('preserves previous order_task work_items when stabilizer keeps previous projection', async () => {
|
||||
api.getShippingProcessing
|
||||
.mockResolvedValueOnce({
|
||||
conversation_id: 'conv-1',
|
||||
work_items: [buildOrderTaskWorkItem('OT-STABLE')],
|
||||
conversation_processing: null,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
conversation_id: 'conv-1',
|
||||
work_items: [{
|
||||
workItemType: 'order_intake',
|
||||
workItemNo: 'SNI-1',
|
||||
sourceType: 'email',
|
||||
conversationId: 'conv-1',
|
||||
intakeNo: 'SNI-1',
|
||||
status: 'processing',
|
||||
stage: 'parsing',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-05T00:00:01Z',
|
||||
currentGate: null,
|
||||
availableActions: [],
|
||||
sourceSummary: {
|
||||
emailSubject: 'mail',
|
||||
filename: 'po.pdf',
|
||||
documentCount: 1,
|
||||
parsedDocumentCount: 0,
|
||||
candidateCount: 0,
|
||||
customerName: null,
|
||||
poNumber: null,
|
||||
},
|
||||
childOrderTasks: [],
|
||||
}],
|
||||
conversation_processing: buildProcessing(),
|
||||
});
|
||||
|
||||
const ctl = useShippingNoticeWorkflow({ conversationId: ref('conv-1') });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
|
||||
expect(ctl.processing.value?.processing[0]?.user_task_no).toBe('OT-STABLE');
|
||||
expect(ctl.processingWorkItems.value[0]?.workItemType).toBe('order_task');
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2000);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
|
||||
expect(ctl.processing.value?.processing[0]?.user_task_no).toBe('OT-STABLE');
|
||||
expect(ctl.processingWorkItems.value).toHaveLength(1);
|
||||
expect(ctl.processingWorkItems.value[0]?.workItemType).toBe('order_task');
|
||||
expect(ctl.processingWorkItems.value[0]?.workItemNo).toBe('OT-STABLE');
|
||||
ctl.stop();
|
||||
});
|
||||
|
||||
it('derives sibling OT tasks from work_items when embedded conversation_processing omits them', async () => {
|
||||
api.getShippingProcessing.mockResolvedValue({
|
||||
conversation_id: 'conv-1',
|
||||
|
||||
@@ -32,6 +32,7 @@ import type {
|
||||
} from '../types/shipping.api.types';
|
||||
import {
|
||||
buildProcessingSemanticKey,
|
||||
createIntakeOtStabilizer,
|
||||
resolveConversationProcessingFromUnified,
|
||||
} from './conversationProcessingProjection';
|
||||
|
||||
@@ -147,6 +148,27 @@ export function useShippingNoticeWorkflow(
|
||||
let failureCount = 0;
|
||||
let pollingStopped = false;
|
||||
let lastSemanticKey = '';
|
||||
const intakeOtStabilizer = createIntakeOtStabilizer();
|
||||
|
||||
/**
|
||||
* 在 Intake→OT 过渡窗里,若 projection 被稳定器保留为上一轮 OT 视图,
|
||||
* 则 work_items 也必须同步保留上一轮 order_task;否则卡片正文与侧边进度条
|
||||
* 会来自两轮不同响应,导致右侧布局在“带进度条/只剩按钮”之间来回切换。
|
||||
*/
|
||||
function resolveStableWorkItems(
|
||||
nextWorkItems: ShippingProcessingProjection[],
|
||||
previousProjection: ConversationProcessingProjection | null,
|
||||
nextProjection: ConversationProcessingProjection | null,
|
||||
): ShippingProcessingProjection[] {
|
||||
const hasNextOrderTask = nextWorkItems.some((item) => item.workItemType === 'order_task');
|
||||
if (hasNextOrderTask) return nextWorkItems;
|
||||
if (!previousProjection || nextProjection !== previousProjection) return nextWorkItems;
|
||||
const currentWorkItems = Array.isArray(processingWorkItems.value)
|
||||
? processingWorkItems.value
|
||||
: [];
|
||||
const hasCurrentOrderTask = currentWorkItems.some((item) => item.workItemType === 'order_task');
|
||||
return hasCurrentOrderTask ? currentWorkItems : nextWorkItems;
|
||||
}
|
||||
|
||||
const normalizedConversationId = computed(() =>
|
||||
String(readOption(options.conversationId) || '').trim(),
|
||||
@@ -212,10 +234,20 @@ export function useShippingNoticeWorkflow(
|
||||
workItems,
|
||||
embedded,
|
||||
prevProjection,
|
||||
{
|
||||
conversationId,
|
||||
hasSeenOrderTaskBefore: (cId) => intakeOtStabilizer.hasSeenOrderTaskBefore(cId),
|
||||
markSeen: (cId) => intakeOtStabilizer.markSeen(cId),
|
||||
reset: (cId) => intakeOtStabilizer.reset(cId),
|
||||
},
|
||||
);
|
||||
const nextSemanticKey = buildProcessingSemanticKey(nextProjection);
|
||||
|
||||
processingWorkItems.value = workItems;
|
||||
processingWorkItems.value = resolveStableWorkItems(
|
||||
workItems,
|
||||
prevProjection,
|
||||
nextProjection,
|
||||
);
|
||||
if (nextSemanticKey !== lastSemanticKey) {
|
||||
processing.value = nextProjection;
|
||||
lastSemanticKey = nextSemanticKey;
|
||||
@@ -255,6 +287,7 @@ export function useShippingNoticeWorkflow(
|
||||
lastSemanticKey = '';
|
||||
return Promise.resolve();
|
||||
}
|
||||
intakeOtStabilizer.reset(conversationId);
|
||||
if (inFlightRefresh?.conversationId === conversationId) {
|
||||
return inFlightRefresh.promise;
|
||||
}
|
||||
@@ -278,12 +311,16 @@ export function useShippingNoticeWorkflow(
|
||||
}): void {
|
||||
const workItems = Array.isArray(response.work_items) ? response.work_items : [];
|
||||
if (workItems.length > 0) {
|
||||
processingWorkItems.value = workItems as typeof processingWorkItems.value;
|
||||
const nextProjection = resolveConversationProcessingFromUnified(
|
||||
workItems as typeof processingWorkItems.value,
|
||||
response.processing ?? null,
|
||||
processing.value,
|
||||
);
|
||||
processingWorkItems.value = resolveStableWorkItems(
|
||||
workItems as typeof processingWorkItems.value,
|
||||
processing.value,
|
||||
nextProjection,
|
||||
);
|
||||
const nextKey = buildProcessingSemanticKey(nextProjection);
|
||||
if (nextKey !== lastSemanticKey) {
|
||||
processing.value = nextProjection;
|
||||
|
||||
@@ -140,6 +140,125 @@ export type PdfPriorityFieldPolicy =
|
||||
| 'supplement_allowed'
|
||||
| 'review_required';
|
||||
|
||||
/**
|
||||
* 用户态统一 Projection 阻断原因(T8 决策 F2;后端对象 {code, i18n_key, details})。
|
||||
*/
|
||||
export interface ShippingProcessingBlockingReason {
|
||||
code: string;
|
||||
i18nKey?: string | null;
|
||||
details?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户态统一 Projection 主动作(T8 决策 F2;后端对象 {code, i18n_key, parameters})。
|
||||
*/
|
||||
export interface ShippingProcessingPrimaryAction {
|
||||
code: string;
|
||||
i18nKey?: string | null;
|
||||
parameters?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户态统一 Projection facts(T8 决策 F2;子状态事实字典)。
|
||||
*/
|
||||
export interface ShippingProcessingFacts {
|
||||
inventorySourceStatus?: string | null;
|
||||
candidateSetId?: number | null;
|
||||
candidateSetVersion?: number | null;
|
||||
candidateSetStatus?: 'draft' | 'frozen' | 'superseded' | 'invalidated' | null;
|
||||
candidateSourceCodes?: string[];
|
||||
preparedSourceCodes?: string[];
|
||||
pendingSourceCodes?: string[];
|
||||
failedSourceCodes?: string[];
|
||||
sourceAttempts?: Record<string, unknown>;
|
||||
rpaAttempts?: Array<{
|
||||
sourceCode?: string | null;
|
||||
sourceRunNo?: string | null;
|
||||
attemptNo?: number | null;
|
||||
status?: string | null;
|
||||
executionPhase?: string | null;
|
||||
fileGenerated?: boolean;
|
||||
fileExistsAtCallback?: boolean | null;
|
||||
errorCode?: string | null;
|
||||
transactionErrorCode?: string | null;
|
||||
callbackReceivedAt?: string | null;
|
||||
}>;
|
||||
lineResolutions?: Record<string, unknown>[];
|
||||
exportState?: string;
|
||||
uploadState?: string;
|
||||
switchState?: string;
|
||||
forcedMatchSourceCode?: string | null;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface ShippingInventoryCandidateSetSummary {
|
||||
id: number;
|
||||
version: number;
|
||||
status: 'draft' | 'frozen' | 'superseded' | 'invalidated';
|
||||
inputFingerprint: string;
|
||||
frozenAt: string | null;
|
||||
frozenBy: number | null;
|
||||
manifestSnapshotSha256?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingInventoryCandidateSourceDetail {
|
||||
id: number;
|
||||
candidateSetId: number;
|
||||
sourceCode: string;
|
||||
candidateOrder: number;
|
||||
candidateOrigin: string;
|
||||
routingRuleId?: number | null;
|
||||
routingRuleVersion?: number | string | null;
|
||||
sourceConfigVersion?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingInventoryCandidateLineDetail {
|
||||
candidateLineId: number;
|
||||
candidateSetId: number;
|
||||
lineNo: number;
|
||||
sourceLineNo?: string | null;
|
||||
partNumber?: string | null;
|
||||
reservationId?: string | null;
|
||||
allowedSourceCodes: string[];
|
||||
}
|
||||
|
||||
export interface ShippingTaskInventoryCandidatesResponse {
|
||||
taskNo: string;
|
||||
currentSet: ShippingInventoryCandidateSetSummary | null;
|
||||
sources: ShippingInventoryCandidateSourceDetail[];
|
||||
lines: ShippingInventoryCandidateLineDetail[];
|
||||
history: ShippingInventoryCandidateSetSummary[];
|
||||
blockingReason?: ShippingProcessingBlockingReason | null;
|
||||
primaryAction?: ShippingProcessingPrimaryAction | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户态统一 Projection status(T8 决策 F2;running / waiting_human / retryable / failed / completed / cancelled)。
|
||||
*/
|
||||
export type ShippingUserProcessingStatus =
|
||||
| 'running'
|
||||
| 'waiting_human'
|
||||
| 'retryable'
|
||||
| 'failed'
|
||||
| 'completed'
|
||||
| 'cancelled';
|
||||
|
||||
/**
|
||||
* 用户态统一 Projection stage(T8 决策 F2;inventory_fetch / inventory_match / excel_generate / freight_upload 等)。
|
||||
*/
|
||||
export type ShippingUserProcessingStage =
|
||||
| 'document_parsing'
|
||||
| 'order_creating'
|
||||
| 'waiting_human_review'
|
||||
| 'inventory_fetch'
|
||||
| 'inventory_match'
|
||||
| 'excel_generate'
|
||||
| 'freight_upload'
|
||||
| 'completed'
|
||||
| 'failed_terminal'
|
||||
| 'cancelled'
|
||||
| string;
|
||||
|
||||
/**
|
||||
* 统一处理投影 DTO(阶段 4 接线;阶段 0 冻结形状)。
|
||||
* 对话、对话右侧、复核工作台、后台工作台共同消费;禁止页面私自拼接状态。
|
||||
@@ -188,6 +307,78 @@ export interface ShippingProcessingProjection {
|
||||
assetStatus?: string | null;
|
||||
};
|
||||
childOrderTasks: ShippingOrderTaskSummary[];
|
||||
// ============== [T8 用户态 Projection 7 字段] ==============
|
||||
// 后端 apply_user_projection_fields 下发;旧客户端不识别会直接忽略(安全);
|
||||
// 新前端优先用本字段停止本地推导。
|
||||
/** 用户态 status(6 枚举:running / waiting_human / retryable / failed / completed / cancelled)。 */
|
||||
userStatus?: ShippingUserProcessingStatus | null;
|
||||
/** 用户态 stage(inventory_fetch / inventory_match / excel_generate / freight_upload 等)。 */
|
||||
userStage?: ShippingUserProcessingStage | null;
|
||||
/** 用户态 current_gate 编码(纯字符串;旧 currentGate 仍为对象保留)。 */
|
||||
userCurrentGateCode?: string | null;
|
||||
/** 阻断原因:{code, i18nKey, details};status=waiting_human / retryable / failed 时非空。 */
|
||||
blockingReason?: ShippingProcessingBlockingReason | null;
|
||||
/** 技术失败是否可重试;业务阻断(waiting_human)通常 false。 */
|
||||
retryable?: boolean;
|
||||
/** 唯一主入口按钮建议:{code, i18nKey, parameters};前端只渲染不新建动作码。 */
|
||||
primaryAction?: ShippingProcessingPrimaryAction | null;
|
||||
/** 子状态事实字典(inventorySourceStatus / candidateSourceCodes / preparedSourceCodes / pendingSourceCodes / lineResolutions / exportState / uploadState / switchState)。 */
|
||||
facts?: ShippingProcessingFacts;
|
||||
/** 旧 status 备份(T8 apply_user_projection_fields.legacy_status);调试用。 */
|
||||
legacyStatus?: string | null;
|
||||
/** 旧 stage 备份(T8 apply_user_projection_fields.legacy_stage);调试用。 */
|
||||
legacyStage?: string | null;
|
||||
/** 正式 OT 是否已挂接真实 ShippingNotice;T1 判定:order_task + shipping_notice_id 非空 + shipping_notice_no 非空。 */
|
||||
hasFormalOt?: boolean;
|
||||
/**
|
||||
* 题4A:inventory 统一 Projection(仅 inventory 阶段及之前且 hasFormalOt=true 时填充;其他阶段 null)。
|
||||
* 权威事实源:summarize_inventory_rpa_latest_attempts();
|
||||
* 前端按钮禁用/重试文案/状态徽章全部直接读本对象,禁止继续拼接旧字段合成 running。
|
||||
*/
|
||||
inventoryPreparation?: ShippingInventoryPreparationSummary | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 题4A & 7A:逐源 inventory 准备状态(ShippingProcessingProjection.inventoryPreparation)。
|
||||
* 按实际冻结源 required_sources 为基准分类,failed/exhausted 拆分暴露。
|
||||
*/
|
||||
export interface ShippingInventoryPreparationSummary {
|
||||
/** 实际任务级冻结源(task.task_frozen_inventory_source_codes),顺序以冻结记录为准。 */
|
||||
requiredSources: string[];
|
||||
/** 已就绪:有 prepared 状态 Attempt,或 inventory_lines_json + inventory_snapshot_id 已载入。 */
|
||||
preparedSources: string[];
|
||||
/** RPA 正在跑或入队中(queued / running);active_attempt_count > 0 的对应源集合。 */
|
||||
pendingSources: string[];
|
||||
/** 最近一次失败状态(attempt.status == failed)但未耗尽自动次数的源。 */
|
||||
failedSources: string[];
|
||||
/** 题7A:自动重试 max_attempts 已耗尽但允许人工 user_retry 继续的源;独立于 failed,便于 UI 提示。 */
|
||||
exhaustedSources: string[];
|
||||
/** 全表当前 queued+running Attempt 总数(>= pendingSources.length,存在 Gate 活动 Attempt 时会更高)。 */
|
||||
activeAttemptCount: number;
|
||||
/** 题2B:Process Gate 是否有 queued/running 状态的 inventory 批次;作为全局 running 额外保护。 */
|
||||
gateAttemptActive?: boolean;
|
||||
/**
|
||||
* 按冻结源逐源最近 Attempt 摘要(source_code → 结构化记录)。
|
||||
* 用于 UI tooltip/详情;按钮禁用不直接读本字典,读上面的 required/prepared/pending/failed/exhausted 集合。
|
||||
*/
|
||||
latestAttempts?: Record<string, ShippingInventoryPerSourceAttempt>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 逐源最近一次 Inventory RPA Attempt 摘要(inventoryPreparation.latestAttempts[sourceCode])。
|
||||
* 仅用于 UI 展示;业务判定必须走顶层 *_sources 集合。
|
||||
*/
|
||||
export interface ShippingInventoryPerSourceAttempt {
|
||||
sourceCode: string;
|
||||
attemptNo: number;
|
||||
/** queued | running | consumed | failed | exhausted | skipped */
|
||||
status: string;
|
||||
/** 失败/耗尽:人工可继续;running/queued:false */
|
||||
manualRetryable?: boolean;
|
||||
/** attempt.error_message 或 业务错误摘要,供 tooltip。 */
|
||||
message?: string | null;
|
||||
updatedAt?: string | null;
|
||||
/** attempt.id 便于定位日志;不向浏览器直接暴露内部数据库 ID,此处省略。 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,6 +555,15 @@ export interface ConversationProcessingUserTask {
|
||||
primary_action?: string | null;
|
||||
available_actions?: string[];
|
||||
objects?: ConversationProcessingObject[];
|
||||
userStatus?: ShippingUserProcessingStatus | null;
|
||||
userStage?: ShippingUserProcessingStage | null;
|
||||
userCurrentGateCode?: string | null;
|
||||
blockingReason?: ShippingProcessingBlockingReason | null;
|
||||
retryable?: boolean;
|
||||
primaryAction?: ShippingProcessingPrimaryAction | null;
|
||||
facts?: ShippingProcessingFacts;
|
||||
legacyStatus?: string | null;
|
||||
legacyStage?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1965,6 +2165,12 @@ export interface ShippingOrderReviewFieldConflictOption {
|
||||
evidence_role?: 'primary_pdf' | 'auxiliary' | 'context' | string | null;
|
||||
/** PDF_PRIORITY_EVIDENCE_RANKS 档位名。 */
|
||||
evidence_rank?: string | null;
|
||||
/** Vendor Comments 三来源专属:字段来源种类(header_region / table_column / vendor_comments)。 */
|
||||
vc_source_kind?: string | null;
|
||||
/** Vendor Comments 三来源专属:来源种类的本地化展示标签。 */
|
||||
vc_source_kind_label?: string | null;
|
||||
/** Vendor Comments 三来源专属:vc:<doc>:p<N>:region:<rid> 证据引用,可跳转证据查看器定位对应区域。 */
|
||||
evidence_ref?: string | null;
|
||||
}
|
||||
|
||||
/** 建单前 Candidate 字段冲突投影(复核工作台集中裁决区)。 */
|
||||
@@ -1977,6 +2183,18 @@ export interface ShippingOrderReviewFieldConflict {
|
||||
reason: string;
|
||||
options: ShippingOrderReviewFieldConflictOption[];
|
||||
observation_ids?: string[];
|
||||
/** Vendor Comments 三来源专属:true 表示该冲突来自 VC 三来源合并,conflict_key 以 vc: 开头。 */
|
||||
vc_kind?: boolean | null;
|
||||
/** Vendor Comments 三来源专属:细因码(vc_source_conflict_unresolved / vc_source_format_invalid / vc_source_region_unbound)。 */
|
||||
vc_reason?: string | null;
|
||||
/** Vendor Comments 三来源专属:冲突组稳定键(scope:field_code:line_no),裁决时写回 merged_candidates 使用。 */
|
||||
vc_conflict_group_key?: string | null;
|
||||
/** Vendor Comments 三来源专属:只读诊断,展示 resolution / decision_status / format_valid。 */
|
||||
vc_detail?: {
|
||||
resolution?: string | null;
|
||||
decision_status?: string | null;
|
||||
format_valid?: boolean | null;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface ShippingOrderReviewCase {
|
||||
@@ -2091,6 +2309,33 @@ export interface ShippingOrderReviewCase {
|
||||
order_data_version?: number | null;
|
||||
llm_suggestions?: ShippingOrderReviewLlmSuggestion[];
|
||||
process_gate?: ShippingProcessGateUserSummary | null;
|
||||
/** Case 用户态六事实之一:禁止前端自行从 stage 推导。 */
|
||||
user_status?:
|
||||
| 'running'
|
||||
| 'waiting_human'
|
||||
| 'retryable'
|
||||
| 'failed'
|
||||
| 'completed'
|
||||
| 'cancelled'
|
||||
| null;
|
||||
/** Case 用户阻断说明:仅消费后端投影。 */
|
||||
blocking_reason?: ShippingProcessingBlockingReason | null;
|
||||
/** Case 主动作:仅消费后端投影。 */
|
||||
primary_action?: ShippingProcessingPrimaryAction | null;
|
||||
}
|
||||
|
||||
/** 完整 Case 快照的纯展示 loading 上下文。 */
|
||||
export interface ShippingOrderReviewCaseLoadingContext {
|
||||
phase?: string | null;
|
||||
status?: string | null;
|
||||
message?: string | null;
|
||||
}
|
||||
|
||||
/** 工作台单 Case 完整快照:包装现有 case 投影并附审计版本。 */
|
||||
export interface ShippingOrderReviewCaseSnapshot {
|
||||
case: ShippingOrderReviewCase;
|
||||
projection_version: number;
|
||||
loading_context?: ShippingOrderReviewCaseLoadingContext | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2191,24 +2436,58 @@ export interface ShippingOrderReviewEvidence {
|
||||
requires_review?: boolean;
|
||||
}
|
||||
|
||||
/** Dify 最小证据建议 DTO;与后端 serialize_suggestion 对齐。 */
|
||||
/** Dify 最小证据建议 DTO;与后端 serialize_suggestion 对齐(Phase 4 权限分层:普通用户无 provider_trace / request_preview)。 */
|
||||
export interface ShippingOrderReviewLlmSuggestion {
|
||||
suggestion_no: string;
|
||||
field_id: string;
|
||||
line_key?: string | null;
|
||||
scope: string;
|
||||
evidence_level: string;
|
||||
contract_version?: string;
|
||||
status: string;
|
||||
error_code?: string | null;
|
||||
/** @deprecated 后端不再输出;前端统一按 error_code 查 i18n errors.json */
|
||||
error_message?: string | null;
|
||||
suggested_value?: unknown;
|
||||
validation_issues?: Array<{ code?: string; severity?: string }>;
|
||||
validation_issues?: Array<{
|
||||
code?: string;
|
||||
severity?: string;
|
||||
checks_order?: string[];
|
||||
match?: Record<string, unknown>;
|
||||
detail?: string;
|
||||
}>;
|
||||
decision?: string | null;
|
||||
decision_reason?: string | null;
|
||||
decision_note?: string | null;
|
||||
draft_version_at_request?: number | null;
|
||||
created_at?: string | null;
|
||||
adjudicated_at?: string | null;
|
||||
auto_upgrade_reason?: string | null;
|
||||
/** 普通用户可见:证据范围摘要(level/auto_upgraded/counts/context_truncated)。 */
|
||||
evidence_summary?: {
|
||||
level: string;
|
||||
auto_upgraded: boolean;
|
||||
auto_upgrade_reason?: string | null;
|
||||
field_count: number;
|
||||
row_count?: number | null;
|
||||
table_count?: number | null;
|
||||
page_count?: number | null;
|
||||
core_evidence_source?: string | null;
|
||||
context_truncated: boolean;
|
||||
} | null;
|
||||
/** 管理员专属:Provider 对账追踪信息。 */
|
||||
provider_trace?: {
|
||||
provider?: string | null;
|
||||
conversation_id?: string | null;
|
||||
message_id?: string | null;
|
||||
latency_ms?: number | null;
|
||||
} | null;
|
||||
/** 管理员专属:请求信封审计预览(fields_sent_preview / policies_applied / budget_tokens / method)。 */
|
||||
request_preview?: Record<string, unknown> | null;
|
||||
/** 管理员专属:上下文指纹。 */
|
||||
context_hash?: string | null;
|
||||
/** 管理员专属:Provider 端到端延迟 ms。 */
|
||||
latency_ms?: number | null;
|
||||
}
|
||||
|
||||
export interface ShippingOrderReviewLlmSuggestionRequest {
|
||||
@@ -2465,12 +2744,18 @@ export interface ShippingOrderReviewLineFulfillmentLine {
|
||||
inventory_snapshot_id?: number | null;
|
||||
inventory_checked_at?: string | null;
|
||||
inventory_source_code?: string | null;
|
||||
inventory_source?: {
|
||||
inventory_source?: ({
|
||||
code?: string | null;
|
||||
label?: string | null;
|
||||
status?: 'resolved' | 'resolving' | 'unrecognized' | 'conflict' | 'unavailable' | string | null;
|
||||
source?: string | null;
|
||||
} | null;
|
||||
} & ({
|
||||
status: 'candidates_frozen';
|
||||
candidates: Array<string | { code?: string | null; label?: string | null; [key: string]: unknown }>;
|
||||
} | {
|
||||
status?: Exclude<string, 'candidates_frozen'> | null;
|
||||
candidates?: never;
|
||||
})) | null;
|
||||
decision_source?: 'system' | 'user' | 'unknown' | null;
|
||||
/** 行级统一「重试」是否可点;前端禁止用 inventory_allowed_actions 猜按钮。 */
|
||||
retryable?: boolean;
|
||||
|
||||
@@ -155,6 +155,8 @@ function createReviewComposableMock() {
|
||||
return {
|
||||
reviewRun,
|
||||
activeCase,
|
||||
caseProjectionVersion: ref(1),
|
||||
caseLoadingContext: ref(null),
|
||||
reviewProgressContext,
|
||||
workItem,
|
||||
authoritativeOrderTaskNo: computed(() => {
|
||||
@@ -800,7 +802,7 @@ describe('ShippingOrderReviewView layout phase 1', () => {
|
||||
});
|
||||
|
||||
describe('ShippingOrderReviewView audit and progress recovery', () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
resetActiveCaseFixture();
|
||||
reviewProgressContext.value = null;
|
||||
@@ -812,7 +814,7 @@ describe('ShippingOrderReviewView audit and progress recovery', () => {
|
||||
audited: true,
|
||||
case_no: 'CASE-1',
|
||||
});
|
||||
});
|
||||
}, 20000);
|
||||
|
||||
it('refuses to open version history when access audit fails', async () => {
|
||||
vi.mocked(auditWorkspaceShippingOrderReviewVersionHistory).mockRejectedValueOnce(new Error('audit down'));
|
||||
@@ -1037,7 +1039,7 @@ describe('ShippingOrderReviewView audit and progress recovery', () => {
|
||||
const wrapper = await mountView();
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="review-profile-match-panel"]').exists()).toBe(true);
|
||||
});
|
||||
}, 15000);
|
||||
|
||||
it('hydrates progress-failed retry state from Case projection without confirm UI', async () => {
|
||||
// 关键断言:无确认建单按钮时,仍可从 post_confirm_auto_progress 恢复对象级重试入口。
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -67,8 +67,8 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
|
||||
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
|
||||
const NEEDS_ACTION_STATUSES = new Set([
|
||||
'blocked', 'waiting_review', 'pending_review', 'failed', 'reparse_failed',
|
||||
'manual_upload_pending', 'upload_rpa_failed',
|
||||
'blocked', 'waiting_review', 'pending_review', 'waiting_human',
|
||||
'failed', 'reparse_failed', 'manual_upload_pending', 'upload_rpa_failed',
|
||||
]);
|
||||
/** 永不升为主 CTA 的动作码(仍可作次要/溢出)。 */
|
||||
const NEVER_PRIMARY_CODES = new Set(['cancel_task', 'cancel_run', 'view_details']);
|
||||
@@ -217,7 +217,7 @@ export function resolveProcessingActionPresentation(
|
||||
items.push(toItem(code, intent, surface));
|
||||
};
|
||||
|
||||
pushCode(projection.currentGate?.nextActionCode);
|
||||
pushCode(projection.primaryAction?.code || projection.currentGate?.nextActionCode);
|
||||
// [ORDER-STABLE] 对 availableActions 标准化(去重 + 字典序排序),确保后端返回顺序不影响前端按钮顺序。
|
||||
const normalizedAvailableActions = normalizeActionCodes(projection.availableActions || []);
|
||||
for (const action of normalizedAvailableActions) {
|
||||
@@ -250,7 +250,9 @@ export function resolveConversationTaskActionPresentation(
|
||||
if (!task) return empty;
|
||||
|
||||
const surface = options?.surface || 'right';
|
||||
const status = String(task.status_label || '').trim().toLowerCase();
|
||||
const userStatus = String(task.userStatus ?? '').trim().toLowerCase();
|
||||
const legacyStatus = String(task.status_label ?? '').trim().toLowerCase();
|
||||
const status = userStatus || legacyStatus;
|
||||
const isNeedsAction = task.group === 'needs_action' || NEEDS_ACTION_STATUSES.has(status);
|
||||
const isProcessing = task.group === 'processing' || AUTOMATING_STATUSES.has(status);
|
||||
if (task.group === 'history' || status === 'cancelled') {
|
||||
@@ -270,7 +272,7 @@ export function resolveConversationTaskActionPresentation(
|
||||
items.push(toItem(code, intent, surface));
|
||||
};
|
||||
|
||||
pushCode(task.primary_action);
|
||||
pushCode(task.primaryAction?.code || task.primary_action);
|
||||
// [ORDER-STABLE] 对 available_actions 标准化排序,确保后端顺序变化不影响按钮渲染顺序。
|
||||
const normalizedTaskActions = normalizeActionCodes(task.available_actions || []);
|
||||
for (const action of normalizedTaskActions) {
|
||||
|
||||
@@ -69,10 +69,12 @@ function mountStrip(projection: ShippingProcessingProjection, polling = false) {
|
||||
},
|
||||
shippingProcessing: {
|
||||
progress: {
|
||||
completedOfTotal: '已完成 {done} / {total}',
|
||||
currentNeedLabel: '当前需要:',
|
||||
title: '订单处理进度',
|
||||
currentStage: '当前阶段:{stage}',
|
||||
progressTitleWithStage: '订单处理进度 · {stage}',
|
||||
systemProcessingWithStage: '系统处理中 · {stage}',
|
||||
completedOfTotal: '已完成 {done} / {total}',
|
||||
currentNeedLabel: '当前需要:',
|
||||
viewProcessDetails: '查看流程详情',
|
||||
viewFullProcess: '查看完整流程',
|
||||
stageNodesUnavailable: '进度详情暂不可用',
|
||||
@@ -86,6 +88,7 @@ function mountStrip(projection: ShippingProcessingProjection, polling = false) {
|
||||
shippingNotice: {
|
||||
processGate: {
|
||||
actions: { confirm_customer: '确认客户', retry_freight_upload_rpa: '重试货代上传' },
|
||||
actionCodes: { confirm_customer: '确认客户', retry_freight_upload_rpa: '重试货代上传' },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -56,9 +56,49 @@ const isAutomating = computed(() => {
|
||||
});
|
||||
|
||||
/**
|
||||
* 标题仅「订单处理进度」,阶段名由节点/窄屏摘要表达。
|
||||
* 标题:默认「订单处理进度 · 当前阶段」;自动推进状态切换为「系统处理中 · 当前阶段」;
|
||||
* 无阶段名时退化为纯标题,保证标题行至少可读。
|
||||
*/
|
||||
const titleLine = computed(() => t('chat.shippingProcessing.progress.title'));
|
||||
const titleLine = computed(() => {
|
||||
const stage = currentStageName.value;
|
||||
if (isAutomating.value) {
|
||||
const withStage = te('chat.shippingProcessing.progress.systemProcessingWithStage');
|
||||
if (withStage && stage && stage !== '—') {
|
||||
return t('chat.shippingProcessing.progress.systemProcessingWithStage', { stage });
|
||||
}
|
||||
const fallback = t('chat.shippingProcessing.progress.title');
|
||||
return fallback;
|
||||
}
|
||||
const withStage = te('chat.shippingProcessing.progress.progressTitleWithStage');
|
||||
if (withStage && stage && stage !== '—') {
|
||||
return t('chat.shippingProcessing.progress.progressTitleWithStage', { stage });
|
||||
}
|
||||
return t('chat.shippingProcessing.progress.title');
|
||||
});
|
||||
|
||||
/**
|
||||
* 当前需要文案:优先 blockingReasonCode → gateReasons;无则回退 nextActionCode → actionCodes;
|
||||
* 自动推进状态 / 已生成正式 OT / 无有效 label 时不渲染。
|
||||
*/
|
||||
const currentNeedLabel = computed<string | null>(() => {
|
||||
if (props.hasFormalOt) return null;
|
||||
if (isAutomating.value) return null;
|
||||
const gate = props.projection.currentGate;
|
||||
if (!gate) return null;
|
||||
const reasonCode = String(gate.blockingReasonCode || '').trim();
|
||||
if (reasonCode) {
|
||||
const reasonKey = `chat.shippingProcessing.gateReasons.${reasonCode}`;
|
||||
if (te(reasonKey)) return t(reasonKey);
|
||||
}
|
||||
const nextCode = String(gate.nextActionCode || '').trim();
|
||||
if (nextCode) {
|
||||
const actionKey = `workspace.shippingNotice.processGate.actionCodes.${nextCode}`;
|
||||
if (te(actionKey)) return t(actionKey);
|
||||
const chatActionKey = `chat.shippingProcessing.action.${nextCode}`;
|
||||
if (te(chatActionKey)) return t(chatActionKey);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
/**
|
||||
* 窄屏当前阶段名:只用 stage code → 阶段 i18n,不用 waiting_system_start 等自动化 label_key。
|
||||
@@ -115,6 +155,13 @@ function nodeShortLabel(stage: string): string {
|
||||
data-testid="review-progress-title"
|
||||
>
|
||||
{{ titleLine }}
|
||||
<span
|
||||
v-if="currentNeedLabel"
|
||||
class="ml-2 font-normal text-secondary"
|
||||
data-testid="review-progress-current-need"
|
||||
>
|
||||
{{ t('chat.shippingProcessing.progress.currentNeedLabel') }}{{ currentNeedLabel }}
|
||||
</span>
|
||||
<span
|
||||
class="ml-2 font-normal text-secondary md:hidden"
|
||||
data-testid="review-progress-current-stage-narrow"
|
||||
|
||||
Reference in new issue
Block a user