Files
syops/frontend/src/features/chat/components/shipping-review/ReviewLlmSuggestionDialog.vue
T
hugo 3a9fbac2fc feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估
- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。
- 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。
- 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。
- 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。
- 增强文档与代码注释,反映新的业务逻辑与功能要求。
2026-08-02 19:26:35 +08:00

234 lines
7.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
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;
/** 订单字段展示名;缺省时使用通用业务名称。 */
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 || t('chat.shippingOrderReview.unknownField')).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.evidenceLevel.unknown');
});
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>