Files
syops/frontend/src/features/workspace/shipping-task-center/TaskProgressTimeline.vue
T
hugo d0fe084999 feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全
- 引入审计事件的哈希链校验机制,支持数据完整性验证
- 增强订单抽取与审计功能,支持敏感快照的访问控制
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 完善文档与代码注释,反映新的业务逻辑与审计要求
2026-07-31 08:59:44 +08:00

129 lines
4.9 KiB
Vue

/**
* features/workspace/shipping-task-center/TaskProgressTimeline.vue
* 用途:展示任务事件 + Workflow Event 统一时间线(只读),不发明进度百分比。
* 依赖:ShippingTaskEvent、ShippingWorkflowEvent、dateTime、vue-i18n。
* 逻辑:由 ShippingTaskWorkbench 传入 task events 与 workflow events;按时间合并排序;
* Workflow 事件操作人展示为 actor_type/actor_id。
*/
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import type { ShippingTaskEvent, ShippingWorkflowEvent } from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
events: ShippingTaskEvent[];
workflowEvents?: ShippingWorkflowEvent[];
}>();
const { t, te } = useI18n();
type TimelineRow = {
key: string;
label: string;
createdAt?: string | null;
actor?: string | null;
detail?: Record<string, unknown> | null;
source: 'task' | 'workflow';
};
/**
* 将任务事件类型映射为可读文案;契约外码原样展示。
*/
function taskEventLabel(eventType: string | null | undefined): string {
const code = String(eventType || '').trim();
if (!code) return t('workspace.shippingNotice.eventTypes.system');
const key = `workspace.shippingNotice.eventTypes.${code}`;
return te(key) ? t(key) : code;
}
/**
* 将 Workflow Event 码映射为可读文案。
*/
function workflowEventLabel(event: ShippingWorkflowEvent): string {
const code = String(event.event_code || event.message_code || event.stage_code || '').trim();
if (!code) return t('workspace.shippingNotice.timeline.workflowEvent');
const key = `workspace.shippingNotice.workflowEvents.${code}`;
return te(key) ? t(key) : code;
}
/**
* 格式化操作人展示:优先 type/id,便于审计追溯。
* @param actorType - 角色(user/system/admin…)
* @param actorId - 操作者 ID 或系统标识
*/
function formatActorLabel(actorType?: string | null, actorId?: string | number | null): string | null {
const type = String(actorType || '').trim();
const id = actorId == null ? '' : String(actorId).trim();
if (type && id) return `${type}/${id}`;
if (id) return id;
if (type) return type;
return null;
}
const rows = computed<TimelineRow[]>(() => {
const taskRows: TimelineRow[] = (props.events || []).map((event, index) => ({
key: `task-${event.event_type}-${index}`,
label: taskEventLabel(event.event_type),
createdAt: event.created_at,
actor: formatActorLabel(null, event.actor_id),
detail: event.detail_json || null,
source: 'task',
}));
const workflowRows: TimelineRow[] = (props.workflowEvents || []).map((event, index) => ({
key: `wf-${event.seq_no}-${index}`,
label: workflowEventLabel(event),
createdAt: event.occurred_at,
actor: formatActorLabel(event.actor_type, event.actor_id),
detail: {
...(event.payload || {}),
...(event.reason ? { reason: event.reason } : {}),
...(event.stage_code ? { stage_code: event.stage_code } : {}),
},
source: 'workflow',
}));
return [...taskRows, ...workflowRows].sort((a, b) => {
const ta = a.createdAt ? new Date(a.createdAt).getTime() : 0;
const tb = b.createdAt ? new Date(b.createdAt).getTime() : 0;
return ta - tb;
});
});
</script>
<template>
<section class="rounded-2xl border border-default/80 bg-surface px-4 py-3 text-sm">
<h3 class="mb-2 text-sm font-semibold text-secondary">
{{ $t('workspace.shippingNotice.events') }}
</h3>
<div v-if="!rows.length" class="py-4 text-center text-xs text-muted">
{{ $t('workspace.shippingNotice.timeline.empty') }}
</div>
<div
v-for="row in rows"
:key="row.key"
class="border-t border-default/70 py-2 first:border-t-0 first:pt-0"
>
<div class="flex flex-wrap gap-x-3 gap-y-1 text-xs">
<span class="font-medium text-secondary">{{ row.label }}</span>
<span
class="rounded px-1.5 py-0.5 text-[10px]"
:class="row.source === 'workflow' ? 'bg-indigo-50 text-indigo-700' : 'bg-slate-100 text-slate-600'"
>
{{ row.source === 'workflow'
? $t('workspace.shippingNotice.timeline.sourceWorkflow')
: $t('workspace.shippingNotice.timeline.sourceTask') }}
</span>
<span class="text-muted">{{ formatLocalDateTime(row.createdAt) }}</span>
<span v-if="row.actor" class="text-muted">{{ $t('workspace.shippingNotice.operator', { id: row.actor }) }}</span>
</div>
<details
v-if="row.detail && Object.keys(row.detail).length"
class="mt-1 text-xs text-muted"
>
<summary class="cursor-pointer select-none">{{ $t('workspace.shippingNotice.timeline.detail') }}</summary>
<pre class="mt-1 whitespace-pre-wrap break-words">{{ JSON.stringify(row.detail, null, 2) }}</pre>
</details>
</div>
</section>
</template>