feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议

This commit is contained in:
hugo committed 2026-07-18 11:41:02 +08:00
1 parent 46eb63f5bb
commit e9bdd81f1a
320 files changed
+28361 -10487

No files matched your search

@@ -0,0 +1,32 @@
/**
* 用途:验证货代任务状态筛选覆盖全部用户可见流程状态。
* 依赖:shippingTaskStatuses 中的统一状态目录。
* 逻辑:锁定等待处理、人工复核、完成和终止状态,防止后续新增徽标时遗漏筛选入口。
*/
import { describe, expect, it } from 'vitest';
import { SHIPPING_TASK_STATUS_FILTERS } from './shippingTaskStatuses';
describe('SHIPPING_TASK_STATUS_FILTERS', () => {
it('covers review, processing, completion and terminal task states', () => {
const values = SHIPPING_TASK_STATUS_FILTERS.map(([value]) => value);
expect(values).toEqual([
'created',
'parsed',
'pending_review',
'shortage_review',
'waiting_inventory',
'inventory_ready',
'matched',
'waiting_upload',
'uploaded',
'upload_failed',
'rejected',
'closed',
]);
expect(new Set(values).size).toBe(values.length);
});
});
@@ -0,0 +1,21 @@
/**
* 用途:集中定义货代任务工作台可筛选的流程状态。
* 依赖:ShippingNoticeView 使用状态值请求后端,并通过 i18n key 渲染业务名称。
* 逻辑:筛选集合与任务状态徽标保持一致,避免可展示状态无法被筛选。
*/
export const SHIPPING_TASK_STATUS_FILTERS = [
['created', 'created'],
['parsed', 'parsed'],
['pending_review', 'pendingReview'],
['shortage_review', 'shortageReview'],
['waiting_inventory', 'waitingInventory'],
['inventory_ready', 'inventoryReady'],
['matched', 'matched'],
['waiting_upload', 'waitingUpload'],
['uploaded', 'uploaded'],
['upload_failed', 'uploadFailed'],
['rejected', 'rejected'],
['closed', 'closed'],
] as const;
@@ -13,8 +13,10 @@ import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflow
import ShippingMatchResultCard from '@/features/chat/components/messages/ShippingMatchResultCard.vue';
import ShippingTaskParsedResultCard from '@/features/chat/components/ShippingTaskParsedResultCard.vue';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import { useMessage } from '@/shared/composables/useMessage';
import {
getWorkspaceShippingTask,
downloadWorkspaceShippingExportArchive,
listShippingChatAgents,
listWorkspaceShippingTasks,
SHIPPING_NOTICE_AGENT_CODE,
@@ -26,6 +28,12 @@ import {
import { getAuthHeaders } from '@/shared/utils/auth';
import { resolveShippingWorkflowSteps } from '@/features/chat/shipping';
import { sanitizeShippingRuntimeStatusText } from '@/features/chat/shipping/shippingText';
import {
retainVisibleShippingExportSelection,
selectVisibleShippingExports,
updateShippingExportSelection,
} from '@/features/shipping-notice/utils/exportSelection';
import { SHIPPING_TASK_STATUS_FILTERS } from '../shippingTaskStatuses';
const props = defineProps<{
embedded?: boolean;
@@ -33,11 +41,14 @@ const props = defineProps<{
const router = useRouter();
const { t, te } = useI18n();
const msg = useMessage();
const loading = ref(false);
const detailLoading = ref(false);
const tasks = ref<ShippingTaskSummary[]>([]);
const selectedTaskNo = ref<string | null>(null);
const selectedExportTaskNos = ref<string[]>([]);
const archiveDownloading = ref(false);
const detail = ref<ShippingTaskDetail | null>(null);
const statusFilter = ref('all');
const chatAgentId = ref<number | null>(null);
@@ -51,13 +62,10 @@ const batchProgressLabel = computed(() => {
const statusOptions = computed(() => [
{ value: 'all', label: t('workspace.shippingNotice.status.all') },
{ value: 'created', label: t('workspace.shippingNotice.status.created') },
{ value: 'waiting_inventory', label: t('workspace.shippingNotice.status.waitingInventory') },
{ value: 'inventory_ready', label: t('workspace.shippingNotice.status.inventoryReady') },
{ value: 'matched', label: t('workspace.shippingNotice.status.matched') },
{ value: 'waiting_upload', label: t('workspace.shippingNotice.status.waitingUpload') },
{ value: 'uploaded', label: t('workspace.shippingNotice.status.uploaded') },
{ value: 'upload_failed', label: t('workspace.shippingNotice.status.uploadFailed') },
...SHIPPING_TASK_STATUS_FILTERS.map(([value, labelKey]) => ({
value,
label: t(`workspace.shippingNotice.status.${labelKey}`),
})),
]);
type ShippingStatusSource = Pick<
@@ -70,7 +78,6 @@ const displayStatusCode = (source: ShippingStatusSource | string) => {
const reason = String(source.pending_human_reason || '').trim();
const reviewStatus = String(source.review_status || '').trim();
if (reason === 'shortage' || reason === 'shortage_review' || reviewStatus === 'shortage_review') return 'shortage_review';
if (reason === 'align_review' || reviewStatus === 'align_review') return 'align_review';
return String(source.process_status || '').trim();
};
@@ -80,7 +87,6 @@ const statusBadge = (source: ShippingStatusSource | string) => {
created: { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.created') },
parsed: { cls: 'bg-blue-100 text-blue-700', label: t('workspace.shippingNotice.status.parsed') },
pending_review: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.pendingReview') },
align_review: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.alignReview') },
shortage_review: { cls: 'bg-rose-100 text-rose-700', label: t('workspace.shippingNotice.status.shortageReview') },
waiting_inventory: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingInventory') },
inventory_ready: { cls: 'bg-blue-100 text-blue-700', label: t('workspace.shippingNotice.status.inventoryReady') },
@@ -168,7 +174,6 @@ const hasInventorySourceFields = computed(() => {
if (!item) return false;
return !!(
item.inventory_source_code
|| item.inventory_site_id
|| item.inventory_warehouse_id
|| item.inventory_source_status
);
@@ -181,6 +186,10 @@ const loadCases = async () => {
process_status: statusFilter.value === 'all' ? undefined : statusFilter.value,
limit: 100,
});
selectedExportTaskNos.value = retainVisibleShippingExportSelection(
selectedExportTaskNos.value,
tasks.value.map((item) => item.task_no),
);
} catch {
tasks.value = [];
} finally {
@@ -231,6 +240,47 @@ const downloadExport = async (taskNo: string) => {
URL.revokeObjectURL(a.href);
};
/** 下载当前任务所属批次的所有有效 Artifact;缺失票据记录在 ZIP manifest。 */
const downloadBatchExports = async (batchNo: string) => {
await downloadExportArchive({ batch_no: batchNo });
};
/** 下载批次或显式任务集合,并确保临时对象 URL 在点击后释放。 */
const downloadExportArchive = async (payload: { batch_no?: string; task_nos?: string[] }) => {
archiveDownloading.value = true;
try {
const { blob, filename } = await downloadWorkspaceShippingExportArchive(payload);
const a = document.createElement('a');
a.href = URL.createObjectURL(blob); a.download = filename; a.click(); URL.revokeObjectURL(a.href);
} catch {
msg.error(t('workspace.shippingNotice.archiveDownloadFailed'));
} finally {
archiveDownloading.value = false;
}
};
/** 更新单票勾选;数量门禁与后端 100 票限制一致。 */
const toggleExportTask = (taskNo: string, checked: boolean) => {
selectedExportTaskNos.value = updateShippingExportSelection(selectedExportTaskNos.value, taskNo, checked);
};
/** 全选或清空当前查询结果,不跨筛选条件保留不可见任务。 */
const toggleAllVisibleExports = (checked: boolean) => {
selectedExportTaskNos.value = checked
? selectVisibleShippingExports(tasks.value.map((item) => item.task_no))
: [];
};
const allVisibleExportsSelected = computed(() => (
tasks.value.length > 0 && tasks.value.every((item) => selectedExportTaskNos.value.includes(item.task_no))
));
/** 按用户显式选择下载,后端仍逐票执行权限与 Artifact 当前性校验。 */
const downloadSelectedExports = async () => {
if (!selectedExportTaskNos.value.length) return;
await downloadExportArchive({ task_nos: selectedExportTaskNos.value });
};
const shortageLines = computed(() => detail.value?.shortage?.lines || []);
const hasMatchCard = computed(() =>
!!detail.value && (
@@ -290,6 +340,27 @@ onMounted(async () => {
>
{{ $t('workspace.shippingNotice.search') }}
</button>
<label class="ml-auto inline-flex items-center gap-2 text-sm text-secondary">
<input
type="checkbox"
:checked="allVisibleExportsSelected"
:disabled="tasks.length === 0"
@change="toggleAllVisibleExports(($event.target as HTMLInputElement).checked)"
>
{{ $t('workspace.shippingNotice.selectAllVisible') }}
</label>
<span class="text-sm text-muted">
{{ $t('workspace.shippingNotice.selectedCount', { count: selectedExportTaskNos.length }) }}
</span>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedExportTaskNos.length === 0 || archiveDownloading"
@click="downloadSelectedExports"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.downloadSelected') }}
</button>
</div>
<div class="grid gap-5 lg:grid-cols-5">
@@ -300,32 +371,39 @@ onMounted(async () => {
<div v-else-if="tasks.length === 0" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.empty') }}
</div>
<button
<article
v-for="item in tasks"
:key="item.task_no"
type="button"
class="w-full rounded-2xl border px-4 py-3 text-left transition-colors"
class="flex w-full items-start gap-3 rounded-2xl border px-4 py-3 transition-colors"
:class="selectedTaskNo === item.task_no ? 'border-brand-400 bg-brand-50/60' : 'border-default hover:bg-surface-soft/70'"
@click="selectedTaskNo = item.task_no"
>
<div class="flex items-center justify-between gap-2">
<span class="font-mono text-sm font-semibold text-primary">{{ item.task_no }}</span>
<span
class="rounded-full px-2 py-0.5 text-xs font-medium"
:class="statusBadge(item).cls"
:title="item.process_status"
>
{{ statusBadge(item).label }}
</span>
</div>
<div class="mt-1 truncate text-sm text-secondary">{{ item.customer_name || '—' }}</div>
<div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted">
<span>{{ formatLocalDateTime(item.created_at) }}</span>
<span v-if="item.batch_index && item.batch_total" class="rounded-full bg-sky-50 px-2 py-0.5 font-medium text-sky-700">
{{ t('chat.shippingNoticeUi.batchProgress', { index: item.batch_index, total: item.batch_total }) }}
</span>
</div>
</button>
<input
type="checkbox"
class="mt-1"
:aria-label="$t('workspace.shippingNotice.selectForDownload', { taskNo: item.task_no })"
:checked="selectedExportTaskNos.includes(item.task_no)"
@change="toggleExportTask(item.task_no, ($event.target as HTMLInputElement).checked)"
>
<button type="button" class="min-w-0 flex-1 text-left" @click="selectedTaskNo = item.task_no">
<div class="flex items-center justify-between gap-2">
<span class="font-mono text-sm font-semibold text-primary">{{ item.task_no }}</span>
<span
class="rounded-full px-2 py-0.5 text-xs font-medium"
:class="statusBadge(item).cls"
:title="item.process_status"
>
{{ statusBadge(item).label }}
</span>
</div>
<div class="mt-1 truncate text-sm text-secondary">{{ item.customer_name || '—' }}</div>
<div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted">
<span>{{ formatLocalDateTime(item.created_at) }}</span>
<span v-if="item.batch_index && item.batch_total" class="rounded-full bg-sky-50 px-2 py-0.5 font-medium text-sky-700">
{{ t('chat.shippingNoticeUi.batchProgress', { index: item.batch_index, total: item.batch_total }) }}
</span>
</div>
</button>
</article>
</div>
<div class="lg:col-span-3 rounded-2xl border border-default bg-surface/50 p-5">
@@ -368,6 +446,16 @@ onMounted(async () => {
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.download') }}
</button>
<button
v-if="detail.batch_no"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft"
:disabled="archiveDownloading"
@click="downloadBatchExports(detail.batch_no)"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.downloadBatch') }}
</button>
</div>
</div>
@@ -437,10 +525,6 @@ onMounted(async () => {
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.status') }}</dt>
<dd>{{ inventorySourceStatusLabel(detail.inventory_source_status) }}</dd>
</div>
<div>
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.siteId') }}</dt>
<dd class="font-mono">{{ detail.inventory_site_id || '—' }}</dd>
</div>
<div>
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.warehouseId') }}</dt>
<dd class="font-mono">{{ detail.inventory_warehouse_id || '—' }}</dd>