feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码

This commit is contained in:
hugo committed 2026-08-23 00:27:18 +08:00
1 parent 935bf26fa6
commit 7cfd5d167e
230 files changed
+9337 -10989

No files matched your search

@@ -33,7 +33,7 @@ const i18n = createI18n({
},
chat: {
shippingOrderReview: {
saveOrderAndValidate: '保存订单并校验',
saveOrderAndValidate: '提交订单',
currentProcessing: {
waitingStart: '等待系统启动',
},
@@ -69,7 +69,10 @@ describe('ReviewCurrentProcessingCard', () => {
it('keeps the retry action for retryable states', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: { stageCode: 'inventory_preparation', userStatus: 'retryable', retryable: true },
props: {
stageCode: 'inventory_preparation', userStatus: 'retryable', retryable: true,
primaryAction: { code: 'retry_inventory_preparation', i18nKey: 'workspace.shippingNotice.processGate.inventoryActions.retryInventoryPreparation' },
},
global: { plugins: [i18n] },
});
@@ -104,7 +107,7 @@ describe('ReviewCurrentProcessingCard', () => {
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').text()).toBe('重新库存匹配');
expect(wrapper.find('[data-testid="review-current-processing-retry"]').text()).toBe('重新库存匹配');
});
it('does not render save and validate as a current-task action', () => {
@@ -116,9 +119,9 @@ describe('ReviewCurrentProcessingCard', () => {
global: { plugins: [i18n] },
});
// 保存订单并校验是底栏唯一动作;未提交校验必须给出明确交接提示,不能显示系统处理中。
// 提交订单是底栏唯一动作;未提交前必须给出明确交接提示,不能显示系统处理中。
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()).toBe('保存订单并校验');
expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()).toBe('提交订单');
});
it('labels an unqueued automatic Gate as waiting for system start', () => {
@@ -207,7 +210,7 @@ describe('ReviewCurrentProcessingCard', () => {
global: { plugins: [i18n] },
});
await wrapper.get('[data-testid="review-current-task-primary-action"]').trigger('click');
await wrapper.get('[data-testid="review-current-processing-retry"]').trigger('click');
await wrapper.get('[data-testid="review-current-task-recovery-retry_inventory_preparation"]').trigger('click');
// 两个稳定 action 码分别进入 Gate API:重匹配不可误触 RPA,重新获取库存才会触发 RPA。
@@ -62,7 +62,6 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
retry: [];
locate: [lineKey?: string | null, fieldId?: string | null];
action: [code: string, parameters?: Record<string, unknown>];
}>();
@@ -219,8 +218,7 @@ function isNonTaskCapabilityAction(code: string): boolean {
}
/**
* 业务动作按钮:后端确认 retryable=true → 主按钮为「重试」;
* 否则若 primary_action.code 非 retry 且不是工作台内自跳转 → 渲染对应人工动作。
* 业务动作按钮只消费 primary_action;retryable 是状态,不是授权。
*/
const showBusinessAction = computed(() => {
if (props.loading) return false;
@@ -228,13 +226,12 @@ const showBusinessAction = computed(() => {
// [STEP] 自动处理期间没有人工业务动作;只保留外层的刷新进度入口。
// 防止正式任务编辑等历史 primary_action 穿透到库存获取运行态。
if (props.userStatus === 'running') return false;
if (props.retryable) return true;
const code = String(props.primaryAction?.code || '').trim();
if (isInternalInventoryAction(code)) return false;
if (!code) return false;
if (isNonTaskCapabilityAction(code)) return false;
if (isHiddenWorkbenchNavigationAction(code)) return false;
// retry 仅当 retryable=true 时展示(避免按钮闪烁矛盾)
// 无对象边界的泛化 retry 永不展示。
if (code === 'retry') return false;
return true;
});
@@ -243,7 +240,6 @@ const businessActionLabel = computed(() => {
const code = String(props.primaryAction?.code || '').trim();
const inventoryKey = inventoryActionLabelKey(code);
if (inventoryKey && te(inventoryKey)) return t(inventoryKey);
if (props.retryable) return t('chat.shippingOrderReview.currentTask.actionRetry');
const pa = props.primaryAction;
if (!pa) return '';
if (isNonTaskCapabilityAction(String(pa.code || ''))) return '';
@@ -257,11 +253,6 @@ const businessActionLabel = computed(() => {
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);
}
// 当前任务按钮没有受控文案时 fail-closed,禁止泄漏内部 action code。
return '';
});
@@ -274,7 +265,7 @@ const businessActionTitle = computed(() => {
return '';
});
const actionIsRetry = computed(() => Boolean(props.retryable) || String(props.primaryAction?.code || '') === 'retry');
const actionIsRetry = computed(() => String(props.primaryAction?.code || '').trim().startsWith('retry_'));
const actionIsInventoryRpa = computed(() => String(props.primaryAction?.code || '').trim() === 'retry_inventory_preparation');
const recoveryActions = computed(() => (props.recoveryActions || []).filter((action) => {
const code = String(action.code || '').trim();
@@ -301,14 +292,7 @@ function recoveryActionLabel(action: (typeof recoveryActions.value)[number]): st
function handleBusinessActionClick() {
const primaryActionCode = String(props.primaryAction?.code || '').trim();
if (props.retryable && primaryActionCode && primaryActionCode !== 'retry') {
emit('action', primaryActionCode, props.primaryAction?.parameters ?? {});
return;
}
if (actionIsRetry.value) {
emit('retry');
return;
}
if (!primaryActionCode || primaryActionCode === 'retry') return;
emit('action', primaryActionCode, props.primaryAction?.parameters ?? {});
}
@@ -31,7 +31,8 @@ const i18n = createI18n({
customValue: '手工值', customPlaceholder: '请输入', submitCustom: '确认手工值',
resolveReason: '人工裁决', resolveFailed: '提交失败', resolveSuccess: '已处理',
fields: { part_number: '料号' }, reasons: { field_conflict: '字段冲突' },
evidenceRole: {}, optionLabel: '候选 {index}', adoptOption: '采用候选值',
evidenceRole: {}, recoveryAction: { reparse_current_pdf: '建议操作:重新识别此 PDF' },
optionLabel: '候选 {index}', adoptOption: '采用候选值',
},
resume: { autoCreated: '已自动建单', waitingManualConfirm: '待人工确认' },
} },
@@ -57,6 +58,20 @@ describe('ReviewFieldConflictPanel', () => {
expect(wrapper.find('[data-testid="review-field-conflict-custom-toggle"]').exists()).toBe(false);
});
it('shows the server-provided recovery action for a historical evidence gap', () => {
const wrapper = mount(ReviewFieldConflictPanel, {
props: {
caseNo: 'SORC-1', draftVersion: 1, editable: true, conflicts: [],
evidenceIssues: [{
conflict_key: '-1:unit_price', field_code: 'unit_price', reason: 'supplement_conflict_evidence_insufficient',
options: [], recovery_action: 'reparse_current_pdf',
}],
},
global: { plugins: [i18n] },
});
expect(wrapper.get('[data-testid="review-evidence-issue-recovery-action"]').text()).toContain('重新识别此 PDF');
});
it('refreshes the case when confirming a stale manual value returns conflict-not-found', async () => {
resolveFieldConflict.mockRejectedValueOnce(new BusinessError({
message: 'Field conflict not found',
@@ -73,6 +73,16 @@ function evidenceRoleLabel(role: string | undefined | null): string {
return te(key) ? t(key) : code;
}
/**
* 显示服务端指定的恢复动作;页面只解释并复用既有顶部操作,不自行发起重识别。
*/
function recoveryActionLabel(action: string | undefined | null): string {
const code = String(action || '').trim();
if (!code) return '';
const key = `chat.shippingOrderReview.fieldConflict.recoveryAction.${code}`;
return te(key) ? t(key) : code;
}
/**
* 定位冲突字段到草稿/证据区。
*/
@@ -311,6 +321,13 @@ async function submitCustom(conflict: ShippingOrderReviewFieldConflict) {
<span class="text-muted">{{ scopeLabel(issue.scope) }} · </span>
<span class="font-mono">{{ fieldLabel(issue.field_code) }}</span>
</span>
<span
v-if="recoveryActionLabel(issue.recovery_action)"
class="text-[11px] text-amber-800 dark:text-amber-200"
data-testid="review-evidence-issue-recovery-action"
>
{{ recoveryActionLabel(issue.recovery_action) }}
</span>
<button
type="button"
class="text-[11px] text-primary underline-offset-2 hover:underline"
@@ -2,7 +2,7 @@
* features/chat/components/shipping-review/ReviewWorkbenchFooter.spec.ts
* 用途:验证字段冲突的 Gate 主动作只由右栏当前任务卡承载,底栏不得重复展示。
* 依赖:Vitest、Vue Test Utils、Vue I18n、ReviewWorkbenchFooter。
* 逻辑:订单复核底栏只保留保存校验,不展示已由当前任务卡或阶段页承载的流程动作。
* 逻辑:订单复核底栏只保留提交订单,不展示已由当前任务卡或阶段页承载的流程动作。
*/
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
@@ -16,7 +16,11 @@ const i18n = createI18n({
'zh-CN': {
chat: {
shippingProcessing: { action: { resolve_field_conflicts: '处理字段冲突', view_result: '查看结果', none: '无操作' } },
shippingOrderReview: { unsavedSwitch: { unsavedCount: '未保存 {count} 项' } },
shippingOrderReview: {
saveOrderAndValidate: '提交订单',
submitOrderHint: '提交后自动校验,满足条件将自动建单。',
unsavedSwitch: { unsavedCount: '未保存 {count} 项' },
},
},
workspace: { shippingNotice: { processGate: { actions: {} } } },
},
@@ -59,4 +63,17 @@ describe('ReviewWorkbenchFooter', () => {
expect(wrapper.find('[data-testid="review-footer-flow-resolve_field_conflicts"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-footer-flow-view_result"]').exists()).toBe(false);
});
it('uses submit-order wording and explains the automatic creation policy', () => {
const wrapper = mount(ReviewWorkbenchFooter, {
props: {
availableActions: ['validate'], canConfirmBuild: false, saving: false, isReadOnly: false, hasDraft: true,
},
global: { plugins: [i18n] },
});
// 关键断言:唯一写入口完成提交语义;资格通过后的自动建单是系统行为,不要求第二次确认。
expect(wrapper.text()).toContain('提交订单');
expect(wrapper.get('[data-testid="review-submit-order-hint"]').text()).toBe('提交后自动校验,满足条件将自动建单。');
});
});
@@ -3,7 +3,7 @@
用途:订单处理工作台底部唯一写操作栏(处置 / 保存 / 统一流程动作)。
依赖:vue-i18n、lucide-vue-next、ActionPresentation。
逻辑:ShippingOrderReviewView 传入 available_actions 与流程动作投影;sticky bottom;
订单复核只保留保存校验;流程动作由所属阶段或当前任务卡承载;写按钮受 actionsExecutable 约束;
订单复核只保留提交订单;流程动作由所属阶段或当前任务卡承载;写按钮受 actionsExecutable 约束;
流程写操作经 flow-action emit(与 Resolver 同链);flowBusy||saving 时禁用。
-->
<script setup lang="ts">
@@ -76,7 +76,7 @@ function hasAction(action: string): boolean {
/**
* 订单复核底栏不承载流程投影动作。
*
* 核心逻辑:保存并校验是表单级提交,固定放在这里;字段裁决、重试、查看结果等
* 核心逻辑:提交订单是表单级提交,固定放在这里;字段裁决、重试、查看结果等
* Case/阶段级动作必须留在其业务上下文中,避免同一动作在顶栏、右栏和底栏重复出现。
*/
const footerFlowItems = computed((): ActionPresentationItem[] => []);
@@ -180,6 +180,13 @@ const canWriteCaseActions = computed(() => props.actionsExecutable && !props.isR
>
<Save class="h-4 w-4" />{{ t('chat.shippingOrderReview.saveOrderAndValidate') }}
</button>
<p
v-if="showValidate && hasAction('validate')"
class="basis-full text-right text-xs text-muted"
data-testid="review-submit-order-hint"
>
{{ t('chat.shippingOrderReview.submitOrderHint') }}
</p>
</template>
</div>
</footer>