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,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>
|
||||
Reference in new issue
Block a user