feat(shipping-notice): 落地字段资产治理与唯一 Schema,自动建单随版本冻结

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-07-29 16:23:15 +08:00
1 parent b7307fc573
commit 3a1dbf7ce5
144 files changed
+15167 -4480

No files matched your search

@@ -0,0 +1,753 @@
/**
* features/workspace/shipping-task-center/TaskTodoPanel.vue
* 用途:仅渲染后端 ui_state.action_buttons / summary.allowed_actions 对应的当前待办动作。
* 依赖:shipping.api 履约写接口、shipping-tasks.api 下载/人工上传、各确认对话框。
* 逻辑:禁止按 process_status 二次推导按钮;管理员 can_handle=false 时只读。
*/
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useMessage } from '@/shared/composables/useMessage';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import ShippingCustomerConfirmDialog from '@/features/chat/components/ShippingCustomerConfirmDialog.vue';
import type {
ShippingChatAction,
ShippingCustomerOption,
ShippingInventorySourceCandidate,
ShippingTaskDetail,
} from '@/features/chat/types/shipping.api.types';
import {
confirmWorkspaceShippingCustomer,
confirmWorkspaceShippingInventorySource,
freezeWorkspaceShippingOrder,
generateWorkspaceShippingExcel,
listWorkspaceShippingCustomerOptions,
matchWorkspaceShippingInventory,
retryWorkspaceShippingUpload,
submitWorkspaceShippingDecision,
} from '@/features/chat/api/shipping.api';
import { downloadWorkspaceShippingExcelFile } from '@/features/workspace/api/shipping-tasks.api';
import { refreshShippingTodoBadge } from '@/features/workspace/composables/useShippingTodoBadge';
import InventorySourceSelectDialog from './InventorySourceSelectDialog.vue';
import ManualUploadEvidenceDialog from './ManualUploadEvidenceDialog.vue';
const props = defineProps<{
detail: ShippingTaskDetail;
canHandle: boolean;
}>();
const emit = defineEmits<{
refreshed: [];
}>();
const { t } = useI18n();
const msg = useMessage();
const busyId = ref<string | null>(null);
const manualUploadOpen = ref(false);
const customerDialogOpen = ref(false);
const customerOptions = ref<ShippingCustomerOption[]>([]);
const customerLoading = ref(false);
const freezeDialogOpen = ref(false);
const pendingFreezeVersion = ref<number | null>(null);
const inventorySourceDialogOpen = ref(false);
const inventorySourceCandidates = ref<ShippingInventorySourceCandidate[]>([]);
const inventorySourceInitialCode = ref('');
const summary = computed(() => props.detail.ui_state?.summary || {});
const actionButtons = computed(() => props.detail.ui_state?.action_buttons || []);
const checkpointKind = computed(() => String(props.detail.ui_state?.checkpoint_kind || ''));
/** auto_continue 仅保留刷新;正常 STP 由后台自动推进。 */
const AUTO_CONTINUE_ACTIONS = new Set(['refresh']);
/** wait_manual_upload 仅允许下载/导出/人工上传确认。 */
const WAIT_MANUAL_UPLOAD_ACTIONS = new Set(['download_excel', 'export', 'mark_manual_uploaded', 'refresh']);
/** must_human 保留例外处理动作,禁止 Chat 侧履约写路径。 */
const MUST_HUMAN_ACTIONS = new Set([
'confirm',
'reject',
'reparse',
'replace_notice_file',
'rematch',
'retry_rpa',
'confirm_inventory_source',
'retry_resolve_inventory_source',
'confirm_customer',
'freeze_order',
'upload_inventory_file',
'match_inventory',
'refresh',
]);
/**
* 按 STP checkpoint_kind 过滤工作台动作,避免 auto_continue 误点写操作。
*/
function isActionAllowedForCheckpoint(actionId: string, kind: string): boolean {
if (!kind || kind === 'complete') return actionId === 'refresh';
if (kind === 'auto_continue') return AUTO_CONTINUE_ACTIONS.has(actionId);
if (kind === 'wait_manual_upload') return WAIT_MANUAL_UPLOAD_ACTIONS.has(actionId);
if (kind === 'must_human') return MUST_HUMAN_ACTIONS.has(actionId);
return true;
}
const allowedIds = computed(() => {
const fromSummary = summary.value.allowed_actions;
if (Array.isArray(fromSummary) && fromSummary.length) return new Set(fromSummary.map(String));
return new Set(actionButtons.value.map((item) => item.id));
});
const visibleActions = computed(() =>
actionButtons.value.filter((action) => {
const id = String(action.id || '');
return allowedIds.value.has(id) && isActionAllowedForCheckpoint(id, checkpointKind.value);
}),
);
/**
* 动作成功后刷新详情并更新导航徽标。
*/
async function afterSuccess() {
await refreshShippingTodoBadge(true);
emit('refreshed');
}
/**
* 从任务上下文解析唯一库存源编码;多候选或无候选时返回空字符串。
*/
function resolveSingleInventorySourceCode(action: ShippingChatAction): string {
const fromAction = String(action.source_code || '').trim().toUpperCase();
if (fromAction) return fromAction;
const resolution = props.detail.inventory_source_resolution;
const candidates = resolution && typeof resolution === 'object'
? (resolution as { candidates?: unknown }).candidates
: null;
if (Array.isArray(candidates) && candidates.length === 1) {
const only = candidates[0];
if (only && typeof only === 'object') {
return String((only as { source_code?: unknown }).source_code || '').trim().toUpperCase();
}
}
return '';
}
/**
* 打开库存源选择对话框;若已能唯一解析则直接提交。
*/
async function runConfirmInventorySource(action: ShippingChatAction) {
const directCode = resolveSingleInventorySourceCode(action);
if (directCode) {
busyId.value = 'confirm_inventory_source';
try {
await confirmWorkspaceShippingInventorySource(props.detail.task_no, directCode);
await afterSuccess();
} catch (e: unknown) {
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
} finally {
busyId.value = null;
}
return;
}
const resolution = props.detail.inventory_source_resolution;
const raw = resolution && typeof resolution === 'object'
? (resolution as { candidates?: unknown }).candidates
: null;
inventorySourceCandidates.value = Array.isArray(raw)
? raw.filter((item): item is ShippingInventorySourceCandidate =>
Boolean(item && typeof item === 'object' && (item as ShippingInventorySourceCandidate).source_code))
: [];
inventorySourceInitialCode.value = String(action.source_code || '').trim().toUpperCase();
inventorySourceDialogOpen.value = true;
}
/**
* 对话框确认库存源后提交后端。
*/
async function onInventorySourceConfirm(sourceCode: string) {
if (!sourceCode.trim()) {
msg.warning(t('workspace.shippingNotice.actions.inventorySourcePrompt'));
return;
}
busyId.value = 'confirm_inventory_source';
try {
await confirmWorkspaceShippingInventorySource(props.detail.task_no, sourceCode.trim().toUpperCase());
await afterSuccess();
} catch (e: unknown) {
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
} finally {
busyId.value = null;
}
}
/**
* 打开客户确认对话框并加载启用标准客户。
*/
async function openCustomerDialog() {
customerDialogOpen.value = true;
customerLoading.value = true;
try {
customerOptions.value = await listWorkspaceShippingCustomerOptions();
} catch (e: unknown) {
customerOptions.value = [];
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.customerNotFound'));
} finally {
customerLoading.value = false;
}
}
/**
* 按关键词刷新客户选项。
*/
async function searchCustomers(query: string) {
customerLoading.value = true;
try {
customerOptions.value = await listWorkspaceShippingCustomerOptions(query.trim());
if (!customerOptions.value.length) {
msg.warning(t('workspace.shippingNotice.actions.customerNotFound'));
}
} catch (e: unknown) {
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.customerNotFound'));
} finally {
customerLoading.value = false;
}
}
/**
* 确认客户后刷新任务详情。
*/
async function onCustomerConfirm(customerId: number) {
busyId.value = 'confirm_customer';
try {
await confirmWorkspaceShippingCustomer(props.detail.task_no, customerId);
customerDialogOpen.value = false;
await afterSuccess();
} catch (e: unknown) {
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
} finally {
busyId.value = null;
}
}
/**
* 校验版本并打开冻结确认对话框。
*/
function openFreezeDialog() {
const version = Number(props.detail.order_data_version);
if (!Number.isInteger(version) || version < 1) {
msg.warning(t('workspace.shippingNotice.actions.freezeFailed'));
return;
}
pendingFreezeVersion.value = version;
freezeDialogOpen.value = true;
}
/**
* 确认冻结后提交后端。
*/
async function onFreezeConfirm() {
const version = pendingFreezeVersion.value;
if (version == null) return;
busyId.value = 'freeze_order';
try {
await freezeWorkspaceShippingOrder(props.detail.task_no, version);
await afterSuccess();
} catch (e: unknown) {
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
} finally {
busyId.value = null;
pendingFreezeVersion.value = null;
}
}
/**
* 执行后端允许的动作;人工上传/客户/库存源/冻结走对话框,其余走对应工作台 API。
*/
async function runAction(action: ShippingChatAction) {
if (!props.canHandle || busyId.value) return;
const id = String(action.id || '');
if (id === 'mark_manual_uploaded') {
manualUploadOpen.value = true;
return;
}
if (id === 'refresh') {
emit('refreshed');
return;
}
if (id === 'confirm_customer') {
await openCustomerDialog();
return;
}
if (id === 'confirm_inventory_source') {
await runConfirmInventorySource(action);
return;
}
if (id === 'freeze_order') {
openFreezeDialog();
return;
}
busyId.value = id;
try {
if (id === 'download_excel' || id === 'export') {
await downloadWorkspaceShippingExcelFile(props.detail.task_no);
await afterSuccess();
return;
}
if (id === 'generate_excel') {
await generateWorkspaceShippingExcel(props.detail.task_no);
await afterSuccess();
return;
}
if (id === 'match_inventory' || id === 'rematch') {
await matchWorkspaceShippingInventory(props.detail.task_no);
await afterSuccess();
return;
}
if (id === 'retry_upload') {
await retryWorkspaceShippingUpload(props.detail.task_no);
await afterSuccess();
return;
}
await submitWorkspaceShippingDecision(props.detail.task_no, id);
await afterSuccess();
} catch (e: unknown) {
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
} finally {
busyId.value = null;
}
}
</script>
<template>
<section class="rounded-2xl border border-brand-200/80 bg-brand-50/40 px-4 py-3">
<div class="mb-1 text-xs font-semibold uppercase tracking-wide text-brand-700">
{{ $t('workspace.shippingNotice.todo.currentTodo') }}
</div>
<h3 class="text-sm font-semibold text-primary">
{{ summary.current_todo || summary.title || $t('workspace.shippingNotice.todo.noActionTitle') }}
</h3>
<p class="mt-1 text-sm text-secondary">
{{ summary.message || $t('workspace.shippingNotice.todo.noActionMessage') }}
</p>
<p v-if="summary.pause_reason" class="mt-1 text-xs text-amber-700">
{{ summary.pause_reason }}
</p>
<div v-if="!canHandle" class="mt-3 text-xs text-muted">
{{ $t('workspace.shippingNotice.todo.adminViewOnly') }}
</div>
<div v-else-if="visibleActions.length" class="mt-3 flex flex-wrap gap-2">
<button
v-for="action in visibleActions"
:key="action.id"
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-50"
:class="action.variant === 'danger'
? 'bg-rose-600 text-white hover:bg-rose-700'
: action.variant === 'secondary'
? 'border border-default bg-surface text-secondary hover:bg-surface-soft'
: 'bg-brand-600 text-white hover:bg-brand-700'"
:disabled="busyId === action.id"
@click="runAction(action)"
>
{{ action.label }}
</button>
</div>
<ManualUploadEvidenceDialog
v-model:open="manualUploadOpen"
:task-no="detail.task_no"
:artifact-id="detail.export_artifacts?.[0]?.id"
:disabled="!canHandle"
@success="afterSuccess"
/>
<ShippingCustomerConfirmDialog
:open="customerDialogOpen"
:options="customerOptions"
:loading="customerLoading"
@close="customerDialogOpen = false"
@search="searchCustomers"
@confirm="onCustomerConfirm"
/>
<InventorySourceSelectDialog
v-model:open="inventorySourceDialogOpen"
:candidates="inventorySourceCandidates"
:initial-code="inventorySourceInitialCode"
@confirm="onInventorySourceConfirm"
/>
<DeleteConfirmDialog
v-model="freezeDialogOpen"
confirm-tone="primary"
:title="$t('workspace.shippingNotice.actions.freezeOrder')"
:message="$t('workspace.shippingNotice.actions.freezeConfirm')"
:confirm-text="$t('workspace.shippingNotice.actions.freezeOrder')"
:confirm-loading="busyId === 'freeze_order'"
@confirm="onFreezeConfirm"
/>
</section>
</template>