feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置 新增收料报表管理的前端页面、路由和侧边栏入口 新增后端收料报表配置接口、数据库模型和RPA脚本 优化发货通知流程的重试策略,将shipping相关job默认不自动重试 移除废弃的库存源确认相关逻辑,更新流程门禁规则 重构订单模板的值适配器模块,新增坐标OCR值适配器 清理前端shipping菜单和action的废弃选项 更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
1 parent
260465b72d
commit
1b6483a4ea
466 files changed
+32115
-33796
No files matched your search
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* features/workspace/api/receipt-report.api.spec.ts
|
||||
* 用途:锁定收料报表列表与下载地址的工作台契约。
|
||||
* 依赖:receipt-report.api、vitest。
|
||||
* 逻辑:普通接收人只能经工作台受控下载,不拼接对象存储地址。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
listFailedReceiptRpaUnits, receiptReportDownloadUrl, resendReceiptReportFile, retryReceiptRpaUnit,
|
||||
} from './receipt-report.api';
|
||||
|
||||
describe('receiptReportDownloadUrl', () => {
|
||||
it('uses the workspace authorization endpoint instead of an object storage URL', () => {
|
||||
// 关键断言:浏览器只能使用后端鉴权下载代理,不能得到 MinIO bucket/key。
|
||||
expect(receiptReportDownloadUrl(42)).toBe('/api/workspace/receipt-report-files/42/download');
|
||||
});
|
||||
|
||||
it('keeps manual compensation routes in the admin namespace', () => {
|
||||
expect(String(listFailedReceiptRpaUnits)).toContain('receipt-rpa-units?status=failed');
|
||||
expect(String(retryReceiptRpaUnit)).toContain('/api/admin/receipt-rpa-units/');
|
||||
expect(String(resendReceiptReportFile)).toContain('/api/admin/receipt-report-files/');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* features/workspace/api/receipt-report.api.ts
|
||||
* 用途:工作台收料归档列表与受控下载 API。
|
||||
* 依赖:requestJson、getAuthHeaders。
|
||||
* 逻辑:列表由服务端按当前接收人/管理员授权裁剪;下载始终经过工作台鉴权代理。
|
||||
*/
|
||||
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
export type ReceiptReportFile = {
|
||||
id: number;
|
||||
original_filename: string;
|
||||
content_type?: string | null;
|
||||
file_size: number;
|
||||
sha256: string;
|
||||
source_code?: string | null;
|
||||
warehouse_id?: string | null;
|
||||
schedule_run_no?: string | null;
|
||||
archive_expires_at?: string | null;
|
||||
created_at?: string | null;
|
||||
download_url: string;
|
||||
};
|
||||
|
||||
export type ReceiptRpaUnit = {
|
||||
id: number;
|
||||
source_code: string;
|
||||
warehouse_id?: string | null;
|
||||
status: string;
|
||||
error_code?: string | null;
|
||||
error_message?: string | null;
|
||||
retry_of_id?: number | null;
|
||||
schedule_run_id: number;
|
||||
created_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取当前用户有权查看的收料原文件列表。
|
||||
* 核心逻辑:不接收 user_id 或对象存储参数,服务端以当前会话和排程接收人关系授权。
|
||||
* @returns 脱敏归档元数据和受控下载地址。
|
||||
*/
|
||||
export const listWorkspaceReceiptReportFiles = (limit = 100) => requestJson<{ items: ReceiptReportFile[] }>(
|
||||
`/api/workspace/receipt-report-files?limit=${encodeURIComponent(String(limit))}`,
|
||||
{ headers: getAuthHeaders() },
|
||||
);
|
||||
|
||||
/**
|
||||
* 返回一个收料文件的受控下载地址。
|
||||
* 核心逻辑:禁止把 MinIO bucket 或 object key 暴露到浏览器。
|
||||
* @param fileId - 收料归档文件主键。
|
||||
* @returns 由后端再次校验接收人权限的下载路径。
|
||||
*/
|
||||
export const receiptReportDownloadUrl = (fileId: number) => `/api/workspace/receipt-report-files/${encodeURIComponent(String(fileId))}/download`;
|
||||
|
||||
/** 管理员读取失败收料单元;普通用户不调用此管理端接口。 */
|
||||
export const listFailedReceiptRpaUnits = () => requestJson<{ items: ReceiptRpaUnit[] }>(
|
||||
'/api/admin/receipt-rpa-units?status=failed&limit=100', { headers: getAuthHeaders() },
|
||||
);
|
||||
|
||||
/** 管理员以必填原因新建失败单元的独立人工重试事实。 */
|
||||
export const retryReceiptRpaUnit = (unitId: number, reason: string) => requestJson<unknown>(
|
||||
`/api/admin/receipt-rpa-units/${encodeURIComponent(String(unitId))}/retry`,
|
||||
{ method: 'POST', headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' }, body: JSON.stringify({ reason }) },
|
||||
);
|
||||
|
||||
/** 管理员仅重发已归档文件的企微消息,不会重新导出。 */
|
||||
export const resendReceiptReportFile = (fileId: number) => requestJson<unknown>(
|
||||
`/api/admin/receipt-report-files/${encodeURIComponent(String(fileId))}/resend`,
|
||||
{ method: 'POST', headers: getAuthHeaders() },
|
||||
);
|
||||
@@ -2,13 +2,12 @@
|
||||
* features/workspace/api/shipping-tasks.api.ts
|
||||
* 用途:工作台发货任务 / 我的待办 API 客户端。
|
||||
* 依赖:shared/api/client、chat shipping.api(履约写操作暂复用)。
|
||||
* 逻辑:My Todos 与徽标走本文件;submit-decision / 下载 / 人工上传仍委托 shipping.api。
|
||||
* 逻辑:My Todos 与徽标走本文件;下载与人工上传凭据登记复用 shipping.api。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import type { ShippingTaskSummary } from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
markWorkspaceShippingManualUploaded,
|
||||
submitWorkspaceShippingDecision,
|
||||
workspaceShippingExportUrl,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { downloadWorkspaceShippingExcelFile } from '@/features/chat/shipping/shippingDownload';
|
||||
@@ -62,6 +61,5 @@ export function countWorkspaceShippingMyTodos() {
|
||||
export {
|
||||
downloadWorkspaceShippingExcelFile,
|
||||
markWorkspaceShippingManualUploaded,
|
||||
submitWorkspaceShippingDecision,
|
||||
workspaceShippingExportUrl,
|
||||
};
|
||||
@@ -9,7 +9,7 @@ import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import {
|
||||
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package, PanelLeftClose, PanelLeftOpen, ClipboardCheck,
|
||||
ChevronDown, ChevronRight, ContactRound, Inbox,
|
||||
ChevronDown, ChevronRight, ContactRound, Inbox, FileDown,
|
||||
} from 'lucide-vue-next';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
@@ -31,6 +31,7 @@ const primaryLinkItems = [
|
||||
{ path: WORKSPACE_PATHS.profile, labelKey: 'workspace.nav.profile', icon: User, match: ['workspace-profile'] },
|
||||
{ path: WORKSPACE_PATHS.applications, labelKey: 'workspace.nav.applications', icon: LayoutGrid, match: ['workspace-applications'] },
|
||||
{ path: WORKSPACE_PATHS.scheduleRuns, labelKey: 'workspace.nav.scheduleRuns', icon: Clock, match: ['workspace-schedule-runs'] },
|
||||
{ path: WORKSPACE_PATHS.receiptReports, labelKey: 'workspace.nav.receiptReports', icon: FileDown, match: ['workspace-receipt-reports'] },
|
||||
] as const;
|
||||
|
||||
const secondaryLinkItems = [
|
||||
|
||||
@@ -21,6 +21,7 @@ const ROUTE_NAME_TO_SIDEBAR: Record<string, WorkspaceSidebarItem> = {
|
||||
'workspace-knowledge-base': 'knowledge_base',
|
||||
'workspace-knowledge-base-group': 'knowledge_base',
|
||||
'workspace-schedule-runs': 'schedule_runs',
|
||||
'workspace-receipt-reports': 'receipt_reports',
|
||||
'workspace-shipping-customers': 'shipping_notice',
|
||||
'workspace-shipping-tasks': 'shipping_notice',
|
||||
'workspace-shipping-my-tasks': 'shipping_notice',
|
||||
|
||||
@@ -9,6 +9,7 @@ export const WORKSPACE_PATHS = {
|
||||
updates: '/workspace/updates',
|
||||
knowledgeBase: '/workspace/knowledge-base',
|
||||
scheduleRuns: '/workspace/schedule-runs',
|
||||
receiptReports: '/workspace/receipt-reports',
|
||||
shippingNotice: '/workspace/shipping-notice/my-tasks',
|
||||
shippingNoticeCustomers: '/workspace/shipping-notice/customers',
|
||||
shippingNoticeTasks: '/workspace/shipping-notice/tasks',
|
||||
@@ -26,6 +27,7 @@ export const LEGACY_VIEW_TO_PATH: Record<string, string> = {
|
||||
updates: WORKSPACE_PATHS.updates,
|
||||
knowledge_base: WORKSPACE_PATHS.knowledgeBase,
|
||||
schedule_runs: WORKSPACE_PATHS.scheduleRuns,
|
||||
receipt_reports: WORKSPACE_PATHS.receiptReports,
|
||||
shipping_notice: WORKSPACE_PATHS.shippingNotice,
|
||||
accounting_voucher_check: WORKSPACE_PATHS.accountingVoucherCheck,
|
||||
history: WORKSPACE_PATHS.history,
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* features/workspace/pages/ReceiptReportFilesPage.spec.ts
|
||||
* 用途:验证收料归档页的接收人与管理员补偿权限边界。
|
||||
* 依赖:Vue Test Utils、Vue I18n、receipt-report.api、Workspace 上下文。
|
||||
* 逻辑:普通接收人只能下载获授权文件;管理员才会查询失败单元并看到重发/重试操作。
|
||||
*/
|
||||
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import ReceiptReportFilesPage from './ReceiptReportFilesPage.vue';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
|
||||
const listWorkspaceReceiptReportFiles = vi.fn();
|
||||
const listFailedReceiptRpaUnits = vi.fn();
|
||||
const resendReceiptReportFile = vi.fn();
|
||||
|
||||
vi.mock('../api/receipt-report.api', () => ({
|
||||
listWorkspaceReceiptReportFiles: (...args: unknown[]) => listWorkspaceReceiptReportFiles(...args),
|
||||
listFailedReceiptRpaUnits: (...args: unknown[]) => listFailedReceiptRpaUnits(...args),
|
||||
receiptReportDownloadUrl: (id: number) => `/download/${id}`,
|
||||
resendReceiptReportFile: (...args: unknown[]) => resendReceiptReportFile(...args),
|
||||
retryReceiptRpaUnit: vi.fn(),
|
||||
}));
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
workspace: {
|
||||
receiptReports: {
|
||||
title: 'Receipt Files', hint: 'hint', refresh: 'Refresh', loading: 'Loading', empty: 'Empty',
|
||||
file: 'File', site: 'Site', warehouse: 'Warehouse', createdAt: 'Created', expiresAt: 'Expires',
|
||||
action: 'Action', download: 'Download', resend: 'Resend to WeCom', failedUnits: 'Failed receipt units',
|
||||
retry: 'Retry with reason', retryReasonPrompt: 'Reason {target}',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function mountPage(role: string) {
|
||||
return mount(ReceiptReportFilesPage, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
provide: { [WORKSPACE_KEY as symbol]: { currentUser: { role } } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe('ReceiptReportFilesPage permissions', () => {
|
||||
it('does not expose administrator compensation actions to a recipient', async () => {
|
||||
listWorkspaceReceiptReportFiles.mockResolvedValue({ items: [{
|
||||
id: 1, original_filename: 'receipt.xlsx', file_size: 12, sha256: 'a'.repeat(64),
|
||||
}] });
|
||||
listFailedReceiptRpaUnits.mockResolvedValue({ items: [{ id: 9, source_code: 'DBS-A', status: 'failed' }] });
|
||||
|
||||
const wrapper = mountPage('user');
|
||||
await flushPromises();
|
||||
|
||||
// 普通接收人只能看到下载,前端也不得请求管理员失败单元接口。
|
||||
expect(wrapper.text()).toContain('Download');
|
||||
expect(wrapper.text()).not.toContain('Resend to WeCom');
|
||||
expect(wrapper.text()).not.toContain('Failed receipt units');
|
||||
expect(listFailedReceiptRpaUnits).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows failed-unit compensation only to an administrator', async () => {
|
||||
listWorkspaceReceiptReportFiles.mockResolvedValue({ items: [] });
|
||||
listFailedReceiptRpaUnits.mockResolvedValue({ items: [{
|
||||
id: 9, source_code: 'DBS-A', warehouse_id: 'WH-01', status: 'failed', error_code: 'RPA.TIMEOUT',
|
||||
}] });
|
||||
|
||||
const wrapper = mountPage('admin');
|
||||
await flushPromises();
|
||||
|
||||
// 即使没有成功文件,管理员仍能看到独立失败单元并开始带原因的补偿。
|
||||
expect(wrapper.text()).toContain('Failed receipt units');
|
||||
expect(wrapper.text()).toContain('DBS-A / WH-01');
|
||||
expect(wrapper.text()).toContain('Retry with reason');
|
||||
expect(listFailedReceiptRpaUnits).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uses the notification resend action without creating another export', async () => {
|
||||
listWorkspaceReceiptReportFiles.mockResolvedValue({ items: [{
|
||||
id: 7, original_filename: 'receipt.xlsx', file_size: 12, sha256: 'b'.repeat(64),
|
||||
}] });
|
||||
listFailedReceiptRpaUnits.mockResolvedValue({ items: [] });
|
||||
resendReceiptReportFile.mockResolvedValue({});
|
||||
|
||||
const wrapper = mountPage('admin');
|
||||
await flushPromises();
|
||||
await wrapper.get('button:nth-of-type(2)').trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
// 重发只调用归档文件的通知接口,不存在浏览器侧重新导出入口。
|
||||
expect(resendReceiptReportFile).toHaveBeenCalledWith(7);
|
||||
expect(wrapper.text()).not.toContain('Export');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/pages/ReceiptReportFilesPage.vue
|
||||
* 用途:向排程收件人展示可下载的收料原样归档文件。
|
||||
* 依赖:receipt-report.api、Vue I18n、Lucide。
|
||||
* 逻辑:文件列表始终由服务端按收件人授权裁剪;浏览器只请求受控下载地址。
|
||||
*/
|
||||
import { computed, inject, onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Download, RefreshCw } from 'lucide-vue-next';
|
||||
import {
|
||||
listFailedReceiptRpaUnits, listWorkspaceReceiptReportFiles, receiptReportDownloadUrl,
|
||||
resendReceiptReportFile, retryReceiptRpaUnit, type ReceiptReportFile, type ReceiptRpaUnit,
|
||||
} from '../api/receipt-report.api';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
|
||||
const files = ref<ReceiptReportFile[]>([]);
|
||||
const failedUnits = ref<ReceiptRpaUnit[]>([]);
|
||||
const loading = ref(false);
|
||||
const { t } = useI18n();
|
||||
const ws = inject(WORKSPACE_KEY);
|
||||
const isAdmin = computed(() => String(ws?.currentUser?.role || '').trim().toLowerCase() === 'admin');
|
||||
|
||||
/** 读取当前用户的收料归档,不在前端补充或推断授权范围。 */
|
||||
async function loadFiles(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
files.value = (await listWorkspaceReceiptReportFiles()).items;
|
||||
failedUnits.value = isAdmin.value ? (await listFailedReceiptRpaUnits()).items : [];
|
||||
} catch {
|
||||
files.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 将 ISO 时间格式化为当前浏览器时区的简短可读值。 */
|
||||
function formatDate(value?: string | null): string {
|
||||
if (!value) return '-';
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
||||
}
|
||||
|
||||
/** 统一从后端受控下载入口获取文件,下载时服务端会再次做权限审计。 */
|
||||
function downloadFile(file: ReceiptReportFile): void {
|
||||
window.location.assign(receiptReportDownloadUrl(file.id));
|
||||
}
|
||||
|
||||
/** 管理员重发已归档文件,不触发任何新的 RPA 导出。 */
|
||||
async function resendFile(file: ReceiptReportFile): Promise<void> {
|
||||
await resendReceiptReportFile(file.id);
|
||||
}
|
||||
|
||||
/** 管理员填写审计原因后才允许创建新的失败单元重试。 */
|
||||
async function retryUnit(unit: ReceiptRpaUnit): Promise<void> {
|
||||
const target = `${unit.source_code}${unit.warehouse_id ? ` / ${unit.warehouse_id}` : ''}`;
|
||||
const reason = window.prompt(t('workspace.receiptReports.retryReasonPrompt', { target }));
|
||||
if (!reason?.trim()) return;
|
||||
await retryReceiptRpaUnit(unit.id, reason.trim());
|
||||
await loadFiles();
|
||||
}
|
||||
|
||||
onMounted(() => { void loadFiles(); });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="space-y-5 animate-fade-in-up">
|
||||
<header class="flex items-center justify-between gap-3">
|
||||
<div><h2 class="text-2xl font-bold text-primary">{{ $t('workspace.receiptReports.title') }}</h2><p class="mt-1 text-sm text-muted">{{ $t('workspace.receiptReports.hint') }}</p></div>
|
||||
<button type="button" class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft" :disabled="loading" @click="loadFiles"><RefreshCw class="h-3.5 w-3.5" />{{ $t('workspace.receiptReports.refresh') }}</button>
|
||||
</header>
|
||||
<div v-if="loading" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">{{ $t('workspace.receiptReports.loading') }}</div>
|
||||
<div v-else-if="!files.length" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">{{ $t('workspace.receiptReports.empty') }}</div>
|
||||
<div v-else class="overflow-hidden rounded-2xl border border-default bg-surface"><div class="overflow-auto"><table class="w-full min-w-[860px] text-sm"><thead class="border-b border-subtle bg-surface-soft text-left text-secondary"><tr><th class="px-4 py-3">{{ $t('workspace.receiptReports.file') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.site') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.warehouse') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.createdAt') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.expiresAt') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.action') }}</th></tr></thead><tbody><tr v-for="file in files" :key="file.id" class="border-b border-subtle last:border-0"><td class="px-4 py-3 font-medium text-primary">{{ file.original_filename }}</td><td class="px-4 py-3 text-muted">{{ file.source_code || '-' }}</td><td class="px-4 py-3 text-muted">{{ file.warehouse_id || '-' }}</td><td class="px-4 py-3 text-muted">{{ formatDate(file.created_at) }}</td><td class="px-4 py-3 text-muted">{{ formatDate(file.archive_expires_at) }}</td><td class="px-4 py-3"><button type="button" class="inline-flex items-center gap-1 rounded-lg border border-default px-2 py-1 text-xs font-medium text-secondary hover:bg-surface-soft" @click="downloadFile(file)"><Download class="h-3 w-3" />{{ $t('workspace.receiptReports.download') }}</button><button v-if="isAdmin" type="button" class="ml-2 inline-flex rounded-lg border border-default px-2 py-1 text-xs font-medium text-secondary hover:bg-surface-soft" @click="resendFile(file)">{{ $t('workspace.receiptReports.resend') }}</button></td></tr></tbody></table></div></div>
|
||||
<section v-if="isAdmin && failedUnits.length" class="overflow-hidden rounded-2xl border border-amber-200 bg-amber-50/40"><header class="border-b border-amber-200 px-4 py-3 text-sm font-semibold text-primary">{{ $t('workspace.receiptReports.failedUnits') }}</header><div class="overflow-auto"><table class="w-full min-w-[720px] text-sm"><tbody><tr v-for="unit in failedUnits" :key="unit.id" class="border-b border-amber-100 last:border-0"><td class="px-4 py-3 font-medium">{{ unit.source_code }}<span v-if="unit.warehouse_id"> / {{ unit.warehouse_id }}</span></td><td class="px-4 py-3 text-muted">{{ unit.error_code || unit.error_message || '-' }}</td><td class="px-4 py-3"><button type="button" class="rounded-lg border border-amber-300 px-2 py-1 text-xs font-medium text-amber-800 hover:bg-amber-100" @click="retryUnit(unit)">{{ $t('workspace.receiptReports.retry') }}</button></td></tr></tbody></table></div></section>
|
||||
</section>
|
||||
</template>
|
||||
@@ -1,128 +0,0 @@
|
||||
/**
|
||||
* features/workspace/shipping-task-center/InventorySourceSelectDialog.vue
|
||||
* 用途:确认库存查询来源——展示 resolution 候选列表或手动输入 source_code。
|
||||
* 依赖:ShippingInventorySourceCandidate、vue-i18n。
|
||||
* 逻辑:由 TaskTodoPanel 在 confirm_inventory_source 动作时打开;emit confirm(sourceCode)。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingInventorySourceCandidate } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
candidates?: ShippingInventorySourceCandidate[] | null;
|
||||
initialCode?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [boolean];
|
||||
confirm: [sourceCode: string];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const selectedCode = ref('');
|
||||
const manualCode = ref('');
|
||||
const useManual = ref(false);
|
||||
|
||||
const candidateList = computed(() =>
|
||||
Array.isArray(props.candidates) ? props.candidates.filter((item) => item?.source_code) : [],
|
||||
);
|
||||
const hasCandidates = computed(() => candidateList.value.length > 0);
|
||||
|
||||
/**
|
||||
* 关闭对话框并重置本地选择状态。
|
||||
*/
|
||||
function close() {
|
||||
emit('update:open', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交选中的库存源编码;候选模式取 radio,否则取手动输入。
|
||||
*/
|
||||
function submit() {
|
||||
const code = useManual.value || !hasCandidates.value
|
||||
? manualCode.value.trim().toUpperCase()
|
||||
: selectedCode.value.trim().toUpperCase();
|
||||
if (!code) return;
|
||||
emit('confirm', code);
|
||||
close();
|
||||
}
|
||||
|
||||
/** 每次打开时初始化选择与输入模式。 */
|
||||
watch(() => props.open, (open) => {
|
||||
if (!open) return;
|
||||
selectedCode.value = '';
|
||||
manualCode.value = String(props.initialCode || '').trim().toUpperCase();
|
||||
useManual.value = !hasCandidates.value;
|
||||
if (candidateList.value.length === 1) {
|
||||
selectedCode.value = candidateList.value[0]!.source_code;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="admin-modal-overlay animate-fade-in items-center z-[170]"
|
||||
@click.self="close"
|
||||
>
|
||||
<div class="admin-modal-panel max-w-xl max-h-[90vh] scale-100">
|
||||
<div class="px-6 py-5 border-b border-subtle">
|
||||
<h3 class="section-title">{{ t('workspace.shippingNotice.inventorySourceDialog.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('workspace.shippingNotice.inventorySourceDialog.hint') }}</p>
|
||||
</div>
|
||||
<div class="px-6 py-5 space-y-4 overflow-y-auto">
|
||||
<div v-if="hasCandidates && !useManual" class="space-y-2 max-h-80 overflow-y-auto">
|
||||
<label
|
||||
v-for="candidate in candidateList"
|
||||
:key="candidate.source_code"
|
||||
class="flex items-start gap-3 rounded-xl border border-default p-3 cursor-pointer hover:border-brand-300"
|
||||
>
|
||||
<input v-model="selectedCode" type="radio" :value="candidate.source_code" class="mt-1" />
|
||||
<span class="flex-1 min-w-0">
|
||||
<span class="font-mono text-sm font-semibold text-primary">{{ candidate.source_code }}</span>
|
||||
<span v-if="candidate.display_name" class="ml-2 text-sm text-secondary">{{ candidate.display_name }}</span>
|
||||
<span
|
||||
v-if="candidate.warehouse_id"
|
||||
class="mt-0.5 block text-xs text-muted"
|
||||
>
|
||||
{{ t('workspace.shippingNotice.inventorySource.warehouseId') }}: {{ candidate.warehouse_id }}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div v-if="hasCandidates" class="flex items-center gap-2">
|
||||
<input
|
||||
id="inventory-source-manual-toggle"
|
||||
v-model="useManual"
|
||||
type="checkbox"
|
||||
class="rounded border-default"
|
||||
/>
|
||||
<label for="inventory-source-manual-toggle" class="text-sm text-secondary cursor-pointer">
|
||||
{{ t('workspace.shippingNotice.inventorySourceDialog.manualEntry') }}
|
||||
</label>
|
||||
</div>
|
||||
<div v-if="useManual || !hasCandidates">
|
||||
<input
|
||||
v-model="manualCode"
|
||||
class="input-field text-sm w-full font-mono uppercase"
|
||||
:placeholder="t('workspace.shippingNotice.actions.inventorySourcePrompt')"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="close">{{ t('common.cancel') }}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary"
|
||||
:disabled="!(useManual || !hasCandidates ? manualCode.trim() : selectedCode.trim())"
|
||||
@click="submit"
|
||||
>
|
||||
{{ t('workspace.shippingNotice.inventorySourceDialog.confirm') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+9
-48
@@ -11,20 +11,18 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import TaskTodoPanel from './TaskTodoPanel.vue';
|
||||
import type { ShippingTaskDetail } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const postGateAction = vi.fn().mockResolvedValue({});
|
||||
const postGateAction = vi.fn().mockResolvedValue({ dispatch: 'sync' });
|
||||
const getProcessExecution = vi.fn();
|
||||
const refreshBadge = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
vi.mock('@/features/chat/api/shipping.api', () => ({
|
||||
confirmWorkspaceShippingCustomer: vi.fn(),
|
||||
confirmWorkspaceShippingInventorySource: vi.fn(),
|
||||
freezeWorkspaceShippingOrder: vi.fn(),
|
||||
listWorkspaceShippingCustomerOptions: vi.fn().mockResolvedValue([]),
|
||||
retryWorkspaceShippingUpload: vi.fn(),
|
||||
submitWorkspaceShippingDecision: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/features/shipping-process-gates/api/process-gates.api', () => ({
|
||||
postWorkspaceProcessGateAction: (...args: unknown[]) => postGateAction(...args),
|
||||
getWorkspaceProcessExecution: (...args: unknown[]) => getProcessExecution(...args),
|
||||
}));
|
||||
|
||||
vi.mock('@/features/workspace/api/shipping-tasks.api', () => ({
|
||||
@@ -80,6 +78,7 @@ function detail(): ShippingTaskDetail {
|
||||
actions: {
|
||||
primary: {
|
||||
code: 'retry_inventory_matching', kind: 'recovery', enabled: true,
|
||||
label: '重新匹配', dispatch: 'mutation',
|
||||
requires_confirmation: false,
|
||||
},
|
||||
secondary: [],
|
||||
@@ -99,61 +98,23 @@ function detail(): ShippingTaskDetail {
|
||||
describe('TaskTodoPanel actionsExecutable', () => {
|
||||
beforeEach(() => {
|
||||
postGateAction.mockClear();
|
||||
postGateAction.mockResolvedValue({ dispatch: 'sync' });
|
||||
getProcessExecution.mockReset();
|
||||
refreshBadge.mockClear();
|
||||
});
|
||||
|
||||
it('invokes formal Gate Action when gateCanHandle=false but actionsExecutable=true', async () => {
|
||||
it('does not expose a hidden action-code executor when the Gate card is read-only', async () => {
|
||||
const wrapper = mount(TaskTodoPanel, {
|
||||
props: {
|
||||
detail: detail(),
|
||||
gateCanHandle: false,
|
||||
actionsExecutable: true,
|
||||
hidePrimaryActions: true,
|
||||
hidePrimaryActions: false,
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
expect(wrapper.get('[data-testid="gate-stub"]').attributes('data-can-handle')).toBe('false');
|
||||
await (wrapper.vm as { invokeActionByCode: (id: string) => Promise<void> }).invokeActionByCode('retry_inventory_matching');
|
||||
await flushPromises();
|
||||
expect(postGateAction).toHaveBeenCalledWith(
|
||||
'SPE-1',
|
||||
'inventory_matching',
|
||||
expect.objectContaining({
|
||||
action_code: 'retry_inventory_matching',
|
||||
expected_gate_version: 3,
|
||||
idempotency_key: expect.any(String),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('blocks fulfillment invoke when expectedNoticeTaskNo mismatches', async () => {
|
||||
const wrapper = mount(TaskTodoPanel, {
|
||||
props: {
|
||||
detail: detail(),
|
||||
gateCanHandle: false,
|
||||
actionsExecutable: true,
|
||||
hidePrimaryActions: true,
|
||||
expectedNoticeTaskNo: 'SN-OTHER',
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await (wrapper.vm as { invokeActionByCode: (id: string) => Promise<void> }).invokeActionByCode('retry_inventory_matching');
|
||||
await flushPromises();
|
||||
expect(postGateAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('no-ops invokeActionByCode when actionsExecutable=false', async () => {
|
||||
const wrapper = mount(TaskTodoPanel, {
|
||||
props: {
|
||||
detail: detail(),
|
||||
gateCanHandle: false,
|
||||
actionsExecutable: false,
|
||||
hidePrimaryActions: true,
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await (wrapper.vm as { invokeActionByCode: (id: string) => Promise<void> }).invokeActionByCode('retry_inventory_matching');
|
||||
await flushPromises();
|
||||
expect((wrapper.vm as { invokeActionByCode?: unknown }).invokeActionByCode).toBeUndefined();
|
||||
expect(postGateAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -10,32 +10,28 @@
|
||||
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,
|
||||
ShippingUnifiedAction,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import {
|
||||
confirmWorkspaceShippingCustomer,
|
||||
confirmWorkspaceShippingInventorySource,
|
||||
freezeWorkspaceShippingOrder,
|
||||
listWorkspaceShippingCustomerOptions,
|
||||
retryWorkspaceShippingUpload,
|
||||
submitWorkspaceShippingDecision,
|
||||
type ShippingFulfillmentOwnershipContext,
|
||||
} 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';
|
||||
import ProcessGateRecoveryCard from '@/features/shipping-process-gates/components/ProcessGateRecoveryCard.vue';
|
||||
import { postWorkspaceProcessGateAction } from '@/features/shipping-process-gates/api/process-gates.api';
|
||||
import type { ShippingProcessGateUserSummary } from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
getWorkspaceProcessExecution,
|
||||
postWorkspaceProcessGateAction,
|
||||
} from '@/features/shipping-process-gates/api/process-gates.api';
|
||||
import type {
|
||||
ShippingProcessGateActionResponse,
|
||||
ShippingProcessGateUserSummary,
|
||||
} from '@/features/shipping-process-gates/types/process-gate.types';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
detail: ShippingTaskDetail;
|
||||
@@ -43,14 +39,12 @@ const props = withDefaults(defineProps<{
|
||||
canHandle?: boolean;
|
||||
/** Gate 卡是否允许写(订单处理工作台恒为 false)。 */
|
||||
gateCanHandle?: boolean;
|
||||
/** Footer/Resolver 委托的 invokeActionByCode 是否可执行写。 */
|
||||
/** 当前可见面板是否允许执行后端已授权动作。 */
|
||||
actionsExecutable?: boolean;
|
||||
/** 为 true 时隐藏本卡全部后端 actions(订单处理工作台写入口仅 Footer)。 */
|
||||
hidePrimaryActions?: boolean;
|
||||
/** 订单处理工作台将 Gate 卡提升到右侧展示时隐藏此处重复卡。 */
|
||||
hideGateCard?: boolean;
|
||||
/** 仅作为工作台动作执行器/弹窗宿主,不渲染第二套卡片或按钮。 */
|
||||
headless?: boolean;
|
||||
/** 工作台权威正式 Notice 号;与 detail.task_no 不一致时禁止履约写。 */
|
||||
expectedNoticeTaskNo?: string | null;
|
||||
/** 工作台权威 OT 号,随履约 API 校验归属。 */
|
||||
@@ -65,7 +59,6 @@ const props = withDefaults(defineProps<{
|
||||
actionsExecutable: undefined,
|
||||
hidePrimaryActions: false,
|
||||
hideGateCard: false,
|
||||
headless: false,
|
||||
expectedNoticeTaskNo: null,
|
||||
expectedOrderTaskNo: null,
|
||||
expectedReviewCaseNo: null,
|
||||
@@ -83,11 +76,6 @@ 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 processGateSummary = computed((): ShippingProcessGateUserSummary | null =>
|
||||
@@ -175,70 +163,6 @@ 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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 打开客户确认对话框并加载启用标准客户。
|
||||
*/
|
||||
@@ -285,49 +209,6 @@ async function onCustomerConfirm(customerId: number) {
|
||||
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 归属上下文(仅非空字段)。
|
||||
*/
|
||||
function ownershipContext(): ShippingFulfillmentOwnershipContext | undefined {
|
||||
const ctx: ShippingFulfillmentOwnershipContext = {};
|
||||
const ot = String(props.expectedOrderTaskNo || '').trim();
|
||||
const caseNo = String(props.expectedReviewCaseNo || '').trim();
|
||||
const run = String(props.expectedRunNo || '').trim();
|
||||
if (ot) ctx.expectedOrderTaskNo = ot;
|
||||
if (caseNo) ctx.expectedReviewCaseNo = caseNo;
|
||||
if (run) ctx.expectedRunNo = run;
|
||||
return (ctx.expectedOrderTaskNo || ctx.expectedReviewCaseNo || ctx.expectedRunNo) ? ctx : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 履约写前校验正式任务号与工作台权威上下文一致。
|
||||
*
|
||||
@@ -344,7 +225,43 @@ async function assertFulfillmentOwnership(): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 将兼容按钮收口为服务端正式 Gate Action;缺少 Projection 身份时只刷新。 */
|
||||
const ASYNC_ATTEMPT_POLL_INTERVAL_MS = 800;
|
||||
const ASYNC_ATTEMPT_POLL_LIMIT = 25;
|
||||
const ASYNC_ATTEMPT_TERMINAL_STATUSES = new Set(['succeeded', 'failed', 'cancelled', 'superseded']);
|
||||
|
||||
/**
|
||||
* 等待后端已受理的异步 Gate Attempt 收口,避免仅刷新一次而仍读取到 Worker 执行前的投影。
|
||||
*
|
||||
* @param response - Gate Action API 的原始响应;仅由 dispatch/attempt 判定是否轮询。
|
||||
*/
|
||||
async function waitForAsyncGateAttempt(response: ShippingProcessGateActionResponse): Promise<void> {
|
||||
if (response.dispatch !== 'async_job' || !Number.isInteger(Number(response.attempt?.id))) return;
|
||||
const executionNo = String(response.execution_no || '').trim();
|
||||
const submittedGateCode = String(response.gate_code || '').trim();
|
||||
const attemptId = Number(response.attempt.id);
|
||||
if (!executionNo || !submittedGateCode || attemptId < 1) return;
|
||||
for (let index = 0; index < ASYNC_ATTEMPT_POLL_LIMIT; index += 1) {
|
||||
const latest = await getWorkspaceProcessExecution(executionNo);
|
||||
const latestAttempt = latest.current_blocking_gate?.latest_attempt;
|
||||
const latestAttemptId = Number(latestAttempt?.id || 0);
|
||||
const latestAttemptStatus = String(latestAttempt?.status || '').trim().toLowerCase();
|
||||
if (
|
||||
(latestAttemptId === attemptId || latestAttemptId === 0)
|
||||
&& ASYNC_ATTEMPT_TERMINAL_STATUSES.has(latestAttemptStatus)
|
||||
) return;
|
||||
const currentGateCode = String(latest.current_blocking_gate?.gate_code || '').trim();
|
||||
const executionStatus = String(latest.status || '').trim().toLowerCase();
|
||||
if (
|
||||
currentGateCode
|
||||
&& currentGateCode !== submittedGateCode
|
||||
&& !['pending', 'queued', 'running'].includes(executionStatus)
|
||||
) return;
|
||||
if (!latest.current_blocking_gate && ['completed', 'cancelled'].includes(executionStatus)) return;
|
||||
await new Promise((resolve) => window.setTimeout(resolve, ASYNC_ATTEMPT_POLL_INTERVAL_MS));
|
||||
}
|
||||
}
|
||||
|
||||
/** 将后端下发的 Gate Action 原样提交;缺少 Projection 身份时只刷新。 */
|
||||
async function requestProjectedGateAction(actionCode: string): Promise<boolean> {
|
||||
const executionNo = String(processGateSummary.value?.execution_no || '').trim();
|
||||
const gate = processGateSummary.value?.current_blocking_gate;
|
||||
@@ -354,119 +271,63 @@ async function requestProjectedGateAction(actionCode: string): Promise<boolean>
|
||||
emit('refreshed');
|
||||
return false;
|
||||
}
|
||||
await postWorkspaceProcessGateAction(executionNo, gateCode, {
|
||||
const response = await postWorkspaceProcessGateAction(executionNo, gateCode, {
|
||||
action_code: actionCode,
|
||||
expected_gate_version: version,
|
||||
idempotency_key: `task-todo:${executionNo}:${gateCode}:${version}:${actionCode}:${crypto.randomUUID()}`,
|
||||
});
|
||||
try {
|
||||
await waitForAsyncGateAttempt(response);
|
||||
} catch {
|
||||
// 受理结果已由 POST 确认;轮询仅用于缩小异步投影窗口,读取短暂失败仍刷新父级事实。
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行后端允许的动作;人工上传/客户/库存源/冻结走对话框,其余走对应工作台 API。
|
||||
*/
|
||||
async function runAction(action: ShippingChatAction) {
|
||||
if (!resolvedActionsExecutable.value || busyId.value) return;
|
||||
const id = String(action.id || '');
|
||||
if (id === 'mark_manual_uploaded') {
|
||||
/** 将后端统一动作适配到既有宿主能力;业务判断、展示和授权仍完全由后端提供。 */
|
||||
async function runUnifiedAction(action: ShippingUnifiedAction) {
|
||||
if (!resolvedActionsExecutable.value || !action.enabled || busyId.value) return;
|
||||
const dispatch = String(action.dispatch || 'mutation').trim();
|
||||
const uiHandler = String(action.ui_handler || '').trim();
|
||||
if (dispatch === 'dialog' && uiHandler === 'manual_upload_evidence') {
|
||||
if (!(await assertFulfillmentOwnership())) return;
|
||||
manualUploadOpen.value = true;
|
||||
return;
|
||||
}
|
||||
if (id === 'refresh') {
|
||||
emit('refreshed');
|
||||
if (dispatch === 'view' && uiHandler === 'excel_download') {
|
||||
busyId.value = action.code;
|
||||
try {
|
||||
await downloadWorkspaceShippingExcelFile(props.detail.task_no);
|
||||
await afterSuccess();
|
||||
} catch (e: unknown) {
|
||||
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
|
||||
} finally {
|
||||
busyId.value = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (id === 'confirm_customer') {
|
||||
if (dispatch === 'navigation' && uiHandler === 'customer_resolution') {
|
||||
await openCustomerDialog();
|
||||
return;
|
||||
}
|
||||
if (id === 'confirm_inventory_source') {
|
||||
if (!(await assertFulfillmentOwnership())) return;
|
||||
await runConfirmInventorySource(action);
|
||||
return;
|
||||
}
|
||||
if (id === 'freeze_order') {
|
||||
if (!(await assertFulfillmentOwnership())) return;
|
||||
openFreezeDialog();
|
||||
return;
|
||||
}
|
||||
busyId.value = id;
|
||||
if (dispatch !== 'mutation' && dispatch !== 'refresh') return;
|
||||
// 生命周期区域按后端 target_surface 展示后,再将同一份后端 action.code 原样
|
||||
// 提交 Gate;前端不再维护库存、Excel 或 RPA 的动作别名与 API 分派。
|
||||
busyId.value = action.code;
|
||||
try {
|
||||
if (!(await assertFulfillmentOwnership())) return;
|
||||
const ownership = ownershipContext();
|
||||
if (id === 'download_excel' || id === 'export') {
|
||||
await downloadWorkspaceShippingExcelFile(props.detail.task_no);
|
||||
await afterSuccess();
|
||||
return;
|
||||
}
|
||||
if (id === 'generate_excel') {
|
||||
await requestProjectedGateAction('regenerate_excel_artifact');
|
||||
await afterSuccess();
|
||||
return;
|
||||
}
|
||||
// [AUTHORITY] Gate 投影使用 retry_inventory_matching;保留旧码仅用于过渡数据。
|
||||
// 三者均必须走同一个带 execution/gate/version 的 Gate Action API,不能退回
|
||||
// 旧 submitWorkspaceShippingDecision,否则会绕过当前 Gate 的乐观锁与授权校验。
|
||||
if (id === 'match_inventory' || id === 'rematch' || id === 'retry_inventory_matching') {
|
||||
await requestProjectedGateAction('retry_inventory_matching');
|
||||
await afterSuccess();
|
||||
return;
|
||||
}
|
||||
if (id === 'retry_upload') {
|
||||
await retryWorkspaceShippingUpload(props.detail.task_no, ownership);
|
||||
await afterSuccess();
|
||||
return;
|
||||
}
|
||||
await submitWorkspaceShippingDecision(props.detail.task_no, id);
|
||||
await requestProjectedGateAction(action.code);
|
||||
await afterSuccess();
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof BusinessError && e.code === 'SHIPPING_PROCESSING_TASK_OWNERSHIP_MISMATCH') {
|
||||
msg.warning(t('errors.codes.SHIPPING_PROCESSING_TASK_OWNERSHIP_MISMATCH'));
|
||||
emit('refreshed');
|
||||
return;
|
||||
}
|
||||
msg.warning(e instanceof Error ? e.message : t('workspace.shippingNotice.actions.failed'));
|
||||
} finally {
|
||||
busyId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 将后端统一动作适配到现有专用弹窗/提交执行器;业务判断仍完全由后端提供。 */
|
||||
async function runUnifiedAction(action: ShippingUnifiedAction) {
|
||||
if (!action.enabled) return;
|
||||
await runAction({
|
||||
id: action.code,
|
||||
// 此入口也供 Footer 按 action code 委托执行;该动作不一定会渲染为卡片按钮,
|
||||
// 因此展示 label 缺失时使用协议 code 作为仅供执行器的占位,而非拒绝正式 Gate 动作。
|
||||
label: String(action.label || action.code),
|
||||
message: action.disabled_reason || '',
|
||||
variant: action.kind === 'terminate' ? 'danger' : action.kind === 'view' ? 'secondary' : 'primary',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 供订单处理工作台统一 ActionBar 委托履约动作(库存源/匹配/上传登记等)。
|
||||
*
|
||||
* @param actionId - ui_state / Gate 动作码
|
||||
*/
|
||||
async function invokeActionByCode(actionId: string) {
|
||||
const id = String(actionId || '').trim();
|
||||
if (!id) return;
|
||||
const projected = [rawBackendPrimaryAction.value, ...rawBackendSecondaryActions.value]
|
||||
.find((item) => item && item.code === id);
|
||||
if (projected) {
|
||||
await runUnifiedAction(projected);
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
invokeActionByCode,
|
||||
openCustomerDialog,
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div v-if="!headless" class="space-y-3">
|
||||
<div class="space-y-3">
|
||||
<ProcessGateRecoveryCard
|
||||
v-if="!hideGateCard"
|
||||
:summary="processGateSummary"
|
||||
@@ -478,7 +339,7 @@ defineExpose({
|
||||
@refreshed="afterSuccess"
|
||||
@refresh-needed="afterSuccess"
|
||||
@confirm-customer="() => void openCustomerDialog()"
|
||||
@manual-upload="() => void invokeActionByCode('mark_manual_uploaded')"
|
||||
@manual-upload="manualUploadOpen = true"
|
||||
/>
|
||||
<section
|
||||
v-if="!hasBlockingGate && !isSystemAutoWait"
|
||||
@@ -541,21 +402,6 @@ defineExpose({
|
||||
@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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -20,6 +20,7 @@ export type WorkspaceSidebarItem =
|
||||
| 'updates'
|
||||
| 'knowledge_base'
|
||||
| 'schedule_runs'
|
||||
| 'receipt_reports'
|
||||
| 'shipping_notice'
|
||||
| 'history';
|
||||
|
||||
|
||||
Reference in new issue
Block a user