feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验

- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全
- 引入审计事件的哈希链校验机制,支持数据完整性验证
- 增强订单抽取与审计功能,支持敏感快照的访问控制
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
hugo committed 2026-07-31 08:59:44 +08:00
1 parent 95cdfe66b0
commit d0fe084999
225 files changed
+25923 -6653

No files matched your search

@@ -2,10 +2,11 @@
* features/workspace/shipping-task-center/ShippingTaskCenterPage.vue
* 用途:发货「我的待办」壳——Pending|Processing|Done + 识别 Run 续办表 + 右侧任务工作台或复核深链。
* 依赖:shipping-tasks.api(my-todos)、shipping.api 详情、ShippingTaskWorkbench、ShippingRunProgressTable、useShippingTodoBadge。
* 逻辑:review_case 项用 review_run_no 打开人工复核;task 项打开任务处理工作台;识别页承接取消/重试/回会话。
* 逻辑:review_case 项用 review_run_no 打开人工复核;task 项打开任务处理工作台;
* 仅对进行中 Workflow/Task 自动刷新(前台 2s / 后台 8s)。
*/
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ExternalLink, RefreshCw } from 'lucide-vue-next';
import {
@@ -24,6 +25,39 @@ import { useShippingTodoBadge } from '../composables/useShippingTodoBadge';
import ShippingTaskWorkbench from './ShippingTaskWorkbench.vue';
import ShippingRunProgressTable from './ShippingRunProgressTable.vue';
/** 进行中 Workflow/Task 前台轮询间隔。 */
const FOREGROUND_POLL_MS = 2000;
/** 页面隐藏时后台轮询间隔。 */
const BACKGROUND_POLL_MS = 8000;
/** 仍视为进行中、需要自动刷新的任务 process_status。 */
const IN_PROGRESS_PROCESS = new Set([
'parsing',
'parsed',
'matching',
'matched',
'waiting_upload',
'uploading',
'upload_failed',
'exporting',
'needs_human',
'pending_void',
]);
/** WorkflowItem 仍开放处理的生命周期(含待人工上传登记)。 */
const IN_PROGRESS_WORKFLOW_ITEM = new Set([
'queued',
'layout_parsing',
'extracting',
'building_order',
'inventory_matching',
'generating_excel',
'pending_review',
'manual_upload_pending',
'reparse_failed',
'failed',
]);
const route = useRoute();
const router = useRouter();
const { refreshShippingTodoBadge } = useShippingTodoBadge();
@@ -54,6 +88,8 @@ const bucketCounts = ref<ShippingMyTodosCount>({
total_pending_badge: 0,
});
const chatAgentId = ref<number | null>(null);
let pollTimer: ReturnType<typeof setTimeout> | null = null;
let pollInFlight = false;
const totalPages = computed(() => Math.max(1, Math.ceil(totalTasks.value / pageSize)));
const canHandle = computed(() => detail.value?.can_handle !== false);
@@ -89,6 +125,73 @@ function todoDisplayNo(item: ShippingTaskSummary): string {
return String(item.task_no || item.todo_ref || '—');
}
/**
* 判断详情是否仍处于进行中(含绑定 WorkflowItem)。
*/
function isDetailInProgress(task: ShippingTaskDetail | null): boolean {
if (!task) return false;
const process = String(task.process_status || '').trim();
if (IN_PROGRESS_PROCESS.has(process)) return true;
const itemStatus = String(task.workflow_item?.lifecycle_status || '').trim();
return IN_PROGRESS_WORKFLOW_ITEM.has(itemStatus);
}
/**
* 是否应继续自动轮询:仅 processing 桶、进行中详情,或 runs 面。
*/
const shouldAutoRefresh = computed(() => {
if (surface.value === 'runs') return true;
if (bucket.value === 'processing') return true;
if (isDetailInProgress(detail.value)) return true;
return tasks.value.some((item) => {
const status = String(item.process_status || '').trim();
return IN_PROGRESS_PROCESS.has(status) || item.item_kind === 'review_case';
});
});
/**
* 按页面可见性选择轮询间隔。
*/
function resolvePollMs(): number {
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
return BACKGROUND_POLL_MS;
}
return FOREGROUND_POLL_MS;
}
/**
* 停止自动轮询。
*/
function stopAutoRefresh() {
if (pollTimer != null) {
clearTimeout(pollTimer);
pollTimer = null;
}
}
/**
* 调度下一次自动刷新(仅进行中 Workflow/Task)。
*/
function scheduleAutoRefresh() {
stopAutoRefresh();
if (!shouldAutoRefresh.value) return;
pollTimer = setTimeout(() => {
void (async () => {
if (pollInFlight || !shouldAutoRefresh.value) {
scheduleAutoRefresh();
return;
}
pollInFlight = true;
try {
await refreshAll({ silent: true });
} finally {
pollInFlight = false;
scheduleAutoRefresh();
}
})();
}, resolvePollMs());
}
/**
* 解析货代 Chat Agent,供复核/会话深链。
*/
@@ -194,9 +297,15 @@ async function loadDetail(taskNo: string) {
/**
* 列表与详情联动刷新。
* @param options.silent - 轮询时不强制切换 loading 闪烁(详情仍更新)
*/
async function refreshAll() {
await Promise.all([loadTodos(), loadCounts()]);
async function refreshAll(options?: { silent?: boolean }) {
const silent = Boolean(options?.silent);
if (!silent) {
await Promise.all([loadTodos(), loadCounts()]);
} else {
await Promise.all([loadTodos(), loadCounts()]);
}
if (isDirectTaskRoute.value && preferredTaskNo.value) {
await loadDetail(preferredTaskNo.value);
return;
@@ -286,20 +395,35 @@ watch(selectedItem, (item) => {
}
});
watch(shouldAutoRefresh, () => {
scheduleAutoRefresh();
});
function onVisibilityChange() {
scheduleAutoRefresh();
}
onMounted(async () => {
await Promise.all([resolveChatAgent(), loadCounts(), loadTodos()]);
if (preferredTaskNo.value) {
if (isDirectTaskRoute.value) {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
return;
}
const hit = tasks.value.find((item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value);
if (!hit) {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
} else {
const hit = tasks.value.find((item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value);
if (!hit) {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
}
}
}
document.addEventListener('visibilitychange', onVisibilityChange);
scheduleAutoRefresh();
});
onBeforeUnmount(() => {
stopAutoRefresh();
document.removeEventListener('visibilitychange', onVisibilityChange);
});
</script>
@@ -313,7 +437,7 @@ onMounted(async () => {
<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"
@click="refreshAll"
@click="refreshAll()"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
@@ -359,7 +483,7 @@ onMounted(async () => {
{{ $t('workspace.shippingNotice.openChat') }}
</button>
</div>
<ShippingTaskWorkbench :detail="detail" :can-handle="canHandle" @refreshed="refreshAll" />
<ShippingTaskWorkbench :detail="detail" :can-handle="canHandle" @refreshed="() => refreshAll()" />
</div>
</div>
@@ -534,7 +658,7 @@ onMounted(async () => {
<ShippingTaskWorkbench
:detail="detail"
:can-handle="canHandle"
@refreshed="refreshAll"
@refreshed="() => refreshAll()"
/>
</div>
</div>