feat(shipping-notice): 收敛订单处理状态与履约门禁
This commit is contained in:
1 parent
bffcd55b40
commit
70dd0051b8
153 files changed
+10916
-4296
No files matched your search
@@ -1,259 +0,0 @@
|
||||
<!--
|
||||
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>
|
||||
+15
-2
@@ -485,7 +485,7 @@ function workbenchFileGroup(file: WorkbenchFileRow): WorkbenchFileGroup | null {
|
||||
const status = String(file.projection?.uiState?.status || file.projection?.userStatus || file.projection?.status || file.status_label || '')
|
||||
.trim().toLowerCase();
|
||||
if (status === 'retryable' || status === 'failed') return 'failed';
|
||||
if (status === 'waiting_human' || status === 'idle') return 'waiting_human';
|
||||
if (status === 'waiting_human') return 'waiting_human';
|
||||
if (status === 'running' || status === 'processing') return 'processing';
|
||||
if (status === 'completed') return 'completed';
|
||||
if (status === 'cancelled') return 'cancelled';
|
||||
@@ -564,8 +564,21 @@ function workbenchFileStatus(file: WorkbenchFileRow, task: ConversationProcessin
|
||||
return resolveShippingProcessingStatusLabel(String(status), te, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略分区文件行:不走 status 组与 taskGroup 对齐过滤(ignored 是展示桶,
|
||||
* 父任务仍保留 domain group=processing/completed)。
|
||||
*/
|
||||
function ignoredWorkbenchFileRows(task: ConversationProcessingUserTask): WorkbenchFileRow[] {
|
||||
return visibleWorkbenchFileRows(task).filter((file) => isIgnoredNonOrderAttachment(file.projection));
|
||||
const filter = props.lifecycleFilter || 'all';
|
||||
const query = String(props.fileSearchQuery || '').trim().toLowerCase();
|
||||
return workbenchFileRows(task)
|
||||
.filter((file) => isIgnoredNonOrderAttachment(file.projection))
|
||||
.filter((file) => {
|
||||
if (filter !== 'all' && String(file.projection?.uiState?.lifecycleStage || '') !== filter) return false;
|
||||
if (!query) return true;
|
||||
return [file.filename, file.label, file.po_number]
|
||||
.some((value) => String(value || '').toLowerCase().includes(query));
|
||||
});
|
||||
}
|
||||
|
||||
/** Excel 附件不进入订单 PDF 识别;仅作为只读诊断行展示。 */
|
||||
|
||||
Reference in new issue
Block a user