Files
syops/frontend/src/features/workspace/shipping-task-center/TaskProgressTimeline.vue
T

98 lines
3.7 KiB
Vue

/**
* features/workspace/shipping-task-center/TaskProgressTimeline.vue
* 用途:展示任务工作台统一 ShippingAuditEvent 时间线(只读),不发明进度百分比。
* 依赖:ShippingTaskAuditTimelineItem、dateTime、vue-i18n。
* 逻辑:由 ShippingTaskWorkbench 传入 auditItems;不再合并 TaskEvent / WorkflowEvent 双轨。
*/
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import type { ShippingTaskAuditTimelineItem } from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
items: ShippingTaskAuditTimelineItem[];
loading?: boolean;
}>();
const { t, te } = useI18n();
type TimelineRow = {
key: string;
label: string;
createdAt?: string | null;
actor?: string | null;
reason?: string | null;
};
/**
* 将统一审计 event_type/action 映射为可读文案;契约外码使用通用说明。
*/
function auditEventLabel(item: ShippingTaskAuditTimelineItem): string {
const eventType = String(item.event_type || item.action || '').trim();
const auditKey = `workspace.shippingNotice.auditTimeline.events.${eventType}`;
if (eventType && te(auditKey)) return t(auditKey);
const legacyKey = `workspace.shippingNotice.eventTypes.${eventType}`;
if (eventType && te(legacyKey)) return t(legacyKey);
return t('workspace.shippingNotice.timeline.updated');
}
/**
* 格式化操作人展示:优先 actor_display,其次 actor_type 映射。
*/
function formatActorLabel(item: ShippingTaskAuditTimelineItem): string | null {
const display = String(item.actor_display || '').trim();
if (display) return display;
const type = String(item.actor_type || '').trim();
const roleKey = `workspace.shippingNotice.timeline.actors.${type}`;
if (type && te(roleKey)) return t(roleKey);
if (type) return t('workspace.shippingNotice.timeline.actors.user');
return null;
}
const rows = computed<TimelineRow[]>(() =>
(props.items || [])
.map((item, index) => ({
key: `audit-${item.id ?? index}`,
label: auditEventLabel(item),
createdAt: item.created_at,
actor: formatActorLabel(item),
reason: String(item.reason || '').trim() || null,
}))
.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="loading && !rows.length" class="py-4 text-center text-xs text-muted">
{{ $t('workspace.shippingNotice.timeline.loading') }}
</div>
<div v-else-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 bg-slate-100 px-1.5 py-0.5 text-[10px] text-slate-600">
{{ $t('workspace.shippingNotice.timeline.sourceAudit') }}
</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>
<p v-if="row.reason" class="mt-1 text-[11px] text-muted">{{ row.reason }}</p>
</div>
</section>
</template>