feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
+167
@@ -0,0 +1,167 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewBuildEligibilityPanel.vue
|
||||
用途:展示建单前资格摘要(can_build、阻断原因、行级 Reservation 与库存候选)。
|
||||
依赖:vue-i18n、ShippingOrderReviewBuildEligibility 类型。
|
||||
逻辑:ShippingOrderReviewView 传入 draft.build_eligibility;只读展示,不发起写请求。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingOrderReviewBuildEligibility } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{
|
||||
eligibility: ShippingOrderReviewBuildEligibility | null;
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
|
||||
/**
|
||||
* 解析建单资格状态文案。
|
||||
*/
|
||||
function statusLabel(status: string): string {
|
||||
const key = `chat.shippingOrderReview.buildEligibility.status.${status}`;
|
||||
return te(key) ? t(key) : status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析行级阻断原因文案。
|
||||
*/
|
||||
function blockReasonLabel(reason?: string | null): string {
|
||||
const normalized = String(reason || '').trim();
|
||||
if (!normalized) return '—';
|
||||
const key = `chat.shippingOrderReview.buildEligibility.blockReasons.${normalized}`;
|
||||
return te(key) ? t(key) : normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析路由状态文案。
|
||||
*/
|
||||
function routingStatusLabel(status?: string | null): string {
|
||||
const normalized = String(status || '').trim();
|
||||
if (!normalized) return '—';
|
||||
const key = `chat.shippingOrderReview.buildEligibility.routingStatus.${normalized}`;
|
||||
return te(key) ? t(key) : normalized;
|
||||
}
|
||||
|
||||
/** 未满足建单资格的明细行。 */
|
||||
const blockedLines = computed(() =>
|
||||
(props.eligibility?.line_projections || []).filter((line) => line.can_build === false),
|
||||
);
|
||||
|
||||
/** 阻断摘要:按 block_reason 聚合行数。 */
|
||||
const blockingSummary = computed(() => {
|
||||
const counts = new Map<string, number>();
|
||||
for (const line of blockedLines.value) {
|
||||
const reason = String(line.block_reason || 'unknown').trim() || 'unknown';
|
||||
counts.set(reason, (counts.get(reason) || 0) + 1);
|
||||
}
|
||||
return [...counts.entries()].map(([reason, count]) => ({ reason, count }));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
v-if="eligibility"
|
||||
class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900"
|
||||
data-testid="review-build-eligibility-panel"
|
||||
>
|
||||
<header class="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.buildEligibility.title') }}</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ t('chat.shippingOrderReview.buildEligibility.subtitle') }}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
class="rounded-full px-2.5 py-1 text-xs font-medium"
|
||||
:class="eligibility.can_build
|
||||
? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100'
|
||||
: 'bg-amber-100 text-amber-900 dark:bg-amber-950 dark:text-amber-100'"
|
||||
data-testid="review-build-eligibility-badge"
|
||||
>
|
||||
{{
|
||||
eligibility.can_build
|
||||
? t('chat.shippingOrderReview.buildEligibility.canBuildYes')
|
||||
: t('chat.shippingOrderReview.buildEligibility.canBuildNo')
|
||||
}}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<dl class="grid gap-2 text-xs text-slate-600 dark:text-slate-400 sm:grid-cols-2">
|
||||
<div>
|
||||
<dt class="inline font-medium">{{ t('chat.shippingOrderReview.buildEligibility.statusLabel') }}:</dt>
|
||||
<dd class="inline">{{ statusLabel(eligibility.status) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<div
|
||||
v-if="!eligibility.can_build && blockingSummary.length"
|
||||
class="mt-3 rounded-lg border border-amber-200 bg-amber-50 p-3 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
|
||||
data-testid="review-build-eligibility-blocking-summary"
|
||||
>
|
||||
<div class="font-semibold">{{ t('chat.shippingOrderReview.buildEligibility.blockingSummary') }}</div>
|
||||
<ul class="mt-1 list-disc space-y-0.5 pl-4">
|
||||
<li v-for="item in blockingSummary" :key="item.reason">
|
||||
{{ blockReasonLabel(item.reason) }}
|
||||
<span class="text-amber-800 dark:text-amber-200">× {{ item.count }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div v-if="eligibility.line_projections.length" class="mt-3 space-y-2">
|
||||
<div class="text-xs font-semibold text-slate-500 dark:text-slate-400">
|
||||
{{ t('chat.shippingOrderReview.buildEligibility.lineProjections') }}
|
||||
</div>
|
||||
<article
|
||||
v-for="line in eligibility.line_projections"
|
||||
:key="String(line.line_key || line.line_index)"
|
||||
class="rounded-lg border border-slate-200 p-3 text-xs dark:border-slate-700"
|
||||
:data-testid="`review-build-eligibility-line-${line.line_key || line.line_index}`"
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<span class="font-medium">
|
||||
{{ t('chat.shippingOrderReview.line', { index: (line.line_index ?? 0) + 1 }) }}
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 text-[11px]"
|
||||
:class="line.can_build
|
||||
? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100'
|
||||
: 'bg-rose-100 text-rose-800 dark:bg-rose-950 dark:text-rose-100'"
|
||||
>
|
||||
{{
|
||||
line.can_build
|
||||
? t('chat.shippingOrderReview.buildEligibility.lineCanBuild')
|
||||
: t('chat.shippingOrderReview.buildEligibility.lineBlocked')
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<dl class="mt-2 grid gap-1 sm:grid-cols-2">
|
||||
<div>
|
||||
<dt class="inline text-slate-500">{{ t('chat.shippingOrderReview.buildEligibility.reservation') }}:</dt>
|
||||
<dd class="inline font-mono">{{ line.effective_reservation_id || '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="inline text-slate-500">{{ t('chat.shippingOrderReview.buildEligibility.routingStatusLabel') }}:</dt>
|
||||
<dd class="inline">{{ routingStatusLabel(line.routing_status) }}</dd>
|
||||
</div>
|
||||
<div v-if="line.inventory_source_hint" class="sm:col-span-2">
|
||||
<dt class="inline text-slate-500">{{ t('chat.shippingOrderReview.buildEligibility.sourceHint') }}:</dt>
|
||||
<dd class="inline">{{ line.inventory_source_hint }}</dd>
|
||||
</div>
|
||||
<div v-if="line.candidate_inventory_source_codes?.length" class="sm:col-span-2">
|
||||
<dt class="inline text-slate-500">{{ t('chat.shippingOrderReview.buildEligibility.candidates') }}:</dt>
|
||||
<dd class="inline font-mono">{{ line.candidate_inventory_source_codes.join(', ') }}</dd>
|
||||
</div>
|
||||
<div v-if="line.block_reason" class="sm:col-span-2">
|
||||
<dt class="inline text-slate-500">{{ t('chat.shippingOrderReview.buildEligibility.blockReason') }}:</dt>
|
||||
<dd class="inline">{{ blockReasonLabel(line.block_reason) }}</dd>
|
||||
</div>
|
||||
<div v-if="line.selection_mode === 'manual' && line.manual_reason" class="sm:col-span-2">
|
||||
<dt class="inline text-slate-500">{{ t('chat.shippingOrderReview.buildEligibility.manualReason') }}:</dt>
|
||||
<dd class="inline">{{ line.manual_reason }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewInventoryCandidatesPanel.vue
|
||||
用途:为库存路由未决的明细行提供多选候选源与强制原因的人工提交表单。
|
||||
依赖:vue-i18n、ShippingOrderReviewBuildEligibilityLineProjection 类型。
|
||||
逻辑:规则候选优先;零候选时回退到已启用库存源列表;emit submit 由 composable 写 API。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { reactive } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingOrderReviewBuildEligibilityLineProjection } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{
|
||||
lines: ShippingOrderReviewBuildEligibilityLineProjection[];
|
||||
/** 已启用库存源;规则零候选时作为可选列表 */
|
||||
enabledSourceCodes?: string[];
|
||||
editable?: boolean;
|
||||
saving?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'submit', payload: { lineKey: string; sourceCodes: string[]; reason: string }): void;
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
|
||||
/** 每行本地表单状态:已选候选与原因。 */
|
||||
const formState = reactive<Record<string, { selected: string[]; reason: string }>>({});
|
||||
|
||||
/**
|
||||
* 行级可选源:规则候选优先,否则回退已启用库存源。
|
||||
*/
|
||||
function selectableCodes(line: ShippingOrderReviewBuildEligibilityLineProjection): string[] {
|
||||
const candidates = (line.candidate_inventory_source_codes || [])
|
||||
.map((code) => String(code || '').trim().toUpperCase())
|
||||
.filter(Boolean);
|
||||
if (candidates.length) return candidates;
|
||||
return (props.enabledSourceCodes || [])
|
||||
.map((code) => String(code || '').trim().toUpperCase())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取或初始化某行的表单状态。
|
||||
*/
|
||||
function getForm(line: ShippingOrderReviewBuildEligibilityLineProjection) {
|
||||
const key = String(line.line_key || (line.line_index ?? ''));
|
||||
if (!formState[key]) {
|
||||
const ruleCandidates = (line.candidate_inventory_source_codes || []).map(String);
|
||||
formState[key] = {
|
||||
selected: [...ruleCandidates],
|
||||
reason: String(line.manual_reason || ''),
|
||||
};
|
||||
}
|
||||
return formState[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换候选编码勾选状态。
|
||||
*/
|
||||
function toggleCode(line: ShippingOrderReviewBuildEligibilityLineProjection, code: string) {
|
||||
const form = getForm(line);
|
||||
const index = form.selected.indexOf(code);
|
||||
if (index >= 0) form.selected.splice(index, 1);
|
||||
else form.selected.push(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析阻断原因展示文案。
|
||||
*/
|
||||
function blockReasonLabel(reason?: string | null): string {
|
||||
const normalized = String(reason || '').trim();
|
||||
if (!normalized) return '';
|
||||
const key = `chat.shippingOrderReview.buildEligibility.blockReasons.${normalized}`;
|
||||
return te(key) ? t(key) : normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并提交指定行的人工候选选择。
|
||||
*/
|
||||
function submitLine(line: ShippingOrderReviewBuildEligibilityLineProjection) {
|
||||
const lineKey = String(line.line_key || '').trim();
|
||||
if (!lineKey) return;
|
||||
const form = getForm(line);
|
||||
emit('submit', {
|
||||
lineKey,
|
||||
sourceCodes: [...form.selected],
|
||||
reason: form.reason.trim(),
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
v-if="lines.length"
|
||||
class="rounded-xl border border-sky-200 bg-sky-50/60 p-4 shadow-sm dark:border-sky-900 dark:bg-sky-950/20"
|
||||
data-testid="review-inventory-candidates-panel"
|
||||
>
|
||||
<header class="mb-3">
|
||||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.inventoryCandidates.title') }}</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-600 dark:text-slate-400">
|
||||
{{ t('chat.shippingOrderReview.inventoryCandidates.subtitle') }}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<article
|
||||
v-for="line in lines"
|
||||
:key="String(line.line_key || line.line_index)"
|
||||
class="mb-3 rounded-lg border border-slate-200 bg-white p-3 last:mb-0 dark:border-slate-700 dark:bg-slate-900"
|
||||
:data-testid="`review-inventory-candidates-line-${line.line_key || line.line_index}`"
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2 text-sm">
|
||||
<span class="font-medium">
|
||||
{{ t('chat.shippingOrderReview.line', { index: (line.line_index ?? 0) + 1 }) }}
|
||||
<span v-if="line.effective_reservation_id" class="ml-1 font-mono text-xs text-slate-500">
|
||||
{{ line.effective_reservation_id }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="line.block_reason" class="text-xs text-amber-800 dark:text-amber-200">
|
||||
{{ blockReasonLabel(line.block_reason) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="selectableCodes(line).length" class="mt-3">
|
||||
<div class="text-xs font-medium text-slate-600 dark:text-slate-300">
|
||||
{{
|
||||
(line.candidate_inventory_source_codes || []).length
|
||||
? t('chat.shippingOrderReview.inventoryCandidates.selectSources')
|
||||
: t('chat.shippingOrderReview.inventoryCandidates.selectEnabledSources')
|
||||
}}
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
<label
|
||||
v-for="code in selectableCodes(line)"
|
||||
:key="code"
|
||||
class="inline-flex cursor-pointer items-center gap-1.5 rounded border border-slate-200 px-2 py-1 text-xs dark:border-slate-600"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="getForm(line).selected.includes(code)"
|
||||
:disabled="!editable || saving"
|
||||
@change="toggleCode(line, code)"
|
||||
>
|
||||
<span class="font-mono">{{ code }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="mt-2 text-xs text-rose-600 dark:text-rose-300">
|
||||
{{ t('chat.shippingOrderReview.inventoryCandidates.noEnabledSources') }}
|
||||
</p>
|
||||
|
||||
<label class="mt-3 block text-xs font-medium text-slate-600 dark:text-slate-300">
|
||||
{{ t('chat.shippingOrderReview.inventoryCandidates.reasonLabel') }}
|
||||
<textarea
|
||||
:value="getForm(line).reason"
|
||||
:disabled="!editable || saving"
|
||||
rows="2"
|
||||
class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 text-xs dark:border-slate-600 dark:bg-slate-950"
|
||||
:placeholder="t('chat.shippingOrderReview.inventoryCandidates.reasonPlaceholder')"
|
||||
@input="getForm(line).reason = ($event.target as HTMLTextAreaElement).value"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div class="mt-3 flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded bg-sky-600 px-3 py-1.5 text-xs text-white disabled:opacity-50"
|
||||
data-testid="review-inventory-candidates-submit"
|
||||
:disabled="!editable || saving || !getForm(line).selected.length || !getForm(line).reason.trim()"
|
||||
@click="submitLine(line)"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.inventoryCandidates.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,259 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewLineNoOverrideDialog.vue
|
||||
用途:复核页编辑内部项次 line_no 时的强制原因弹窗(覆盖须审计)。
|
||||
依赖:vue-i18n、dialog-overlay / dialog-panel。
|
||||
逻辑:ShippingOrderReviewView 拦截 line_no 输入变更;确认后携带 reasonCode/reasonText 调用 patchLine。
|
||||
确认仅发出事件,不自行关闭;父组件成功后再关,失败时保留原因选择与说明。
|
||||
打开时聚焦原因选择框,Tab 焦点陷阱在弹窗内,关闭后恢复先前焦点。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
/** 与后端 LINE_NO_OVERRIDE_REASON_CODES 对齐的稳定原因码。 */
|
||||
const LINE_NO_OVERRIDE_REASON_CODES = [
|
||||
'recognition_error',
|
||||
'customer_line_exception',
|
||||
'business_correction',
|
||||
'other',
|
||||
] as const;
|
||||
|
||||
type LineNoOverrideReasonCode = (typeof LINE_NO_OVERRIDE_REASON_CODES)[number];
|
||||
|
||||
/** 内部项次覆盖确认载荷;供复核页 confirm 事件消费。 */
|
||||
export type LineNoOverridePayload = {
|
||||
value: string;
|
||||
reasonCode: LineNoOverrideReasonCode;
|
||||
reasonText: string;
|
||||
};
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean;
|
||||
/** 用户拟写入的新项次值(已在输入框中编辑)。 */
|
||||
pendingValue: string;
|
||||
confirmLoading?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
confirmLoading: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: boolean): void;
|
||||
(e: 'confirm', payload: LineNoOverridePayload): void;
|
||||
(e: 'cancel'): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const reasonCode = ref<LineNoOverrideReasonCode>('recognition_error');
|
||||
const reasonText = ref('');
|
||||
const reasonMissing = ref(false);
|
||||
const textMissing = ref(false);
|
||||
const panelRef = ref<HTMLElement | null>(null);
|
||||
const reasonSelectRef = ref<HTMLSelectElement | null>(null);
|
||||
let previouslyFocused: HTMLElement | null = null;
|
||||
|
||||
const FOCUSABLE_SELECTOR = [
|
||||
'a[href]',
|
||||
'button:not([disabled])',
|
||||
'textarea:not([disabled])',
|
||||
'input:not([disabled])',
|
||||
'select:not([disabled])',
|
||||
'[tabindex]:not([tabindex="-1"])',
|
||||
].join(',');
|
||||
|
||||
const title = computed(() => t('chat.shippingOrderReview.lineNoOverrideDialog.title'));
|
||||
const impact = computed(() => t('chat.shippingOrderReview.lineNoOverrideDialog.impact'));
|
||||
|
||||
/**
|
||||
* 原因码展示文案。
|
||||
* @param code - 后端允许的覆盖原因码
|
||||
*/
|
||||
const reasonLabel = (code: string) =>
|
||||
t(`chat.shippingOrderReview.lineNoOverrideDialog.reasons.${code}`);
|
||||
|
||||
/** 收集弹窗内可聚焦控件,供 Tab 陷阱使用。 */
|
||||
const 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');
|
||||
};
|
||||
|
||||
/** 关闭弹窗并同步 v-model。 */
|
||||
const closeDialog = () => {
|
||||
emit('update:modelValue', false);
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
if (props.confirmLoading) return;
|
||||
emit('cancel');
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
/**
|
||||
* 校验原因码与「其他」说明后提交覆盖。
|
||||
* 核心逻辑:other 强制补充说明;确认后不关闭,由父组件在保存成功后再关,失败时保留表单。
|
||||
*/
|
||||
const handleConfirm = () => {
|
||||
if (props.confirmLoading) return;
|
||||
reasonMissing.value = false;
|
||||
textMissing.value = false;
|
||||
if (!reasonCode.value) {
|
||||
reasonMissing.value = true;
|
||||
return;
|
||||
}
|
||||
const trimmed = reasonText.value.trim();
|
||||
if (reasonCode.value === 'other' && !trimmed) {
|
||||
textMissing.value = true;
|
||||
return;
|
||||
}
|
||||
emit('confirm', {
|
||||
value: String(props.pendingValue ?? '').trim(),
|
||||
reasonCode: reasonCode.value,
|
||||
reasonText: trimmed,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape 关闭;Tab / Shift+Tab 在弹窗内循环,阻止焦点逃逸到背景页。
|
||||
*/
|
||||
const onKeydown = (event: KeyboardEvent) => {
|
||||
if (!props.modelValue) return;
|
||||
if (event.key === 'Escape' && !props.confirmLoading) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
handleCancel();
|
||||
return;
|
||||
}
|
||||
if (event.key !== 'Tab') return;
|
||||
const nodes = focusableNodes();
|
||||
const first = nodes[0];
|
||||
const last = nodes[nodes.length - 1];
|
||||
// noUncheckedIndexedAccess:空数组或下标越界时 first/last 可能为 undefined。
|
||||
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.modelValue,
|
||||
async (open, wasOpen) => {
|
||||
if (typeof document === 'undefined') return;
|
||||
if (open && !wasOpen) {
|
||||
reasonCode.value = 'recognition_error';
|
||||
reasonText.value = '';
|
||||
reasonMissing.value = false;
|
||||
textMissing.value = false;
|
||||
previouslyFocused = document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
: null;
|
||||
document.addEventListener('keydown', onKeydown, true);
|
||||
await nextTick();
|
||||
(reasonSelectRef.value || focusableNodes()[0])?.focus();
|
||||
return;
|
||||
}
|
||||
if (!open && wasOpen) {
|
||||
document.removeEventListener('keydown', onKeydown, true);
|
||||
const restoreTarget = previouslyFocused;
|
||||
previouslyFocused = null;
|
||||
await nextTick();
|
||||
restoreTarget?.focus?.();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (typeof document !== 'undefined') {
|
||||
document.removeEventListener('keydown', onKeydown, true);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="modelValue"
|
||||
class="dialog-overlay z-50 flex items-center justify-center p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="title"
|
||||
data-testid="review-line-no-override-dialog"
|
||||
@click.self="handleCancel"
|
||||
>
|
||||
<div ref="panelRef" class="dialog-panel w-full max-w-md space-y-4 p-5">
|
||||
<header>
|
||||
<h2 class="text-base font-semibold text-primary" id="review-line-no-override-title">{{ title }}</h2>
|
||||
<p class="mt-2 text-sm text-secondary">{{ impact }}</p>
|
||||
<p class="mt-2 text-sm text-primary">
|
||||
{{ t('chat.shippingOrderReview.lineNoOverrideDialog.newValue', { value: pendingValue || '—' }) }}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<label class="block space-y-1 text-sm">
|
||||
<span class="text-secondary">{{ t('chat.shippingOrderReview.lineNoOverrideDialog.reasonCodeLabel') }}</span>
|
||||
<select
|
||||
ref="reasonSelectRef"
|
||||
v-model="reasonCode"
|
||||
class="select-field w-full text-sm"
|
||||
data-testid="review-line-no-reason-code"
|
||||
:disabled="confirmLoading"
|
||||
:aria-labelledby="'review-line-no-override-title'"
|
||||
@change="reasonMissing = false"
|
||||
>
|
||||
<option v-for="code in LINE_NO_OVERRIDE_REASON_CODES" :key="code" :value="code">
|
||||
{{ reasonLabel(code) }}
|
||||
</option>
|
||||
</select>
|
||||
<p v-if="reasonMissing" class="text-xs text-rose-600 dark:text-rose-400">
|
||||
{{ t('chat.shippingOrderReview.lineNoOverrideDialog.reasonCodeRequired') }}
|
||||
</p>
|
||||
</label>
|
||||
|
||||
<label class="block space-y-1 text-sm">
|
||||
<span class="text-secondary">{{ t('chat.shippingOrderReview.lineNoOverrideDialog.reasonTextLabel') }}</span>
|
||||
<textarea
|
||||
v-model="reasonText"
|
||||
rows="3"
|
||||
class="input-field w-full resize-y text-sm"
|
||||
:placeholder="t('chat.shippingOrderReview.lineNoOverrideDialog.reasonTextPlaceholder')"
|
||||
data-testid="review-line-no-reason-text"
|
||||
:disabled="confirmLoading"
|
||||
@input="textMissing = false"
|
||||
/>
|
||||
<p v-if="textMissing" class="text-xs text-rose-600 dark:text-rose-400">
|
||||
{{ t('chat.shippingOrderReview.lineNoOverrideDialog.reasonTextRequired') }}
|
||||
</p>
|
||||
</label>
|
||||
|
||||
<footer class="flex justify-end gap-2 pt-1">
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="confirmLoading" @click="handleCancel">
|
||||
{{ t('common.deleteDialog.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary btn-sm"
|
||||
:disabled="confirmLoading"
|
||||
data-testid="review-line-no-override-submit"
|
||||
@click="handleConfirm"
|
||||
>
|
||||
{{ confirmLoading ? t('chat.shippingOrderReview.saving') : t('chat.shippingOrderReview.lineNoOverrideDialog.confirm') }}
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
+18
-17
@@ -1,16 +1,16 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewVersionHistoryPanel.vue
|
||||
用途:复核页工作项版本历史时间线;支持只读跳转至历史 Case。
|
||||
依赖:vue-i18n、ShippingSessionWorkItemVersion 类型。
|
||||
逻辑:ShippingOrderReviewView 传入 versions;emit select 供父级切换 case_no。
|
||||
用途:复核页 WorkflowItem 版本历史时间线;支持只读跳转至历史 Case。
|
||||
依赖:vue-i18n、ShippingWorkflowItemVersion 类型。
|
||||
逻辑:ShippingOrderReviewView 传入 versions(由 WorkflowItem 派生);emit select 供父级切换 case_no。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingSessionWorkItemVersion } from '@/features/chat/types/shipping.api.types';
|
||||
import type { ShippingWorkflowItemVersion } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{
|
||||
itemNo?: string | null;
|
||||
versions: ShippingSessionWorkItemVersion[];
|
||||
versions: ShippingWorkflowItemVersion[];
|
||||
loading?: boolean;
|
||||
activeCaseNo?: string | null;
|
||||
}>();
|
||||
@@ -43,7 +43,7 @@ function formatTime(value?: string | null): string {
|
||||
/**
|
||||
* 跳转至指定版本;历史版本以只读模式打开。
|
||||
*/
|
||||
function selectVersion(version: ShippingSessionWorkItemVersion) {
|
||||
function selectVersion(version: ShippingWorkflowItemVersion) {
|
||||
const caseNo = String(version.case_no || '').trim();
|
||||
if (!caseNo) return;
|
||||
emit('select', caseNo, Boolean(version.is_readonly));
|
||||
@@ -65,12 +65,16 @@ function selectVersion(version: ShippingSessionWorkItemVersion) {
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="loading" class="py-4 text-sm text-slate-500">{{ t('chat.shippingSessionWorkItem.loading') }}</div>
|
||||
<p v-else-if="!versions.length" class="py-4 text-sm text-slate-500">
|
||||
{{ t('chat.shippingSessionWorkItem.noVersions') }}
|
||||
</p>
|
||||
<div v-if="loading" class="py-4 text-sm text-slate-500">{{ t('chat.shippingWorkflow.loading') }}</div>
|
||||
<template v-else>
|
||||
<p class="mb-2 text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ t('chat.shippingWorkflow.versionHistoryNote') }}
|
||||
</p>
|
||||
<p v-if="!versions.length" class="py-4 text-sm text-slate-500">
|
||||
{{ t('chat.shippingSessionWorkItem.noVersions') }}
|
||||
</p>
|
||||
|
||||
<ol v-else class="space-y-2">
|
||||
<ol v-else class="space-y-2">
|
||||
<li
|
||||
v-for="version in versions"
|
||||
:key="version.case_no"
|
||||
@@ -84,7 +88,7 @@ function selectVersion(version: ShippingSessionWorkItemVersion) {
|
||||
<div class="min-w-0">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span class="font-medium">
|
||||
{{ version.version_label || t('chat.shippingSessionWorkItem.versionLabel', { version: '?' }) }}
|
||||
{{ version.version_label || t('chat.shippingWorkflow.versionLabel', { version: version.version_no || '?' }) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="version.is_current"
|
||||
@@ -100,7 +104,7 @@ function selectVersion(version: ShippingSessionWorkItemVersion) {
|
||||
</span>
|
||||
</div>
|
||||
<p class="mt-1 truncate text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ version.document_filename || version.case_no }}
|
||||
{{ version.run_no || version.case_no }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@@ -124,12 +128,9 @@ function selectVersion(version: ShippingSessionWorkItemVersion) {
|
||||
<dt class="inline">{{ t('chat.shippingOrderReview.versionHistory.createdAt') }}:</dt>
|
||||
<dd class="inline">{{ formatTime(version.created_at) }}</dd>
|
||||
</div>
|
||||
<div v-if="version.confirmed_at">
|
||||
<dt class="inline">{{ t('chat.shippingOrderReview.versionHistory.confirmedAt') }}:</dt>
|
||||
<dd class="inline">{{ formatTime(version.confirmed_at) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</li>
|
||||
</ol>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* features/chat/components/shipping-review/ReviewWorkflowProgressPanel.spec.ts
|
||||
* 用途:确认后自动进度面板节点状态与无货代上传按钮契约。
|
||||
* 依赖:vitest、@vue/test-utils、vue-i18n stub、RouterLink stub。
|
||||
* 逻辑:按 lifecycle_status 断言 done/active/pending;待登记时展示下一步说明与任务处理台入口。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import ReviewWorkflowProgressPanel from './ReviewWorkflowProgressPanel.vue';
|
||||
import type { ShippingWorkflowItem } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const messages = {
|
||||
en: {
|
||||
chat: {
|
||||
shippingOrderReview: {
|
||||
workflowProgress: {
|
||||
title: 'Auto progress',
|
||||
subtitle: 'Stops at waiting for manual upload registration',
|
||||
polling: 'Refreshing…',
|
||||
taskNo: 'Task {taskNo}',
|
||||
openTaskWorkbench: 'Open task workbench to register',
|
||||
noUploadHint: 'Register credentials in the task workbench',
|
||||
nextStepsManualUpload:
|
||||
'Next: download Excel → upload on freight platform → submit evidence and receipt',
|
||||
nodes: {
|
||||
building_order: 'Create task',
|
||||
inventory_matching: 'Match inventory',
|
||||
generating_excel: 'Generate Excel',
|
||||
manual_upload_pending: 'Awaiting upload registration',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 挂载进度面板。
|
||||
*/
|
||||
function mountPanel(item: Partial<ShippingWorkflowItem> | null, extras?: { taskNo?: string; polling?: boolean }) {
|
||||
const i18n = createI18n({ legacy: false, locale: 'en', messages });
|
||||
return mount(ReviewWorkflowProgressPanel, {
|
||||
props: {
|
||||
item: item as ShippingWorkflowItem | null,
|
||||
taskNo: extras?.taskNo ?? 'SN-1',
|
||||
polling: extras?.polling ?? true,
|
||||
},
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
RouterLink: {
|
||||
props: ['to'],
|
||||
template: '<a :href="JSON.stringify(to)"><slot /></a>',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe('ReviewWorkflowProgressPanel', () => {
|
||||
it('marks earlier nodes done and current active', () => {
|
||||
const wrapper = mountPanel({ lifecycle_status: 'generating_excel', current_stage: 'generating_excel' });
|
||||
expect(wrapper.get('[data-testid="review-workflow-progress-node-building_order"]').attributes('data-state')).toBe('done');
|
||||
expect(wrapper.get('[data-testid="review-workflow-progress-node-inventory_matching"]').attributes('data-state')).toBe('done');
|
||||
expect(wrapper.get('[data-testid="review-workflow-progress-node-generating_excel"]').attributes('data-state')).toBe('active');
|
||||
expect(wrapper.get('[data-testid="review-workflow-progress-node-manual_upload_pending"]').attributes('data-state')).toBe('pending');
|
||||
expect(wrapper.find('[data-testid="review-open-task-workbench"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="review-manual-upload-next-steps"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('shows manual_upload_pending next steps and task workbench link', () => {
|
||||
const wrapper = mountPanel({ lifecycle_status: 'manual_upload_pending' }, { polling: false });
|
||||
expect(wrapper.get('[data-testid="review-workflow-progress-node-manual_upload_pending"]').attributes('data-state')).toBe('active');
|
||||
expect(wrapper.get('[data-testid="review-manual-upload-next-steps"]').text()).toContain('download Excel');
|
||||
const link = wrapper.get('[data-testid="review-open-task-workbench"]');
|
||||
expect(link.text()).toContain('Open task workbench to register');
|
||||
expect(link.attributes('href')).toContain('workspace-shipping-my-tasks');
|
||||
expect(link.attributes('href')).toContain('SN-1');
|
||||
expect(wrapper.find('[data-testid="review-upload-freight"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="review-workflow-progress-polling"]').exists()).toBe(false);
|
||||
});
|
||||
});
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewWorkflowProgressPanel.vue
|
||||
用途:复核确认后展示自动进度节点:创建任务 → 库存匹配 → 生成 Excel → 待人工上传登记。
|
||||
依赖:vue-i18n、vue-router、ShippingWorkflowItem。
|
||||
逻辑:ShippingOrderReviewView 在确认后挂载;按 lifecycle_status / current_stage 点亮节点;
|
||||
无货代上传按钮;待登记时说明下一步并提供跳转任务处理台入口;
|
||||
轮询由父级 composable 负责。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { RouterLink } from 'vue-router';
|
||||
import type { ShippingWorkflowItem } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{
|
||||
item: ShippingWorkflowItem | null;
|
||||
taskNo?: string | null;
|
||||
polling?: boolean;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/** 进度节点稳定键;与 WorkflowItem lifecycle 对齐。 */
|
||||
type ReviewProgressNodeKey =
|
||||
| 'building_order'
|
||||
| 'inventory_matching'
|
||||
| 'generating_excel'
|
||||
| 'manual_upload_pending';
|
||||
|
||||
const NODES: ReviewProgressNodeKey[] = [
|
||||
'building_order',
|
||||
'inventory_matching',
|
||||
'generating_excel',
|
||||
'manual_upload_pending',
|
||||
];
|
||||
|
||||
/**
|
||||
* 将 Item 生命周期映射到进度节点索引(0..3);未知时按建单中。
|
||||
*/
|
||||
function nodeIndex(status?: string | null): number {
|
||||
const normalized = String(status || '').trim();
|
||||
const idx = NODES.indexOf(normalized as ReviewProgressNodeKey);
|
||||
if (idx >= 0) return idx;
|
||||
if (['closed', 'cancelled'].includes(normalized)) return NODES.length - 1;
|
||||
if (['pending_review', 'queued', 'layout_parsing', 'extracting'].includes(normalized)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const activeIndex = computed(() =>
|
||||
nodeIndex(props.item?.lifecycle_status || props.item?.current_stage),
|
||||
);
|
||||
|
||||
const showTaskWorkbenchLink = computed(() => {
|
||||
const status = String(props.item?.lifecycle_status || props.item?.current_stage || '').trim();
|
||||
return status === 'manual_upload_pending' && Boolean(String(props.taskNo || '').trim());
|
||||
});
|
||||
|
||||
/**
|
||||
* 任务处理台路由:带 task_no,便于直接定位待登记任务。
|
||||
*/
|
||||
const taskWorkbenchTo = computed(() => ({
|
||||
name: 'workspace-shipping-my-tasks',
|
||||
query: {
|
||||
task_no: String(props.taskNo || '').trim(),
|
||||
},
|
||||
}));
|
||||
|
||||
/**
|
||||
* 节点展示态:done / active / pending。
|
||||
*/
|
||||
function nodeState(index: number): 'done' | 'active' | 'pending' {
|
||||
const current = activeIndex.value;
|
||||
if (current < 0) return 'pending';
|
||||
if (index < current) return 'done';
|
||||
if (index === current) return 'active';
|
||||
return 'pending';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900"
|
||||
data-testid="review-workflow-progress-panel"
|
||||
>
|
||||
<header class="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.workflowProgress.title') }}</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ t('chat.shippingOrderReview.workflowProgress.subtitle') }}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
v-if="polling"
|
||||
class="text-xs text-sky-700 dark:text-sky-300"
|
||||
data-testid="review-workflow-progress-polling"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.workflowProgress.polling') }}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<div
|
||||
v-if="taskNo"
|
||||
class="mb-3 flex flex-wrap items-center gap-2 text-xs text-slate-600 dark:text-slate-400"
|
||||
>
|
||||
<span>{{ t('chat.shippingOrderReview.workflowProgress.taskNo', { taskNo }) }}</span>
|
||||
<RouterLink
|
||||
v-if="showTaskWorkbenchLink"
|
||||
:to="taskWorkbenchTo"
|
||||
class="inline-flex items-center rounded-lg bg-brand-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-brand-700"
|
||||
data-testid="review-open-task-workbench"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.workflowProgress.openTaskWorkbench') }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
|
||||
<ol class="space-y-2" data-testid="review-workflow-progress-nodes">
|
||||
<li
|
||||
v-for="(key, index) in NODES"
|
||||
:key="key"
|
||||
class="flex items-center gap-3 rounded-lg border px-3 py-2 text-sm"
|
||||
:class="{
|
||||
'border-emerald-200 bg-emerald-50 text-emerald-900 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-100': nodeState(index) === 'done',
|
||||
'border-sky-200 bg-sky-50 text-sky-950 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-100': nodeState(index) === 'active',
|
||||
'border-slate-200 bg-slate-50 text-slate-500 dark:border-slate-800 dark:bg-slate-950/40 dark:text-slate-400': nodeState(index) === 'pending',
|
||||
}"
|
||||
:data-testid="`review-workflow-progress-node-${key}`"
|
||||
:data-state="nodeState(index)"
|
||||
>
|
||||
<span class="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full border text-xs font-semibold">
|
||||
{{ index + 1 }}
|
||||
</span>
|
||||
<span>{{ t(`chat.shippingOrderReview.workflowProgress.nodes.${key}`) }}</span>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p
|
||||
v-if="showTaskWorkbenchLink"
|
||||
class="mt-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-100"
|
||||
data-testid="review-manual-upload-next-steps"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.workflowProgress.nextStepsManualUpload') }}
|
||||
</p>
|
||||
<p
|
||||
v-else
|
||||
class="mt-3 text-xs text-slate-500 dark:text-slate-400"
|
||||
>
|
||||
{{ t('chat.shippingOrderReview.workflowProgress.noUploadHint') }}
|
||||
</p>
|
||||
</section>
|
||||
</template>
|
||||
Reference in new issue
Block a user