feat(shipping-notice): 增强发货通知与订单抽取功能,支持多进程处理与紧急停止
- 移除不再使用的 SHIPPING_NOTICE_LAYOUT_PARSER_REVISION 配置 - 在环境配置中新增 SHIPPING_NOTICE_WORKER_CONCURRENCY 和 SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS - 实现发货通知 worker 进程,支持并发处理订单抽取任务 - 引入紧急停止功能,允许管理员在运行中控制订单解析状态 - 更新相关 API,支持读取与设置紧急停止状态 - 增强文档与代码注释,反映新的业务逻辑与功能要求
This commit is contained in:
1 parent
d0fe084999
commit
b352c281d5
149 files changed
+12550
-1874
No files matched your search
@@ -0,0 +1,85 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewLlmEvidenceComparison.vue
|
||||
用途:三列对比当前草稿、AI 建议与原文证据。
|
||||
依赖:vue-i18n、ShippingOrderReviewEvidence / LlmSuggestion 类型。
|
||||
逻辑:嵌入 ReviewLlmSuggestionDialog;逐字失败码与后端 value_not_in_evidence 对齐;只读展示。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingOrderReviewEvidence, ShippingOrderReviewLlmSuggestion } from '../../types/shipping.api.types';
|
||||
|
||||
/** 三列对比入参;建议/证据可空,标签缺省为空串。 */
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
draftValue?: unknown;
|
||||
suggestion?: ShippingOrderReviewLlmSuggestion | null;
|
||||
evidence?: ShippingOrderReviewEvidence | null;
|
||||
fieldLabel?: string;
|
||||
}>(),
|
||||
{
|
||||
fieldLabel: '',
|
||||
},
|
||||
);
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const suggestedValue = computed(() => props.suggestion?.suggested_value ?? '-');
|
||||
const draftDisplay = computed(() => {
|
||||
const value = props.draftValue;
|
||||
if (value === null || value === undefined || value === '') return '-';
|
||||
return String(value);
|
||||
});
|
||||
const evidenceQuote = computed(() => props.evidence?.quote || '-');
|
||||
const evidenceLocation = computed(() => {
|
||||
const page = props.evidence?.page_no;
|
||||
const cell = props.evidence?.cell_id;
|
||||
if (page && cell) return t('chat.shippingOrderReview.llmSuggestion.evidenceAtCell', { page, cell });
|
||||
if (page) return t('chat.shippingOrderReview.evidenceAt', { page });
|
||||
return t('chat.shippingOrderReview.llmSuggestion.noEvidenceCoords');
|
||||
});
|
||||
/** 与后端 rejection_reason 对齐;含历史别名 suggested_value_not_in_evidence。 */
|
||||
const VERBATIM_FAIL_CODES = new Set([
|
||||
'value_not_in_evidence',
|
||||
'suggested_value_not_in_evidence',
|
||||
'empty_suggestion',
|
||||
'field_id_mismatch',
|
||||
]);
|
||||
const verbatimOk = computed(() => {
|
||||
if (String(props.suggestion?.status || '') === 'validation_failed') return false;
|
||||
const issues = props.suggestion?.validation_issues || [];
|
||||
return !issues.some((item) => VERBATIM_FAIL_CODES.has(String(item.code || '')));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid gap-3 md:grid-cols-3" data-testid="review-llm-evidence-comparison">
|
||||
<div class="rounded-lg border border-slate-200 bg-slate-50 p-3">
|
||||
<p class="text-xs font-medium uppercase tracking-wide text-slate-500">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.currentDraft') }}
|
||||
</p>
|
||||
<p class="mt-2 text-sm font-semibold text-slate-900">{{ props.fieldLabel }}</p>
|
||||
<p class="mt-1 text-sm text-slate-700">{{ draftDisplay }}</p>
|
||||
</div>
|
||||
<div class="rounded-lg border border-indigo-200 bg-indigo-50/60 p-3">
|
||||
<p class="text-xs font-medium uppercase tracking-wide text-indigo-600">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.aiSuggestion') }}
|
||||
</p>
|
||||
<p class="mt-2 text-sm font-semibold text-slate-900">{{ suggestedValue }}</p>
|
||||
<p class="mt-1 text-xs" :class="verbatimOk ? 'text-emerald-700' : 'text-amber-700'">
|
||||
{{
|
||||
verbatimOk
|
||||
? t('chat.shippingOrderReview.llmSuggestion.verbatimOk')
|
||||
: t('chat.shippingOrderReview.llmSuggestion.verbatimFailed')
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="rounded-lg border border-slate-200 bg-white p-3">
|
||||
<p class="text-xs font-medium uppercase tracking-wide text-slate-500">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.sourceEvidence') }}
|
||||
</p>
|
||||
<p class="mt-2 text-sm text-slate-800">{{ evidenceQuote }}</p>
|
||||
<p class="mt-1 text-xs text-slate-500">{{ evidenceLocation }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,233 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewLlmSuggestionDialog.vue
|
||||
用途:复核工作台内 AI 建议对比与裁决对话框。
|
||||
依赖:vue-i18n、ReviewLlmEvidenceComparison、ShippingOrderReview* 类型。
|
||||
逻辑:接受可备注;修改/拒绝必须填写原因;validation_failed 仅允许拒绝;
|
||||
含 dialog 语义、Escape、焦点陷阱与恢复。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type {
|
||||
ShippingOrderReviewEvidence,
|
||||
ShippingOrderReviewLlmSuggestion,
|
||||
} from '../../types/shipping.api.types';
|
||||
import ReviewLlmEvidenceComparison from './ReviewLlmEvidenceComparison.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
suggestion?: ShippingOrderReviewLlmSuggestion | null;
|
||||
evidence?: ShippingOrderReviewEvidence | null;
|
||||
draftValue?: unknown;
|
||||
/** Schema 字段展示名;缺省回退 field_id。 */
|
||||
fieldLabel?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
decide: [payload: { decision: 'accept' | 'modify' | 'reject'; reason: string; value?: unknown }];
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const decision = ref<'accept' | 'modify' | 'reject'>('accept');
|
||||
const reason = ref('');
|
||||
const modifiedValue = ref('');
|
||||
const panelRef = ref<HTMLElement | null>(null);
|
||||
const previousFocus = ref<HTMLElement | null>(null);
|
||||
|
||||
/** 逐字验证失败时仅允许拒绝,禁止 accept/modify。 */
|
||||
const rejectOnly = computed(() => String(props.suggestion?.status || '') === 'validation_failed');
|
||||
|
||||
const displayFieldLabel = computed(() =>
|
||||
String(props.fieldLabel || props.suggestion?.field_id || '').trim(),
|
||||
);
|
||||
|
||||
const evidenceLevelText = computed(() => {
|
||||
const code = String(props.suggestion?.evidence_level || 'L1_field').trim() || 'L1_field';
|
||||
const key = `chat.shippingOrderReview.llmSuggestion.evidenceLevel.${code}`;
|
||||
return te(key) ? t(key) : t('chat.shippingOrderReview.llmSuggestion.scope', { level: code });
|
||||
});
|
||||
|
||||
const canSubmit = computed(() => {
|
||||
if (decision.value === 'accept') return !rejectOnly.value;
|
||||
return Boolean(reason.value.trim());
|
||||
});
|
||||
|
||||
/**
|
||||
* 提交裁决;修改/拒绝无原因时按钮禁用。
|
||||
*/
|
||||
function submit() {
|
||||
if (!canSubmit.value) return;
|
||||
emit('decide', {
|
||||
decision: decision.value,
|
||||
reason: reason.value.trim(),
|
||||
value: decision.value === 'modify' ? modifiedValue.value : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父级。
|
||||
*/
|
||||
function close() {
|
||||
emit('close');
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集面板内可聚焦控件,供焦点陷阱使用。
|
||||
*/
|
||||
function focusableElements(): HTMLElement[] {
|
||||
const root = panelRef.value;
|
||||
if (!root) return [];
|
||||
return Array.from(
|
||||
root.querySelectorAll<HTMLElement>(
|
||||
'button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [href], [tabindex]:not([tabindex="-1"])',
|
||||
),
|
||||
).filter((el) => !el.hasAttribute('disabled') && el.tabIndex !== -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开时聚焦首个可交互控件;关闭时恢复触发焦点。
|
||||
*/
|
||||
async function restoreOrCaptureFocus(open: boolean) {
|
||||
if (typeof document === 'undefined') return;
|
||||
if (open) {
|
||||
previousFocus.value = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
await nextTick();
|
||||
const first = focusableElements()[0];
|
||||
first?.focus();
|
||||
return;
|
||||
}
|
||||
previousFocus.value?.focus?.();
|
||||
previousFocus.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape 关闭;Tab 在对话框内循环,防止焦点落到遮罩后的复核页。
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (!props.open) return;
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (event.key !== 'Tab') return;
|
||||
const nodes = focusableElements();
|
||||
const first = nodes[0];
|
||||
const last = nodes[nodes.length - 1];
|
||||
// [STEP] noUncheckedIndexedAccess:空数组或越界时 first/last 为 undefined,禁止直接 .focus()。
|
||||
if (!first || !last) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
const active = document.activeElement as HTMLElement | null;
|
||||
if (event.shiftKey && active === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && active === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
decision.value = rejectOnly.value ? 'reject' : 'accept';
|
||||
reason.value = '';
|
||||
modifiedValue.value = String(props.suggestion?.suggested_value ?? '');
|
||||
}
|
||||
void restoreOrCaptureFocus(open);
|
||||
if (typeof document === 'undefined') return;
|
||||
if (open) document.addEventListener('keydown', onKeydown);
|
||||
else document.removeEventListener('keydown', onKeydown);
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (typeof document !== 'undefined') document.removeEventListener('keydown', onKeydown);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="t('chat.shippingOrderReview.llmSuggestion.dialogTitle')"
|
||||
data-testid="review-llm-suggestion-dialog"
|
||||
@click.self="close"
|
||||
>
|
||||
<div
|
||||
ref="panelRef"
|
||||
class="max-h-[80vh] w-full max-w-3xl overflow-auto rounded-lg bg-white p-4 shadow-lg dark:bg-slate-900"
|
||||
data-testid="review-llm-suggestion-panel"
|
||||
>
|
||||
<h3 class="text-base font-semibold">{{ t('chat.shippingOrderReview.llmSuggestion.dialogTitle') }}</h3>
|
||||
<p class="mt-1 text-xs text-slate-500">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.dialogHint') }}
|
||||
· {{ evidenceLevelText }}
|
||||
</p>
|
||||
|
||||
<div class="mt-4">
|
||||
<ReviewLlmEvidenceComparison
|
||||
:draft-value="draftValue"
|
||||
:suggestion="suggestion"
|
||||
:evidence="evidence"
|
||||
:field-label="displayFieldLabel"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex flex-wrap gap-4 text-sm">
|
||||
<label v-if="!rejectOnly" class="inline-flex items-center gap-1">
|
||||
<input v-model="decision" type="radio" value="accept" />
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.decisions.accept') }}
|
||||
</label>
|
||||
<label v-if="!rejectOnly" class="inline-flex items-center gap-1">
|
||||
<input v-model="decision" type="radio" value="modify" />
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.decisions.modify') }}
|
||||
</label>
|
||||
<label class="inline-flex items-center gap-1">
|
||||
<input v-model="decision" type="radio" value="reject" />
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.decisions.reject') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<input
|
||||
v-if="decision === 'modify'"
|
||||
v-model="modifiedValue"
|
||||
class="mt-2 w-full rounded border p-2 text-sm dark:border-slate-700 dark:bg-slate-950"
|
||||
:placeholder="t('chat.shippingOrderReview.llmSuggestion.modifiedValue')"
|
||||
/>
|
||||
<textarea
|
||||
v-model="reason"
|
||||
class="mt-2 w-full rounded border p-2 text-sm dark:border-slate-700 dark:bg-slate-950"
|
||||
rows="2"
|
||||
:placeholder="
|
||||
decision === 'accept'
|
||||
? t('chat.shippingOrderReview.llmSuggestion.noteOptional')
|
||||
: t('chat.shippingOrderReview.llmSuggestion.reasonRequired')
|
||||
"
|
||||
/>
|
||||
|
||||
<div class="mt-3 flex justify-end gap-2">
|
||||
<button type="button" class="rounded border px-3 py-1 text-sm" @click="close">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded border px-3 py-1 text-sm disabled:opacity-50"
|
||||
:disabled="!canSubmit"
|
||||
data-testid="review-llm-submit-decision"
|
||||
@click="submit"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* features/chat/components/shipping-review/ReviewLlmSuggestionPanel.spec.ts
|
||||
* 用途:锁定 LLM 建议面板的草稿对比与裁决弹窗契约。
|
||||
* 依赖:vitest、@vue/test-utils、vue-i18n。
|
||||
* 逻辑:按建议字段解析 header 草稿值;弹窗含 dialog 语义;修改/拒绝无原因不可提交。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import ReviewLlmSuggestionPanel from './ReviewLlmSuggestionPanel.vue';
|
||||
import type {
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewLlmSuggestion,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const messages = {
|
||||
en: {
|
||||
chat: {
|
||||
shippingOrderReview: {
|
||||
llmSuggestion: {
|
||||
panelTitle: 'AI suggestion',
|
||||
panelHint: 'Minimal evidence only',
|
||||
request: 'Request',
|
||||
requesting: 'Requesting',
|
||||
review: 'Review',
|
||||
empty: 'No suggestions',
|
||||
scope: 'Scope {level}',
|
||||
dialogTitle: 'AI suggestion dialog',
|
||||
dialogHint: 'Compare draft and evidence',
|
||||
currentDraft: 'Current draft',
|
||||
aiSuggestion: 'AI suggestion',
|
||||
sourceEvidence: 'Evidence',
|
||||
verbatimOk: 'OK',
|
||||
verbatimFailed: 'Failed',
|
||||
evidenceAtCell: 'page {page} {cell}',
|
||||
noEvidenceCoords: 'no coords',
|
||||
cancel: 'Cancel',
|
||||
submit: 'Submit',
|
||||
modifiedValue: 'Modified',
|
||||
noteOptional: 'Note',
|
||||
reasonRequired: 'Reason required',
|
||||
status: { idle: 'Idle', pending: 'Pending', validated: 'Validated' },
|
||||
decisions: { accept: 'Accept', modify: 'Modify', reject: 'Reject' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 构造最小 Case + 建议夹具。
|
||||
*/
|
||||
function fixtures() {
|
||||
const suggestion: ShippingOrderReviewLlmSuggestion = {
|
||||
suggestion_no: 'RSG-TEST001',
|
||||
field_id: 'fld-po',
|
||||
scope: 'header',
|
||||
evidence_level: 'L1_field',
|
||||
status: 'validated',
|
||||
suggested_value: 'PO-NEW',
|
||||
validation_issues: [],
|
||||
};
|
||||
const activeCase = {
|
||||
case_no: 'SRC-1',
|
||||
draft: {
|
||||
draft_version: 3,
|
||||
header_values: {
|
||||
values: { 'fld-po': { value: 'PO-OLD', source: 'manual' } },
|
||||
machine_fields: [{ field_id: 'fld-po', value: 'PO-MACHINE' }],
|
||||
},
|
||||
lines: [],
|
||||
},
|
||||
} as unknown as ShippingOrderReviewCase;
|
||||
return { suggestion, activeCase };
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂载建议面板。
|
||||
*/
|
||||
function mountPanel(overrides?: {
|
||||
suggestions?: ShippingOrderReviewLlmSuggestion[];
|
||||
editable?: boolean;
|
||||
focusedFieldId?: string;
|
||||
}) {
|
||||
const { suggestion, activeCase } = fixtures();
|
||||
const i18n = createI18n({ legacy: false, locale: 'en', messages });
|
||||
return mount(ReviewLlmSuggestionPanel, {
|
||||
props: {
|
||||
activeCase,
|
||||
evidence: [{ evidence_id: 'e1', field_id: 'fld-po', quote: 'PO-NEW', page_no: 1, source: 'layout' }],
|
||||
editable: overrides?.editable ?? true,
|
||||
saving: false,
|
||||
suggestions: overrides?.suggestions ?? [suggestion],
|
||||
suggestionLoading: false,
|
||||
focusedFieldId: overrides?.focusedFieldId ?? 'fld-po',
|
||||
focusedLineKey: null,
|
||||
draftValue: null,
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
attachTo: document.body,
|
||||
});
|
||||
}
|
||||
|
||||
describe('ReviewLlmSuggestionPanel', () => {
|
||||
it('opens dialog with current draft value for three-way compare', async () => {
|
||||
const wrapper = mountPanel();
|
||||
await wrapper.get('ul button').trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
const dialog = document.querySelector('[data-testid="review-llm-suggestion-dialog"]');
|
||||
expect(dialog).not.toBeNull();
|
||||
expect(dialog?.getAttribute('role')).toBe('dialog');
|
||||
expect(dialog?.getAttribute('aria-modal')).toBe('true');
|
||||
expect(document.body.textContent).toContain('PO-OLD');
|
||||
expect(document.body.textContent).toContain('PO-NEW');
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('blocks submit for reject without reason and closes on Escape', async () => {
|
||||
const wrapper = mountPanel();
|
||||
await wrapper.get('ul button').trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
const radios = Array.from(document.querySelectorAll<HTMLInputElement>('input[type="radio"]'));
|
||||
const reject = radios.find((el) => el.value === 'reject');
|
||||
expect(reject).toBeTruthy();
|
||||
reject!.checked = true;
|
||||
reject!.dispatchEvent(new Event('change'));
|
||||
await flushPromises();
|
||||
|
||||
const submit = document.querySelector<HTMLButtonElement>('[data-testid="review-llm-submit-decision"]');
|
||||
expect(submit?.disabled).toBe(true);
|
||||
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
|
||||
await flushPromises();
|
||||
expect(document.querySelector('[data-testid="review-llm-suggestion-dialog"]')).toBeNull();
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('keeps validation_failed suggestions out of accept list and reject-only in dialog', async () => {
|
||||
const failed: ShippingOrderReviewLlmSuggestion = {
|
||||
suggestion_no: 'RSG-FAIL',
|
||||
field_id: 'fld-po',
|
||||
scope: 'header',
|
||||
evidence_level: 'L1_field',
|
||||
status: 'validation_failed',
|
||||
suggested_value: 'PO-BAD',
|
||||
validation_issues: [{ code: 'value_not_in_evidence', severity: 'blocking' }],
|
||||
};
|
||||
const wrapper = mountPanel({ suggestions: [failed] });
|
||||
expect(wrapper.find('ul:not([data-testid="review-llm-failed-list"])').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="review-llm-failed-list"]').exists()).toBe(true);
|
||||
|
||||
await wrapper.get('[data-testid="review-llm-open-failed"]').trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
const radios = Array.from(document.querySelectorAll<HTMLInputElement>('input[type="radio"]'));
|
||||
expect(radios.map((el) => el.value)).toEqual(['reject']);
|
||||
expect(document.body.textContent).toContain('Failed');
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,251 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewLlmSuggestionPanel.vue
|
||||
用途:复核工作台内嵌 AI 建议入口、列表与裁决触发(非顶级导航)。
|
||||
依赖:vue-i18n、ReviewLlmSuggestionDialog、ShippingOrderReview* 类型。
|
||||
逻辑:请求/裁决由父级 composable 执行;仅 validated 可接受;validation_failed 单独列表仅可拒绝;
|
||||
证据按 field_id + line_key/line_index 绑定;打开弹窗时按建议字段解析当前草稿值。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type {
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewEvidence,
|
||||
ShippingOrderReviewLlmAdjudicationPayload,
|
||||
ShippingOrderReviewLlmSuggestion,
|
||||
} from '../../types/shipping.api.types';
|
||||
import ReviewLlmSuggestionDialog from './ReviewLlmSuggestionDialog.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
activeCase?: ShippingOrderReviewCase | null;
|
||||
evidence?: ShippingOrderReviewEvidence[] | null;
|
||||
editable?: boolean;
|
||||
saving?: boolean;
|
||||
suggestions?: ShippingOrderReviewLlmSuggestion[];
|
||||
suggestionLoading?: boolean;
|
||||
focusedFieldId?: string | null;
|
||||
focusedLineKey?: string | null;
|
||||
/** 父级传入的聚焦字段草稿;弹窗优先用建议字段自身解析值。 */
|
||||
draftValue?: unknown;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
requestSuggestion: [];
|
||||
adjudicate: [payload: {
|
||||
suggestion: ShippingOrderReviewLlmSuggestion;
|
||||
body: ShippingOrderReviewLlmAdjudicationPayload;
|
||||
}];
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const dialogOpen = ref(false);
|
||||
const selected = ref<ShippingOrderReviewLlmSuggestion | null>(null);
|
||||
|
||||
/** 仅已通过逐字校验的建议可进入 accept/modify 待裁决列表。 */
|
||||
const pendingSuggestions = computed(() =>
|
||||
(props.suggestions || []).filter((item) => String(item.status || '') === 'validated' && !item.decision),
|
||||
);
|
||||
|
||||
/** 验证失败建议仅可查看/拒绝,不进入可接受列表。 */
|
||||
const failedSuggestions = computed(() =>
|
||||
(props.suggestions || []).filter((item) => String(item.status || '') === 'validation_failed' && !item.decision),
|
||||
);
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
if (props.suggestionLoading) return t('chat.shippingOrderReview.llmSuggestion.status.pending');
|
||||
const latest = (props.suggestions || [])[0];
|
||||
const code = String(latest?.status || latest?.decision || 'idle');
|
||||
const key = `chat.shippingOrderReview.llmSuggestion.status.${code}`;
|
||||
return te(key) ? t(key) : code;
|
||||
});
|
||||
|
||||
const canRequest = computed(() =>
|
||||
Boolean(props.editable && props.activeCase && props.focusedFieldId && !props.suggestionLoading && !props.saving),
|
||||
);
|
||||
|
||||
/**
|
||||
* 证据须同时匹配 field_id 与明细行(machine-N → line_index)。
|
||||
*/
|
||||
function evidenceMatchesFieldLine(
|
||||
item: ShippingOrderReviewEvidence,
|
||||
fieldId: string,
|
||||
lineKey: string | null | undefined,
|
||||
): boolean {
|
||||
if (String(item.field_id || '') !== fieldId) return false;
|
||||
const key = String(lineKey || '').trim();
|
||||
if (!key) {
|
||||
return item.line_index == null || item.line_index === undefined;
|
||||
}
|
||||
const matched = /^machine-(\d+)$/i.exec(key);
|
||||
if (matched) {
|
||||
const idx = Number(matched[1]) - 1;
|
||||
return Number(item.line_index) === idx;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const selectedEvidence = computed(() => {
|
||||
const items = props.evidence || [];
|
||||
const fieldId = String(selected.value?.field_id || props.focusedFieldId || '');
|
||||
const lineKey = selected.value?.line_key ?? props.focusedLineKey;
|
||||
return items.find((item) => evidenceMatchesFieldLine(item, fieldId, lineKey)) || null;
|
||||
});
|
||||
|
||||
/**
|
||||
* 从草稿容器读取字段当前值(人工值优先,否则机器投影)。
|
||||
*/
|
||||
function readContainerDraftValue(container: Record<string, unknown> | null | undefined, fieldId: string): unknown {
|
||||
if (!container || !fieldId) return null;
|
||||
const values = container.values as Record<string, { value?: unknown }> | undefined;
|
||||
if (values?.[fieldId] && 'value' in values[fieldId]) return values[fieldId].value ?? null;
|
||||
const machine = Array.isArray(container.machine_fields)
|
||||
? (container.machine_fields as Array<Record<string, unknown>>)
|
||||
: [];
|
||||
const hit = machine.find((item) => String(item.field_id || '') === fieldId);
|
||||
return hit?.value ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按建议(或聚焦字段)解析当前草稿值,供三方对比。
|
||||
*/
|
||||
const dialogDraftValue = computed(() => {
|
||||
const fieldId = String(selected.value?.field_id || props.focusedFieldId || '');
|
||||
const lineKey = selected.value?.line_key ?? props.focusedLineKey;
|
||||
const draft = props.activeCase?.draft;
|
||||
if (!draft || !fieldId) return props.draftValue ?? null;
|
||||
if (lineKey) {
|
||||
const lines = Array.isArray(draft.lines) ? draft.lines : [];
|
||||
const line = lines.find((item) => String((item as { line_key?: string }).line_key || '') === String(lineKey));
|
||||
return readContainerDraftValue(line as Record<string, unknown> | undefined, fieldId);
|
||||
}
|
||||
return readContainerDraftValue(draft.header_values as Record<string, unknown> | undefined, fieldId);
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开指定建议的对比裁决对话框。
|
||||
*/
|
||||
function openSuggestion(item: ShippingOrderReviewLlmSuggestion) {
|
||||
selected.value = item;
|
||||
dialogOpen.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将建议字段解析为 Schema 展示名;缺失时回退 field_id。
|
||||
*/
|
||||
function suggestionFieldLabel(item: ShippingOrderReviewLlmSuggestion): string {
|
||||
const fieldId = String(item.field_id || '').trim();
|
||||
const fields = props.activeCase?.schema?.fields || [];
|
||||
const hit = fields.find((field) => String(field.field_id || '') === fieldId);
|
||||
const name = String(hit?.display_name || hit?.field_code || '').trim();
|
||||
if (name && item.line_key) {
|
||||
return `${name} · ${item.line_key}`;
|
||||
}
|
||||
return name || fieldId || '—';
|
||||
}
|
||||
|
||||
/**
|
||||
* 将证据等级转为业务文案,避免直接展示 L1_field。
|
||||
*/
|
||||
function evidenceLevelLabel(level?: string | null): string {
|
||||
const code = String(level || 'L1_field').trim() || 'L1_field';
|
||||
const key = `chat.shippingOrderReview.llmSuggestion.evidenceLevel.${code}`;
|
||||
return te(key) ? t(key) : t('chat.shippingOrderReview.llmSuggestion.scope', { level: code });
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对话框裁决转发给父级。
|
||||
*/
|
||||
function onDecide(payload: { decision: 'accept' | 'modify' | 'reject'; reason: string; value?: unknown }) {
|
||||
if (!selected.value) return;
|
||||
emit('adjudicate', {
|
||||
suggestion: selected.value,
|
||||
body: {
|
||||
decision: payload.decision,
|
||||
reason: payload.reason || undefined,
|
||||
value: payload.value,
|
||||
expected_draft_version: props.activeCase?.draft?.draft_version,
|
||||
},
|
||||
});
|
||||
dialogOpen.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="rounded-xl border border-slate-200 bg-white p-3 text-sm shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<div class="font-semibold">{{ t('chat.shippingOrderReview.llmSuggestion.panelTitle') }}</div>
|
||||
<div class="mt-1 text-xs text-slate-500">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.panelHint') }}
|
||||
· {{ evidenceLevelLabel(selected?.evidence_level || 'L1_field') }}
|
||||
· {{ statusLabel }}
|
||||
<span v-if="suggestions?.length">· {{ suggestions.length }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded border px-2 py-1 text-xs disabled:opacity-50"
|
||||
:disabled="!canRequest"
|
||||
data-testid="review-llm-request"
|
||||
@click="emit('requestSuggestion')"
|
||||
>
|
||||
{{
|
||||
suggestionLoading
|
||||
? t('chat.shippingOrderReview.llmSuggestion.requesting')
|
||||
: t('chat.shippingOrderReview.llmSuggestion.request')
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="!pendingSuggestions.length && !failedSuggestions.length" class="mt-3 text-xs text-slate-500">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.empty') }}
|
||||
</p>
|
||||
<ul v-if="pendingSuggestions.length" class="mt-3 space-y-2">
|
||||
<li
|
||||
v-for="item in pendingSuggestions"
|
||||
:key="item.suggestion_no"
|
||||
class="flex items-center justify-between gap-2 rounded border border-slate-200 px-2 py-1.5 dark:border-slate-700"
|
||||
>
|
||||
<div class="min-w-0 truncate text-xs">
|
||||
<span class="font-medium">{{ suggestionFieldLabel(item) }}</span>
|
||||
<span class="ml-2 opacity-70">{{ item.suggested_value ?? '—' }}</span>
|
||||
</div>
|
||||
<button type="button" class="shrink-0 rounded border px-2 py-0.5 text-xs" @click="openSuggestion(item)">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.review') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<ul v-if="failedSuggestions.length" class="mt-3 space-y-2" data-testid="review-llm-failed-list">
|
||||
<li
|
||||
v-for="item in failedSuggestions"
|
||||
:key="item.suggestion_no"
|
||||
class="flex items-center justify-between gap-2 rounded border border-amber-200 bg-amber-50/50 px-2 py-1.5 dark:border-amber-900 dark:bg-amber-950/30"
|
||||
>
|
||||
<div class="min-w-0 truncate text-xs">
|
||||
<span class="font-medium">{{ suggestionFieldLabel(item) }}</span>
|
||||
<span class="ml-2 text-amber-700 dark:text-amber-300">
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.verbatimFailed') }}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded border px-2 py-0.5 text-xs"
|
||||
data-testid="review-llm-open-failed"
|
||||
@click="openSuggestion(item)"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.llmSuggestion.review') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ReviewLlmSuggestionDialog
|
||||
:open="dialogOpen"
|
||||
:suggestion="selected"
|
||||
:evidence="selectedEvidence"
|
||||
:draft-value="dialogDraftValue"
|
||||
:field-label="selected ? suggestionFieldLabel(selected) : ''"
|
||||
@close="dialogOpen = false"
|
||||
@decide="onDecide"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
+97
-37
@@ -3,7 +3,8 @@
|
||||
* features/chat/components/shipping/ShippingOrderDocumentResultItem.vue
|
||||
* 用途:渲染单个 PDF 的订单抽取结果摘要,供详情抽屉按文档逐项展示。
|
||||
* 依赖:订单抽取文档 DTO、vue-i18n。
|
||||
* 逻辑:只显示用户可理解的业务字段;reason_code 优先 i18n,缺失时对 SHIPPING_NOTICE.* 回退通用提示;人工复核由上层统一跳转。
|
||||
* 逻辑:默认只展示状态/PO/行数/阻断原因;审计与补充信息收入详情折叠;
|
||||
* 「查看证据」与「人工复核」分别携带 focus+documentId;未知原因码回退通用文案并展开技术码。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -15,9 +16,20 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
enterManualReview: [];
|
||||
enterManualReview: [payload?: { focus?: 'evidence' | 'draft'; documentId?: number }];
|
||||
}>();
|
||||
|
||||
/**
|
||||
* 向父级发出进入复核事件,并带上当前文档与入口焦点。
|
||||
* @param focus - evidence=查看证据;draft=人工复核草稿
|
||||
*/
|
||||
function emitEnterReview(focus: 'evidence' | 'draft') {
|
||||
emit('enterManualReview', {
|
||||
focus,
|
||||
documentId: Number(props.document.document_id || 0) || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
const { t, te, locale } = useI18n();
|
||||
|
||||
const statusTone = computed(() => {
|
||||
@@ -60,6 +72,13 @@ const reasonLabel = computed(() => {
|
||||
if (code.startsWith('SHIPPING_NOTICE.')) {
|
||||
return t('chat.shippingOrderExtractionTechnicalFailureUserHint');
|
||||
}
|
||||
return t('chat.shippingOrderExtractionReasonUnknown');
|
||||
});
|
||||
const reasonTechnicalCode = computed(() => {
|
||||
const code = String(props.document.reason_code || '').trim();
|
||||
if (!code) return '';
|
||||
const key = `chat.shippingOrderExtractionReason.${code}`;
|
||||
if (te(key) || code.startsWith('SHIPPING_NOTICE.')) return '';
|
||||
return code;
|
||||
});
|
||||
const emailSupplementLabel = computed(() => {
|
||||
@@ -87,6 +106,18 @@ const retryStatusLabel = computed(() => {
|
||||
const key = `chat.shippingOrderExtractionRetryStatus.${status}`;
|
||||
return status && te(key) ? t(key) : '';
|
||||
});
|
||||
const routeTypeLabel = computed(() => {
|
||||
const code = String(props.document.route_type || '').trim();
|
||||
if (!code) return '';
|
||||
const key = `chat.shippingOrderExtractionRouteType.${code}`;
|
||||
return te(key) ? t(key) : code;
|
||||
});
|
||||
const freezeSourceLabel = computed(() => {
|
||||
const code = String(props.document.freeze_source || '').trim();
|
||||
if (!code) return '';
|
||||
const key = `chat.shippingOrderExtractionFreezeSource.${code}`;
|
||||
return te(key) ? t(key) : code;
|
||||
});
|
||||
const budgetCostLabel = computed(() => {
|
||||
if (!props.document.budget_cost) return '';
|
||||
return t('chat.shippingOrderExtractionBudgetCost', {
|
||||
@@ -105,6 +136,27 @@ const canEnterManualReview = computed(() => (
|
||||
props.document.available_actions.some((action) => action === 'review_candidate' || action === 'manual_review')
|
||||
));
|
||||
const canViewEvidence = computed(() => props.document.available_actions.includes('view_evidence'));
|
||||
|
||||
const hasAuditDetails = computed(() => Boolean(
|
||||
props.document.selection_batch
|
||||
|| props.document.group_key
|
||||
|| props.document.profile
|
||||
|| routeTypeLabel.value
|
||||
|| freezeSourceLabel.value
|
||||
|| (props.document.email_supplement?.status && props.document.email_supplement.status !== 'none')
|
||||
|| emailSupplementRelations.value.length
|
||||
|| (props.document.email_supplement?.conflict_count || 0) > 0
|
||||
|| retryStatusLabel.value
|
||||
|| budgetCostLabel.value
|
||||
|| (
|
||||
props.document.email_supplement?.reservation_id_status
|
||||
&& props.document.email_supplement.reservation_id_status !== 'none'
|
||||
)
|
||||
|| (
|
||||
props.document.email_supplement?.source_type_status
|
||||
&& props.document.email_supplement.source_type_status !== 'none'
|
||||
),
|
||||
));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -125,50 +177,23 @@ const canViewEvidence = computed(() => props.document.available_actions.includes
|
||||
<div v-if="['pending', 'routing', 'matching_profile', 'extracting', 'merging_supplement'].includes(document.status) || document.activity_event_code" class="mt-1 text-xs font-medium opacity-85">
|
||||
{{ statusActivityLabel }}
|
||||
</div>
|
||||
<!-- 核心业务结果:状态时间 + PO + 行数 -->
|
||||
<div class="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs opacity-85">
|
||||
<span v-if="activityTimeLabel">{{ activityTimeLabel }}</span>
|
||||
<span v-if="document.selection_batch">
|
||||
{{ t('chat.shippingOrderExtractionSelectionBatch', { batch: document.selection_batch }) }}
|
||||
</span>
|
||||
<span v-if="document.group_key">
|
||||
{{ t('chat.shippingOrderExtractionGroupKey', { key: document.group_key }) }}
|
||||
</span>
|
||||
<span v-if="document.po_number">
|
||||
{{ t('chat.shippingOrderExtractionPoNumber', { value: document.po_number }) }}
|
||||
</span>
|
||||
<span v-if="document.line_count > 0">
|
||||
{{ t('chat.shippingOrderExtractionLineCount', { count: document.line_count }) }}
|
||||
</span>
|
||||
<span v-if="document.profile">
|
||||
{{ t('chat.shippingOrderExtractionProfileSummary', {
|
||||
name: document.profile.name || document.profile.code,
|
||||
version: document.profile.version,
|
||||
}) }}
|
||||
</span>
|
||||
<span>
|
||||
{{ emailSupplementLabel }}
|
||||
</span>
|
||||
<span>
|
||||
{{ t('chat.shippingOrderExtractionEmailSupplementField.reservation') }}{{ reservationStatusLabel }}
|
||||
</span>
|
||||
<span>
|
||||
{{ t('chat.shippingOrderExtractionEmailSupplementField.sourceType') }}{{ sourceTypeStatusLabel }}
|
||||
</span>
|
||||
<span v-for="relation in emailSupplementRelations" :key="relation">
|
||||
{{ relation }}
|
||||
</span>
|
||||
<span v-if="document.email_supplement.conflict_count > 0">
|
||||
{{ t('chat.shippingOrderExtractionEmailSupplementConflictCount', { count: document.email_supplement.conflict_count }) }}
|
||||
</span>
|
||||
<span v-if="retryStatusLabel">
|
||||
{{ retryStatusLabel }}
|
||||
</span>
|
||||
<span v-if="budgetCostLabel">
|
||||
{{ budgetCostLabel }}
|
||||
</span>
|
||||
</div>
|
||||
<!-- 异常信息 -->
|
||||
<div v-if="reasonLabel" class="mt-2 text-xs font-medium opacity-90">
|
||||
{{ reasonLabel }}
|
||||
<details v-if="reasonTechnicalCode" class="mt-1 font-normal opacity-80">
|
||||
<summary class="cursor-pointer">{{ t('chat.shippingOrderExtractionReasonTechDetails') }}</summary>
|
||||
<code class="mt-1 block break-all text-[11px]">{{ reasonTechnicalCode }}</code>
|
||||
</details>
|
||||
</div>
|
||||
<ul v-if="reviewDetails.length" class="mt-2 space-y-1 text-xs font-medium opacity-90">
|
||||
<li v-for="detail in reviewDetails" :key="`${detail.line_number}-${detail.field_code || 'general'}`">
|
||||
@@ -181,12 +206,47 @@ const canViewEvidence = computed(() => props.document.available_actions.includes
|
||||
<div v-if="document.status === 'failed'" class="mt-1 text-xs font-medium opacity-90">
|
||||
{{ t('chat.shippingOrderExtractionTechnicalFailureUserHint') }}
|
||||
</div>
|
||||
<!-- 审计/补充详情:默认折叠,降低首屏密度 -->
|
||||
<details v-if="hasAuditDetails" class="mt-2 text-xs opacity-85">
|
||||
<summary class="cursor-pointer select-none font-medium">
|
||||
{{ t('chat.shippingOrderExtractionMoreDetails') }}
|
||||
</summary>
|
||||
<div class="mt-2 flex flex-wrap gap-x-4 gap-y-1">
|
||||
<span v-if="document.selection_batch">
|
||||
{{ t('chat.shippingOrderExtractionSelectionBatch', { batch: document.selection_batch }) }}
|
||||
</span>
|
||||
<span v-if="document.group_key">
|
||||
{{ t('chat.shippingOrderExtractionGroupKey', { key: document.group_key }) }}
|
||||
</span>
|
||||
<span v-if="document.profile">
|
||||
{{ t('chat.shippingOrderExtractionProfileSummary', {
|
||||
name: document.profile.name || document.profile.code,
|
||||
version: document.profile.version,
|
||||
}) }}
|
||||
</span>
|
||||
<span v-if="routeTypeLabel">{{ routeTypeLabel }}</span>
|
||||
<span v-if="freezeSourceLabel">{{ freezeSourceLabel }}</span>
|
||||
<span>{{ emailSupplementLabel }}</span>
|
||||
<span>
|
||||
{{ t('chat.shippingOrderExtractionEmailSupplementField.reservation') }}{{ reservationStatusLabel }}
|
||||
</span>
|
||||
<span>
|
||||
{{ t('chat.shippingOrderExtractionEmailSupplementField.sourceType') }}{{ sourceTypeStatusLabel }}
|
||||
</span>
|
||||
<span v-for="relation in emailSupplementRelations" :key="relation">{{ relation }}</span>
|
||||
<span v-if="document.email_supplement.conflict_count > 0">
|
||||
{{ t('chat.shippingOrderExtractionEmailSupplementConflictCount', { count: document.email_supplement.conflict_count }) }}
|
||||
</span>
|
||||
<span v-if="retryStatusLabel">{{ retryStatusLabel }}</span>
|
||||
<span v-if="budgetCostLabel">{{ budgetCostLabel }}</span>
|
||||
</div>
|
||||
</details>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="canViewEvidence"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
@click="emit('enterManualReview')"
|
||||
@click="emitEnterReview('evidence')"
|
||||
>
|
||||
<FileText class="h-3.5 w-3.5" />
|
||||
{{ t('chat.shippingOrderExtractionAction.view_evidence') }}
|
||||
@@ -195,7 +255,7 @@ const canViewEvidence = computed(() => props.document.available_actions.includes
|
||||
v-if="canEnterManualReview"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
@click="emit('enterManualReview')"
|
||||
@click="emitEnterReview('draft')"
|
||||
>
|
||||
{{ t(`chat.shippingOrderExtractionAction.${document.available_actions.includes('review_candidate') ? 'review_candidate' : 'manual_review'}`) }}
|
||||
</button>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
|
||||
* 用途:聊天主区批次进度卡——摘要计数、Run 级处理事项、当前文件阶段、健康提醒与动作。
|
||||
* 依赖:订单抽取 Run 状态卡 DTO、orderExtractionProgressDisplay、Workflow 计数投影、vue-router、vue-i18n。
|
||||
* 依赖:订单抽取 Run 状态卡 DTO、shipping.api 文档/进度接口、ShippingOrderExtractionDetailsDrawer、
|
||||
* orderExtractionProgressDisplay、Workflow 计数投影、vue-router、vue-i18n。
|
||||
* 逻辑:有 Workflow 投影时优先展示统一 counts;否则回退 handling_items / primary_notice;
|
||||
* 右侧 ShippingWorkflowTimeline 承接逐 PDF 明细;禁止发明百分比与 ETA。
|
||||
* 「查看处理详情」挂载详情抽屉;抽屉内证据/复核入口携带 focus+document_id 打开复核页;
|
||||
* 文档与时间线加载失败支持独立就地重试;右侧 ShippingWorkflowTimeline 承接逐 PDF 明细。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, ref } from 'vue';
|
||||
@@ -14,7 +16,15 @@ import type {
|
||||
ShippingOrderExtractionHandlingItemState,
|
||||
ShippingOrderExtractionState,
|
||||
} from '../../types/chat.types';
|
||||
import type { ShippingWorkflowItemCounts } from '../../types/shipping.api.types';
|
||||
import type {
|
||||
ShippingOrderExtractionDocumentResult,
|
||||
ShippingOrderExtractionProgressEvent,
|
||||
ShippingWorkflowItemCounts,
|
||||
} from '../../types/shipping.api.types';
|
||||
import {
|
||||
listWorkspaceShippingOrderExtractionDocuments,
|
||||
listWorkspaceShippingOrderExtractionProgressEvents,
|
||||
} from '../../api/shipping.api';
|
||||
import {
|
||||
formatOrderExtractionElapsed,
|
||||
resolveOrderExtractionUserStageKey,
|
||||
@@ -25,6 +35,7 @@ import {
|
||||
type ShippingHandlingRefTarget,
|
||||
} from '../../shipping/orderExtractionHandlingRefs';
|
||||
import { SHIPPING_WORKFLOW_KEY } from '../../shipping/useShippingNoticeWorkflow';
|
||||
import ShippingOrderExtractionDetailsDrawer from './ShippingOrderExtractionDetailsDrawer.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
state: ShippingOrderExtractionState;
|
||||
@@ -49,6 +60,14 @@ const confirmCancelOpen = ref(false);
|
||||
const cancelReason = ref('');
|
||||
const injectedWorkflow = inject(SHIPPING_WORKFLOW_KEY, null);
|
||||
|
||||
const detailsOpen = ref(false);
|
||||
const detailsLoading = ref(false);
|
||||
const detailsLoadFailed = ref(false);
|
||||
const detailsDocuments = ref<ShippingOrderExtractionDocumentResult[]>([]);
|
||||
const progressLoading = ref(false);
|
||||
const progressLoadFailed = ref(false);
|
||||
const progressEvents = ref<ShippingOrderExtractionProgressEvent[]>([]);
|
||||
|
||||
/**
|
||||
* 统一计数:优先 props.workflowSummary,其次 inject 的 Workflow.counts,最后回退 Run summary。
|
||||
*/
|
||||
@@ -230,22 +249,50 @@ function handlingTitle(item: ShippingOrderExtractionHandlingItemState): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析原因码文案;未知码回退为原文。
|
||||
* 解析原因码是否已有本地化文案。
|
||||
* @param code - 原因码
|
||||
*/
|
||||
function hasReasonLabel(code: string): boolean {
|
||||
const normalized = String(code || '').trim();
|
||||
if (!normalized) return false;
|
||||
return te(`chat.shippingOrderExtractionReason.${normalized}`)
|
||||
|| te(`chat.shippingOrderExtractionHandling.reason.${normalized}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析原因码文案;未知码回退通用提示(原始码放入技术详情)。
|
||||
* @param code - 原因码
|
||||
*/
|
||||
function reasonLabel(code: string): string {
|
||||
const key = `chat.shippingOrderExtractionReason.${code}`;
|
||||
const normalized = String(code || '').trim();
|
||||
if (!normalized) return '';
|
||||
const key = `chat.shippingOrderExtractionReason.${normalized}`;
|
||||
if (te(key)) return t(key);
|
||||
const freezeKey = `chat.shippingOrderExtractionHandling.reason.${code}`;
|
||||
return te(freezeKey) ? t(freezeKey) : code;
|
||||
const freezeKey = `chat.shippingOrderExtractionHandling.reason.${normalized}`;
|
||||
return te(freezeKey) ? t(freezeKey) : t('chat.shippingOrderExtractionReasonUnknown');
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集事项中无本地化文案的原因码,供可展开技术详情展示。
|
||||
* @param item - 处理事项
|
||||
*/
|
||||
function unknownReasonCodes(item: ShippingOrderExtractionHandlingItemState): string[] {
|
||||
return (item.reasonCodes || [])
|
||||
.map((code) => String(code || '').trim())
|
||||
.filter((code) => code && !hasReasonLabel(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开订单复核工作台(Chat order-review 模式)。
|
||||
* @param options.documentId - 可选,定位到具体 PDF(由右侧 case 映射承接时仍打开 Run 复核)
|
||||
* @param options.documentId - 可选,定位到具体 PDF
|
||||
* @param options.candidateNo - 可选,写入 query 供复核页筛选
|
||||
* @param options.focus - evidence=证据区;draft=草稿复核(默认)
|
||||
*/
|
||||
async function openOrderReview(options?: { documentId?: number; candidateNo?: string }) {
|
||||
async function openOrderReview(options?: {
|
||||
documentId?: number;
|
||||
candidateNo?: string;
|
||||
focus?: 'evidence' | 'draft';
|
||||
}) {
|
||||
const runNo = String(props.runNo || '').trim();
|
||||
if (!runNo) return;
|
||||
const query: Record<string, string> = {
|
||||
@@ -259,6 +306,10 @@ async function openOrderReview(options?: { documentId?: number; candidateNo?: st
|
||||
if (candidateNo) query.candidate = candidateNo;
|
||||
const documentId = Number(options?.documentId || 0);
|
||||
if (documentId > 0) query.document_id = String(documentId);
|
||||
const focus = options?.focus === 'evidence' || options?.focus === 'draft'
|
||||
? options.focus
|
||||
: 'draft';
|
||||
query.focus = focus;
|
||||
await router.push({
|
||||
name: 'Chat',
|
||||
params: { agentId: String(route.params.agentId || '') },
|
||||
@@ -266,6 +317,89 @@ async function openOrderReview(options?: { documentId?: number; candidateNo?: st
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅重载详情抽屉的文档结果列表。
|
||||
*/
|
||||
async function loadDetailsDocuments() {
|
||||
const runNo = String(props.runNo || '').trim();
|
||||
if (!runNo) {
|
||||
detailsDocuments.value = [];
|
||||
detailsLoadFailed.value = true;
|
||||
return;
|
||||
}
|
||||
detailsLoading.value = true;
|
||||
detailsLoadFailed.value = false;
|
||||
try {
|
||||
const docsRes = await listWorkspaceShippingOrderExtractionDocuments(runNo).catch(() => null);
|
||||
if (docsRes) {
|
||||
detailsDocuments.value = Array.isArray(docsRes.items) ? docsRes.items : [];
|
||||
} else {
|
||||
detailsDocuments.value = [];
|
||||
detailsLoadFailed.value = true;
|
||||
}
|
||||
} finally {
|
||||
detailsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅重载详情抽屉的进度时间线。
|
||||
*/
|
||||
async function loadDetailsProgress() {
|
||||
const runNo = String(props.runNo || '').trim();
|
||||
if (!runNo) {
|
||||
progressEvents.value = [];
|
||||
progressLoadFailed.value = true;
|
||||
return;
|
||||
}
|
||||
progressLoading.value = true;
|
||||
progressLoadFailed.value = false;
|
||||
try {
|
||||
const eventsRes = await listWorkspaceShippingOrderExtractionProgressEvents(runNo).catch(() => null);
|
||||
if (eventsRes) {
|
||||
progressEvents.value = Array.isArray(eventsRes.items) ? eventsRes.items : [];
|
||||
} else {
|
||||
progressEvents.value = [];
|
||||
progressLoadFailed.value = true;
|
||||
}
|
||||
} finally {
|
||||
progressLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 并行加载详情抽屉所需的文档列表与进度事件。
|
||||
*/
|
||||
async function loadDetailsDrawerData() {
|
||||
await Promise.all([loadDetailsDocuments(), loadDetailsProgress()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开 Run 级处理详情抽屉(文档结果 + 进度时间线)。
|
||||
*/
|
||||
async function openDetailsDrawer() {
|
||||
detailsOpen.value = true;
|
||||
await loadDetailsDrawerData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭详情抽屉。
|
||||
*/
|
||||
function closeDetailsDrawer() {
|
||||
detailsOpen.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从详情抽屉进入复核/证据页。
|
||||
*/
|
||||
async function enterReviewFromDetails(payload?: { focus?: 'evidence' | 'draft'; documentId?: number }) {
|
||||
await openOrderReview({
|
||||
documentId: payload?.documentId,
|
||||
focus: payload?.focus === 'evidence' ? 'evidence' : 'draft',
|
||||
});
|
||||
closeDetailsDrawer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开任务工作台,定位自动冻结受阻等任务号。
|
||||
*/
|
||||
@@ -290,6 +424,7 @@ async function openAffectedRef(target: ShippingHandlingRefTarget) {
|
||||
await openOrderReview({
|
||||
documentId: target.documentId,
|
||||
candidateNo: target.candidateNo,
|
||||
focus: 'draft',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -316,12 +451,12 @@ async function handleHandlingAction(item: ShippingOrderExtractionHandlingItemSta
|
||||
await openAffectedRef(first.target);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
action === 'enter_manual_review'
|
||||
|| action === 'review_candidate'
|
||||
|| action === 'view_details'
|
||||
) {
|
||||
await openOrderReview();
|
||||
if (action === 'view_details') {
|
||||
await openDetailsDrawer();
|
||||
return;
|
||||
}
|
||||
if (action === 'enter_manual_review' || action === 'review_candidate') {
|
||||
await openOrderReview({ focus: 'draft' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,6 +569,18 @@ function openCancelConfirm() {
|
||||
<div v-if="item.reasonCodes.length" class="mt-1 opacity-80">
|
||||
{{ t('chat.shippingOrderExtractionHandling.reasonPrefix') }}
|
||||
{{ item.reasonCodes.slice(0, 4).map(reasonLabel).join(';') }}
|
||||
<details
|
||||
v-if="unknownReasonCodes(item).length"
|
||||
class="mt-1"
|
||||
data-testid="shipping-order-extraction-reason-tech"
|
||||
>
|
||||
<summary class="cursor-pointer opacity-90">
|
||||
{{ t('chat.shippingOrderExtractionReasonTechDetails') }}
|
||||
</summary>
|
||||
<code class="mt-1 block break-all text-[11px]">
|
||||
{{ unknownReasonCodes(item).join(', ') }}
|
||||
</code>
|
||||
</details>
|
||||
</div>
|
||||
<div
|
||||
v-if="affectedRows(item).length"
|
||||
@@ -511,6 +658,15 @@ function openCancelConfirm() {
|
||||
</div>
|
||||
|
||||
<div v-else class="mt-2 flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="String(props.runNo || '').trim()"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
data-testid="shipping-order-extraction-view-details"
|
||||
@click="openDetailsDrawer"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionAction.view_details') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showRefresh"
|
||||
type="button"
|
||||
@@ -545,5 +701,20 @@ function openCancelConfirm() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ShippingOrderExtractionDetailsDrawer
|
||||
:open="detailsOpen"
|
||||
:state="state"
|
||||
:documents="detailsDocuments"
|
||||
:progress-events="progressEvents"
|
||||
:loading="detailsLoading"
|
||||
:load-failed="detailsLoadFailed"
|
||||
:progress-loading="progressLoading"
|
||||
:progress-load-failed="progressLoadFailed"
|
||||
@close="closeDetailsDrawer"
|
||||
@enter-manual-review="enterReviewFromDetails"
|
||||
@retry-documents="loadDetailsDocuments"
|
||||
@retry-progress="loadDetailsProgress"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
+148
-27
@@ -3,9 +3,11 @@
|
||||
* features/chat/components/shipping/ShippingOrderExtractionDetailsDrawer.vue
|
||||
* 用途:以抽屉形式展示一次订单抽取 Run 的按 PDF 归并详情和事实时间线。
|
||||
* 依赖:订单抽取状态卡、文档结果项、订单抽取 progress-events DTO、vue-i18n。
|
||||
* 逻辑:聊天摘要卡只显示概览;需要查看逐文档结果和每轮事件原因时由本抽屉承接新的 Run 级事实时间线。
|
||||
* 逻辑:聊天摘要卡只显示概览;需要查看逐文档结果和每轮事件原因时由本抽屉承接;
|
||||
* 以模态对话框语义呈现(初始焦点、Tab 陷阱、Escape/关闭后焦点恢复);
|
||||
* 文档与时间线加载失败分别提供就地重试。
|
||||
*/
|
||||
import { onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { X } from 'lucide-vue-next';
|
||||
import type { ShippingOrderExtractionState } from '../../types/chat.types';
|
||||
@@ -29,20 +31,33 @@ const props = defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
enterManualReview: [];
|
||||
enterManualReview: [payload?: { focus?: 'evidence' | 'draft'; documentId?: number }];
|
||||
retryDocuments: [];
|
||||
retryProgress: [];
|
||||
}>();
|
||||
|
||||
const { t, te, locale } = useI18n();
|
||||
let removeKeydownListener: (() => void) | null = null;
|
||||
const panelRef = ref<HTMLElement | null>(null);
|
||||
const closeButtonRef = ref<HTMLButtonElement | null>(null);
|
||||
let previouslyFocused: HTMLElement | null = null;
|
||||
const timelineOpen = ref(false);
|
||||
|
||||
const FOCUSABLE_SELECTOR = [
|
||||
'a[href]',
|
||||
'button:not([disabled])',
|
||||
'textarea:not([disabled])',
|
||||
'input:not([disabled])',
|
||||
'select:not([disabled])',
|
||||
'[tabindex]:not([tabindex="-1"])',
|
||||
].join(',');
|
||||
|
||||
const translateReasonCodes = (codes: string[] | undefined): string[] => (
|
||||
(codes || [])
|
||||
.map((code) => {
|
||||
const normalized = String(code || '').trim();
|
||||
if (!normalized) return '';
|
||||
const key = `chat.shippingOrderExtractionReason.${normalized}`;
|
||||
return te(key) ? t(key) : normalized;
|
||||
return te(key) ? t(key) : t('chat.shippingOrderExtractionReasonUnknown');
|
||||
})
|
||||
.filter(Boolean)
|
||||
);
|
||||
@@ -88,22 +103,79 @@ const eventContextLabel = (event: ShippingOrderExtractionProgressEvent): string
|
||||
const eventCategoryKey = (event: ShippingOrderExtractionProgressEvent): string =>
|
||||
`chat.shippingOrderExtractionTimelineTag.${classifyOrderExtractionTimelineEvent(event)}`;
|
||||
|
||||
/** 收集抽屉内可聚焦控件。 */
|
||||
function focusableNodes(): HTMLElement[] {
|
||||
if (!panelRef.value) return [];
|
||||
return Array.from(panelRef.value.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR))
|
||||
.filter((node) => !node.hasAttribute('disabled') && node.getAttribute('aria-hidden') !== 'true');
|
||||
}
|
||||
|
||||
/** 关闭抽屉。 */
|
||||
function handleClose(): void {
|
||||
emit('close');
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape 关闭;Tab 在抽屉内循环,阻止焦点逃逸到背景页。
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
if (!props.open) return;
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
handleClose();
|
||||
return;
|
||||
}
|
||||
if (event.key !== 'Tab') return;
|
||||
const nodes = focusableNodes();
|
||||
const first = nodes[0];
|
||||
const last = nodes[nodes.length - 1];
|
||||
if (!first || !last) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
const active = document.activeElement as HTMLElement | null;
|
||||
const inside = Boolean(active && panelRef.value?.contains(active));
|
||||
if (event.shiftKey) {
|
||||
if (!inside || active === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!inside || active === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
removeKeydownListener?.();
|
||||
removeKeydownListener = null;
|
||||
if (!open) return;
|
||||
const handleKeydown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') emit('close');
|
||||
};
|
||||
window.addEventListener('keydown', handleKeydown);
|
||||
removeKeydownListener = () => window.removeEventListener('keydown', handleKeydown);
|
||||
async (open, wasOpen) => {
|
||||
if (typeof document === 'undefined') return;
|
||||
if (open && !wasOpen) {
|
||||
previouslyFocused = document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
: null;
|
||||
document.addEventListener('keydown', onKeydown, true);
|
||||
await nextTick();
|
||||
(closeButtonRef.value || focusableNodes()[0])?.focus();
|
||||
return;
|
||||
}
|
||||
if (!open && wasOpen) {
|
||||
document.removeEventListener('keydown', onKeydown, true);
|
||||
const restoreTarget = previouslyFocused;
|
||||
previouslyFocused = null;
|
||||
await nextTick();
|
||||
restoreTarget?.focus?.();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
removeKeydownListener?.();
|
||||
if (typeof document !== 'undefined') {
|
||||
document.removeEventListener('keydown', onKeydown, true);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -112,9 +184,11 @@ onBeforeUnmount(() => {
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex justify-end bg-slate-950/40"
|
||||
@click.self="emit('close')"
|
||||
data-testid="shipping-order-extraction-details-drawer"
|
||||
@click.self="handleClose"
|
||||
>
|
||||
<aside
|
||||
ref="panelRef"
|
||||
class="flex h-full w-full max-w-[560px] flex-col bg-white shadow-2xl dark:bg-slate-900"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
@@ -145,10 +219,12 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
ref="closeButtonRef"
|
||||
type="button"
|
||||
class="rounded-md p-1 text-slate-500 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-slate-100"
|
||||
:aria-label="t('chat.shippingOrderExtractionCloseDetails')"
|
||||
@click="emit('close')"
|
||||
data-testid="shipping-order-extraction-details-close"
|
||||
@click="handleClose"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
@@ -158,8 +234,20 @@ onBeforeUnmount(() => {
|
||||
<div v-if="loading" class="rounded-lg border border-dashed border-slate-300 px-3 py-4 text-sm text-slate-600 dark:border-slate-700 dark:text-slate-300">
|
||||
{{ t('chat.shippingOrderExtractionDocumentsLoading') }}
|
||||
</div>
|
||||
<div v-else-if="loadFailed" class="rounded-lg border border-amber-300 bg-amber-50 px-3 py-4 text-sm text-amber-900 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-100">
|
||||
{{ t('chat.shippingOrderExtractionDocumentsUnavailable') }}
|
||||
<div
|
||||
v-else-if="loadFailed"
|
||||
class="rounded-lg border border-amber-300 bg-amber-50 px-3 py-4 text-sm text-amber-900 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-100"
|
||||
data-testid="shipping-order-extraction-documents-failed"
|
||||
>
|
||||
<p>{{ t('chat.shippingOrderExtractionDocumentsUnavailable') }}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-2 rounded-md border border-current/30 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
data-testid="shipping-order-extraction-documents-retry"
|
||||
@click="emit('retryDocuments')"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionDetailsRetry') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else-if="documents.length === 0" class="rounded-lg border border-dashed border-slate-300 px-3 py-4 text-sm text-slate-600 dark:border-slate-700 dark:text-slate-300">
|
||||
{{ t('chat.shippingOrderExtractionNoDocuments') }}
|
||||
@@ -168,14 +256,38 @@ onBeforeUnmount(() => {
|
||||
v-for="document in documents"
|
||||
:key="document.unit_id"
|
||||
:document="document"
|
||||
@enter-manual-review="emit('enterManualReview')"
|
||||
@enter-manual-review="(payload) => emit('enterManualReview', payload)"
|
||||
/>
|
||||
<details :open="timelineOpen" class="rounded-lg border border-slate-200 bg-white px-3 py-3 dark:border-slate-700 dark:bg-slate-950/40" @toggle="timelineOpen = ($event.currentTarget as HTMLDetailsElement).open">
|
||||
<summary class="cursor-pointer text-xs font-semibold text-slate-900 dark:text-slate-100">{{ t('chat.shippingOrderExtractionTimelineTitle') }}</summary>
|
||||
<div v-if="state.selectionPlan?.totalAttachmentCount || state.unitSummary?.technicalFailureReasonCodes?.length" class="mt-3 rounded-lg bg-slate-50 px-3 py-3 text-xs text-slate-700 dark:bg-slate-900/60 dark:text-slate-200">
|
||||
<div v-if="state.selectionPlan?.totalAttachmentCount">{{ t('chat.shippingOrderExtractionPlanSummary', { total: state.selectionPlan.totalAttachmentCount, groups: state.selectionPlan.groupCount || 0, attachments: state.selectionPlan.maxInitialAttachments || 0, concurrency: state.selectionPlan.maxInitialConcurrency || 0 }) }}</div>
|
||||
<div v-if="state.unitSummary?.reviewRequiredReasonCodes?.length" class="mt-1">{{ t('chat.shippingOrderExtractionReviewReasonCodes', { codes: translateReasonCodes(state.unitSummary.reviewRequiredReasonCodes).join(' / ') }) }}</div>
|
||||
<div v-if="state.unitSummary?.technicalFailureReasonCodes?.length" class="mt-1">{{ t('chat.shippingOrderExtractionTechnicalFailureCodes', { codes: state.unitSummary.technicalFailureReasonCodes.join(', ') }) }}</div>
|
||||
<details
|
||||
:open="timelineOpen"
|
||||
class="rounded-lg border border-slate-200 bg-white px-3 py-3 dark:border-slate-700 dark:bg-slate-950/40"
|
||||
@toggle="timelineOpen = ($event.currentTarget as HTMLDetailsElement).open"
|
||||
>
|
||||
<summary class="cursor-pointer text-xs font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ t('chat.shippingOrderExtractionTimelineTitle') }}
|
||||
</summary>
|
||||
<div
|
||||
v-if="state.selectionPlan?.totalAttachmentCount || state.unitSummary?.technicalFailureReasonCodes?.length"
|
||||
class="mt-3 rounded-lg bg-slate-50 px-3 py-3 text-xs text-slate-700 dark:bg-slate-900/60 dark:text-slate-200"
|
||||
>
|
||||
<div v-if="state.selectionPlan?.totalAttachmentCount">
|
||||
{{ t('chat.shippingOrderExtractionPlanSummary', {
|
||||
total: state.selectionPlan.totalAttachmentCount,
|
||||
groups: state.selectionPlan.groupCount || 0,
|
||||
attachments: state.selectionPlan.maxInitialAttachments || 0,
|
||||
concurrency: state.selectionPlan.maxInitialConcurrency || 0,
|
||||
}) }}
|
||||
</div>
|
||||
<div v-if="state.unitSummary?.reviewRequiredReasonCodes?.length" class="mt-1">
|
||||
{{ t('chat.shippingOrderExtractionReviewReasonCodes', {
|
||||
codes: translateReasonCodes(state.unitSummary.reviewRequiredReasonCodes).join(' / '),
|
||||
}) }}
|
||||
</div>
|
||||
<div v-if="state.unitSummary?.technicalFailureReasonCodes?.length" class="mt-1">
|
||||
{{ t('chat.shippingOrderExtractionTechnicalFailureCodes', {
|
||||
codes: state.unitSummary.technicalFailureReasonCodes.join(', '),
|
||||
}) }}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="progressLoading"
|
||||
@@ -186,8 +298,17 @@ onBeforeUnmount(() => {
|
||||
<div
|
||||
v-else-if="progressLoadFailed"
|
||||
class="mt-2 text-sm text-amber-700 dark:text-amber-200"
|
||||
data-testid="shipping-order-extraction-timeline-failed"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionTimelineUnavailable') }}
|
||||
<p>{{ t('chat.shippingOrderExtractionTimelineUnavailable') }}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-2 rounded-md border border-current/30 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
data-testid="shipping-order-extraction-timeline-retry"
|
||||
@click="emit('retryProgress')"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionDetailsRetry') }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="progressEvents.length === 0"
|
||||
|
||||
+24
-1
@@ -75,7 +75,12 @@ describe('ShippingWorkflowItemDetailDrawer', () => {
|
||||
const wrapper = mount(ShippingWorkflowItemDetailDrawer, {
|
||||
props: {
|
||||
open: true,
|
||||
item: buildItem({ lifecycle_status: 'failed', current_document_filename: 'fail.pdf' }),
|
||||
item: buildItem({
|
||||
lifecycle_status: 'failed',
|
||||
current_document_filename: 'fail.pdf',
|
||||
available_actions: ['cancel', 'reparse'],
|
||||
reparse_kind: 'failed_run_retry',
|
||||
}),
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
attachTo: document.body,
|
||||
@@ -90,6 +95,24 @@ describe('ShippingWorkflowItemDetailDrawer', () => {
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('hides reparse for pending_review without case contract', async () => {
|
||||
const wrapper = mount(ShippingWorkflowItemDetailDrawer, {
|
||||
props: {
|
||||
open: true,
|
||||
item: buildItem({
|
||||
lifecycle_status: 'pending_review',
|
||||
current_case_no: null,
|
||||
available_actions: ['cancel'],
|
||||
reparse_kind: null,
|
||||
}),
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
attachTo: document.body,
|
||||
});
|
||||
expect(drawerRoot()?.querySelector('[data-testid="shipping-workflow-item-drawer-reparse"]')).toBeNull();
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('hides cancel for closed items and emits close', async () => {
|
||||
const wrapper = mount(ShippingWorkflowItemDetailDrawer, {
|
||||
props: {
|
||||
|
||||
+16
-5
@@ -3,8 +3,8 @@
|
||||
* 用途:单个 WorkflowItem(PDF)详情抽屉——文件名、阶段、事件时间线、取消/重识别入口。
|
||||
* 依赖:vue-i18n、ShippingWorkflowItem / Event 类型、lucide-vue-next。
|
||||
* 逻辑:由 ShippingWorkflowTimeline 打开;展示 filename / current_stage / events;
|
||||
* 取消与重识别仅 emit,由父级用应用内原因弹窗收集;禁止发明百分比与 ETA。
|
||||
* 以模态对话框语义呈现:初始焦点、Tab 陷阱、Escape/关闭后焦点恢复。
|
||||
* 取消与重识别以后端 available_actions 为准,仅 emit 由父级收集原因;
|
||||
* 禁止发明百分比与 ETA。以模态对话框语义呈现:初始焦点、Tab 陷阱、Escape/关闭后焦点恢复。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
@@ -45,13 +45,24 @@ const events = computed((): ShippingWorkflowEvent[] => (
|
||||
));
|
||||
|
||||
const canCancel = computed(() => {
|
||||
const actions = props.item?.available_actions;
|
||||
if (Array.isArray(actions)) return actions.includes('cancel');
|
||||
const status = String(props.item?.lifecycle_status || '').trim();
|
||||
return Boolean(props.item) && !['closed', 'cancelled'].includes(status);
|
||||
});
|
||||
|
||||
const canReparse = computed(() => {
|
||||
const status = String(props.item?.lifecycle_status || '').trim();
|
||||
return Boolean(props.item) && ['failed', 'reparse_failed', 'pending_review'].includes(status);
|
||||
const actions = props.item?.available_actions;
|
||||
if (Array.isArray(actions)) return actions.includes('reparse');
|
||||
// 无契约时 fail-closed,禁止仅凭 pending_review 展示。
|
||||
return false;
|
||||
});
|
||||
|
||||
const reparseActionLabel = computed(() => {
|
||||
if (props.item?.reparse_kind === 'failed_run_retry') {
|
||||
return t('chat.shippingWorkflow.actions.retryFailedRun');
|
||||
}
|
||||
return t('chat.shippingWorkflow.actions.reparse');
|
||||
});
|
||||
|
||||
const filename = computed(() => {
|
||||
@@ -293,7 +304,7 @@ onBeforeUnmount(() => {
|
||||
data-testid="shipping-workflow-item-drawer-reparse"
|
||||
@click="emit('reparse', item)"
|
||||
>
|
||||
{{ t('chat.shippingWorkflow.actions.reparse') }}
|
||||
{{ reparseActionLabel }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canCancel"
|
||||
|
||||
@@ -211,7 +211,13 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
|
||||
it('shows reparse action for failed items', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({ item_no: 'SWI-FAIL', lifecycle_status: 'failed', current_document_filename: 'bad.pdf' }),
|
||||
buildItem({
|
||||
item_no: 'SWI-FAIL',
|
||||
lifecycle_status: 'failed',
|
||||
current_document_filename: 'bad.pdf',
|
||||
available_actions: ['cancel', 'reparse'],
|
||||
reparse_kind: 'failed_run_retry',
|
||||
}),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
@@ -219,5 +225,24 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('重试失败识别');
|
||||
});
|
||||
|
||||
it('hides reparse for pending_review without available_actions.reparse', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({
|
||||
item_no: 'SWI-PR',
|
||||
lifecycle_status: 'pending_review',
|
||||
current_case_no: null,
|
||||
available_actions: ['cancel'],
|
||||
reparse_kind: null,
|
||||
}),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -111,7 +111,6 @@ const ACTIONABLE_FILTER_STATUSES = new Set([
|
||||
'queued',
|
||||
'manual_upload_pending',
|
||||
]);
|
||||
const REPARSE_STATUSES = new Set(['failed', 'reparse_failed', 'pending_review']);
|
||||
|
||||
/**
|
||||
* 将 Item 归入展示分组。
|
||||
@@ -128,17 +127,32 @@ function resolveGroup(item: ShippingWorkflowItem): ItemGroupKey {
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许取消(非 closed/cancelled)。
|
||||
* 是否允许取消:优先后端 available_actions,否则回退非终态。
|
||||
*/
|
||||
function canCancel(item: ShippingWorkflowItem): boolean {
|
||||
const actions = item.available_actions;
|
||||
if (Array.isArray(actions)) return actions.includes('cancel');
|
||||
return !COMPLETED_STATUSES.has(String(item.lifecycle_status || '').trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许重试/重新识别。
|
||||
* 是否允许重试/重新识别:必须以后端 available_actions 为准。
|
||||
*/
|
||||
function canReparse(item: ShippingWorkflowItem): boolean {
|
||||
return REPARSE_STATUSES.has(String(item.lifecycle_status || '').trim());
|
||||
const actions = item.available_actions;
|
||||
if (Array.isArray(actions)) return actions.includes('reparse');
|
||||
// 无契约时 fail-closed:禁止仅凭 pending_review 展示(会稳定触发 CASE_REQUIRED)。
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重识别按钮文案:区分 Case 新版本与失败 Run 重试。
|
||||
*/
|
||||
function reparseActionLabel(item: ShippingWorkflowItem): string {
|
||||
if (item.reparse_kind === 'failed_run_retry') {
|
||||
return t('chat.shippingWorkflow.actions.retryFailedRun');
|
||||
}
|
||||
return t('chat.shippingWorkflow.actions.reparse');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,6 +313,9 @@ async function onReasonConfirm(payload: { reason: string; comment?: string }) {
|
||||
detailItem.value = null;
|
||||
}
|
||||
} catch (err) {
|
||||
// 失败时关闭原因确认框,避免与错误提示双遮罩。
|
||||
reasonDialogOpen.value = false;
|
||||
reasonDialogItem.value = null;
|
||||
const message = err instanceof BusinessError ? err.message : t('errors.generic');
|
||||
msg.error(message);
|
||||
} finally {
|
||||
@@ -528,7 +545,7 @@ watch(
|
||||
data-testid="shipping-workflow-action-reparse"
|
||||
@click="openReparseDialog(item)"
|
||||
>
|
||||
{{ t('chat.shippingWorkflow.actions.reparse') }}
|
||||
{{ reparseActionLabel(item) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canCancel(item)"
|
||||
|
||||
Reference in new issue
Block a user