Files
syops/frontend/src/features/chat/components/ShippingBatchProgressPanel.vue
T
hugo 1fc9976ca3 feat(chat): 更新发货任务处理逻辑和界面文本
- 移除不必要的状态引用
- 更新上传处理提示文本,使用国际化支持
- 扩展发货任务摘要接口,增加错误信息和短缺信息
- 更新多语言支持的文本,改善用户体验
- 增加批次工作区的汇总信息和操作提示
2026-06-29 14:43:27 +08:00

161 lines
6.4 KiB
Vue

<script setup lang="ts">
/**
* features/chat/components/ShippingBatchProgressPanel.vue
* 用途:发货通知聊天顶部轻量批次状态条,展示当前批次进度与工作台入口。
* 依赖:shipping.api.types、vue-i18n、批次 retry API。
* 逻辑:生成式执行摘要由聊天消息流承载;本组件只提供固定状态 chrome 和明确范围的批次操作。
*/
import { computed, ref } from 'vue';
import { List, RefreshCw } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import { retryWorkspaceShippingBatchPending } from '@/features/chat/api/shipping.api';
import { useMessage } from '@/shared/composables/useMessage';
import type {
ShippingBatchSummary,
ShippingConversationWorkspace,
ShippingTaskDetail,
ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
const props = defineProps<{
conversationWorkspace: ShippingConversationWorkspace | null;
activeBatchNo: string;
batchSummary: ShippingBatchSummary | null;
batchTasks: ShippingTaskSummary[];
activeTaskDetail: ShippingTaskDetail | null;
workspaceOpen: boolean;
}>();
const emit = defineEmits<{
'switch-batch': [batchNo: string];
'toggle-workspace': [];
}>();
const { t } = useI18n();
const msg = useMessage();
const retryingPending = ref(false);
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'closed']);
const workspaceBatches = computed(() => props.conversationWorkspace?.batches || []);
const activeBatchNo = computed(() =>
String(props.activeBatchNo || props.batchSummary?.batch_no || workspaceBatches.value[0]?.batch_no || '').trim(),
);
const processSummary = computed(() => {
const summary = props.batchSummary?.process_summary || null;
const total = Number(summary?.total || props.batchSummary?.file_count || props.batchTasks.length || 0);
const completed = Number(
summary?.completed
|| props.batchTasks.filter((task) => COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim())).length
|| 0,
);
const runningFallback = props.batchTasks.some(
(task) => !COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim()),
) ? 1 : 0;
const running = Number(summary?.running || runningFallback || 0);
const pending = Math.max(0, Number(summary?.pending ?? (total - completed - running)));
return { total, completed, running, pending };
});
const abnormalCount = computed(() => {
const batchSummary = props.batchSummary?.process_summary || {};
return Number(batchSummary.failed || 0) + Number((batchSummary as { needs_human?: number }).needs_human || 0);
});
const progressPercent = computed(() =>
processSummary.value.total
? Math.round((processSummary.value.completed / processSummary.value.total) * 100)
: 0,
);
const executionStateMeta = computed(() => {
if (abnormalCount.value > 0) {
return {
text: t('chat.shippingNoticeUi.needsIntervention'),
className: 'border-amber-100 bg-amber-50 text-amber-700',
};
}
if (processSummary.value.running > 0 || processSummary.value.pending > 0) {
return {
text: t('chat.shippingNoticeUi.runningState'),
className: 'border-sky-100 bg-sky-50 text-brand-700',
};
}
return {
text: t('chat.shippingNoticeUi.completedState'),
className: 'border-emerald-100 bg-emerald-50 text-emerald-700',
};
});
const handleRetryPending = async () => {
const batchNo = String(props.batchSummary?.batch_no || '').trim();
if (!batchNo || retryingPending.value) return;
retryingPending.value = true;
try {
const result = await retryWorkspaceShippingBatchPending(batchNo);
msg.success(result.message || t('chat.shippingNoticeUi.retryPendingDone'));
} catch (error) {
msg.error(error instanceof Error ? error.message : t('chat.shippingNoticeUi.retryFailed'));
} finally {
retryingPending.value = false;
}
};
</script>
<template>
<section class="w-full px-3 pt-3 md:px-8 md:pr-10">
<div
class="mx-auto w-full max-w-4xl rounded-2xl border border-default bg-gradient-to-r from-sky-50 via-white to-emerald-50 px-6 py-4 shadow-sm"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-center gap-2 text-xs text-slate-500">
<span class="font-mono font-semibold text-brand-700">{{ activeBatchNo || '--' }}</span>
<span>
{{ t('chat.shippingNoticeUi.batchChromeSummary', {
total: processSummary.total,
completed: processSummary.completed,
running: processSummary.running,
abnormal: abnormalCount,
}) }}
</span>
<span
class="rounded-full border px-2 py-0.5 text-[11px] font-semibold"
:class="executionStateMeta.className"
>
{{ executionStateMeta.text }}
</span>
</div>
<div class="mt-2 h-1.5 max-w-md overflow-hidden rounded-full bg-slate-200">
<div
class="h-full rounded-full bg-brand-500 transition-all"
:style="{ width: `${progressPercent}%` }"
></div>
</div>
</div>
<div class="flex shrink-0 items-center gap-2">
<button
v-if="batchSummary?.batch_no"
type="button"
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white/80 px-2.5 py-1 text-xs font-medium text-secondary transition hover:border-brand-300 hover:bg-brand-50 hover:text-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
:disabled="retryingPending"
@click="handleRetryPending"
>
<RefreshCw class="h-3.5 w-3.5" :class="retryingPending ? 'animate-spin' : ''" />
{{ retryingPending ? t('chat.shippingNoticeUi.retrying') : t('chat.shippingNoticeUi.retryPendingTasks') }}
</button>
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white/80 px-2.5 py-1 text-xs font-medium text-secondary transition hover:border-brand-300 hover:bg-brand-50 hover:text-brand-700"
@click="emit('toggle-workspace')"
>
<List class="h-3.5 w-3.5" />
{{ workspaceOpen ? t('chat.shippingNoticeUi.collapseTaskList') : t('chat.shippingNoticeUi.expandTaskList') }}
<span class="text-brand-600">{{ workspaceOpen ? '▲' : '▼' }}</span>
</button>
</div>
</div>
</div>
</section>
</template>