feat(rohs-check): 新增 RoHS 检核执行进度中增加 Excel 下载功能及相关配置

This commit is contained in:
hugo committed 2026-06-11 17:35:16 +08:00
1 parent ee39270069
commit 599d492895
14 files changed
+845 -272

No files matched your search

@@ -1,6 +1,8 @@
<script setup lang="ts">
import { ref } from 'vue';
import { AlertCircle, CheckCircle2, Clock3, Download, Loader2 } from 'lucide-vue-next';
import type { ToolRunProgress } from '@/api/toolRunProgress';
import { getAuthHeaders } from '@/utils/auth';
const props = defineProps<{
run: ToolRunProgress | null;
@@ -9,6 +11,9 @@ const props = defineProps<{
fallbackTitle?: string;
}>();
const downloadingExcel = ref(false);
const downloadError = ref('');
const statusLabel = (status?: string) => {
const map: Record<string, string> = {
running: '执行中',
@@ -23,7 +28,10 @@ const statusLabel = (status?: string) => {
const formatTime = (value?: string | null) => {
if (!value) return '-';
const date = new Date(String(value));
const normalized = String(value).match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$/)
? `${value}Z`
: String(value);
const date = new Date(normalized);
if (Number.isNaN(date.getTime())) return String(value).replace('T', ' ').slice(0, 19);
const pad = (num: number) => String(num).padStart(2, '0');
return [
@@ -39,12 +47,73 @@ const formatTime = (value?: string | null) => {
const percent = () => Math.max(0, Math.min(Number(props.run?.progress_percent || 0), 100));
const judgementTotal = () => {
const judgement = props.run?.judgement;
if (!judgement) return 0;
return Number(judgement.qualified_count || 0)
+ Number(judgement.unqualified_count || 0)
+ Number(judgement.manual_count || 0);
const kbSyncMeta = (status?: string | null) => {
const value = String(status || '').toLowerCase();
if (value === 'success') {
return { label: '知识库已同步', tone: 'border-emerald-200 bg-emerald-50 text-emerald-700', icon: 'success' };
}
if (value === 'failed') {
return { label: '知识库同步失败', tone: 'border-rose-200 bg-rose-50 text-rose-700', icon: 'failed' };
}
if (['queued', 'cleaning', 'syncing'].includes(value)) {
return { label: '知识库同步中', tone: 'border-sky-200 bg-sky-50 text-sky-700', icon: 'syncing' };
}
if (value === 'skipped') {
return { label: '知识库未同步', tone: 'border-slate-200 bg-slate-50 text-slate-600', icon: 'skipped' };
}
return { label: `知识库:${status || '未知'}`, tone: 'border-slate-200 bg-slate-50 text-slate-600', icon: 'skipped' };
};
const parseDownloadFilename = (disposition: string | null, fallback: string) => {
const value = disposition || '';
const utf8Match = value.match(/filename\*=UTF-8''([^;]+)/i);
const raw = utf8Match?.[1] || value.match(/filename="?([^";]+)"?/i)?.[1] || fallback;
try {
return decodeURIComponent(raw);
} catch {
return raw;
}
};
const stringifyDownloadError = (payload: any, fallback: string) => {
if (!payload) return fallback;
if (typeof payload === 'string') return payload;
if (typeof payload?.message === 'string') return payload.message;
if (typeof payload?.error === 'string') return payload.error;
if (typeof payload?.error?.message === 'string') return payload.error.message;
if (typeof payload?.code === 'string') return payload.code;
return fallback;
};
const downloadExcel = async () => {
const url = props.run?.excel?.download_url;
if (!url || downloadingExcel.value) return;
downloadingExcel.value = true;
downloadError.value = '';
try {
const res = await fetch(url, { headers: getAuthHeaders() });
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(stringifyDownloadError(body, `下载失败:${res.status}`));
}
const blob = await res.blob();
const filename = parseDownloadFilename(
res.headers.get('content-disposition'),
props.run?.excel?.file_name || `${props.run?.run_no || 'result'}.xlsx`,
);
const objectUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = objectUrl;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(objectUrl);
} catch (e: any) {
downloadError.value = e?.message || '下载 Excel 失败';
} finally {
downloadingExcel.value = false;
}
};
</script>
@@ -63,7 +132,10 @@ const judgementTotal = () => {
{{ run?.title || fallbackTitle || '任务进度' }}
</div>
<p class="mt-1 text-xs text-slate-500">
<template v-if="run">批次:{{ run.run_no }} · 状态:{{ statusLabel(run.status) }}</template>
<template v-if="run">
批次:{{ run.run_no }} · 状态:{{ statusLabel(run.status) }}
<span v-if="run.error_message" class="ml-2 text-rose-700">错误信息:{{ run.error_message }}</span>
</template>
<template v-else-if="loading">正在查询任务进度...</template>
<template v-else>{{ error }}</template>
</p>
@@ -73,18 +145,38 @@ const judgementTotal = () => {
<span v-if="run.current_step.started_at"> · 阶段开始:{{ formatTime(run.current_step.started_at) }}</span>
</p>
</div>
<a
v-if="run?.excel?.download_url"
:href="run.excel.download_url"
target="_blank"
class="inline-flex items-center gap-1 rounded-full bg-sky-600 px-3 py-1.5 text-xs font-medium text-white transition hover:bg-sky-700"
>
<Download class="h-3.5 w-3.5" />
下载 Excel
</a>
<div class="flex shrink-0 flex-wrap items-center justify-end gap-2">
<span
v-if="run?.knowledge_base?.sync_status"
class="inline-flex items-center gap-1 rounded-full border px-2.5 py-1.5 text-xs font-medium"
:class="kbSyncMeta(run.knowledge_base.sync_status).tone"
:title="run.knowledge_base.error_message || kbSyncMeta(run.knowledge_base.sync_status).label"
>
<CheckCircle2 v-if="kbSyncMeta(run.knowledge_base.sync_status).icon === 'success'" class="h-3.5 w-3.5" />
<AlertCircle v-else-if="kbSyncMeta(run.knowledge_base.sync_status).icon === 'failed'" class="h-3.5 w-3.5" />
<Loader2 v-else-if="kbSyncMeta(run.knowledge_base.sync_status).icon === 'syncing'" class="h-3.5 w-3.5 animate-spin" />
<Clock3 v-else class="h-3.5 w-3.5" />
{{ kbSyncMeta(run.knowledge_base.sync_status).label }}
</span>
<button
v-if="run?.excel?.download_url"
type="button"
:disabled="downloadingExcel"
class="inline-flex items-center gap-1 rounded-full bg-sky-600 px-3 py-1.5 text-xs font-medium text-white transition hover:bg-sky-700 disabled:cursor-not-allowed disabled:opacity-60"
@click="downloadExcel"
>
<Loader2 v-if="downloadingExcel" class="h-3.5 w-3.5 animate-spin" />
<Download v-else class="h-3.5 w-3.5" />
{{ downloadingExcel ? '下载中...' : '下载 Excel' }}
</button>
</div>
</div>
<div v-if="run" class="space-y-3 px-4 py-4">
<div v-if="downloadError" class="rounded-xl bg-rose-50 px-3 py-2 text-xs text-rose-700">
{{ downloadError }}
</div>
<div class="h-2.5 overflow-hidden rounded-full bg-slate-200">
<div
class="h-full rounded-full bg-gradient-to-r from-sky-500 to-emerald-500 transition-all duration-500"
@@ -119,36 +211,8 @@ const judgementTotal = () => {
</div>
</div>
<div v-if="judgementTotal() > 0" class="rounded-xl bg-white/70 px-3 py-3">
<div class="mb-2 text-xs font-semibold text-slate-600">判定口径</div>
<div class="grid grid-cols-2 gap-2 md:grid-cols-5">
<div class="rounded-lg bg-emerald-50/80 px-3 py-2">
<div class="text-xs text-slate-500">合格</div>
<div class="text-lg font-bold text-emerald-700">{{ run.judgement?.qualified_count || 0 }}</div>
</div>
<div class="rounded-lg bg-rose-50/80 px-3 py-2">
<div class="text-xs text-slate-500">不合格</div>
<div class="text-lg font-bold text-rose-700">{{ run.judgement?.unqualified_count || 0 }}</div>
</div>
<div class="rounded-lg bg-amber-50/80 px-3 py-2">
<div class="text-xs text-slate-500">人工判定</div>
<div class="text-lg font-bold text-amber-700">{{ run.judgement?.manual_count || 0 }}</div>
</div>
<div class="rounded-lg bg-orange-50/80 px-3 py-2">
<div class="text-xs text-slate-500">Dify 异常</div>
<div class="text-lg font-bold text-orange-700">{{ run.judgement?.dify_error_count || 0 }}</div>
</div>
<div class="rounded-lg bg-slate-50/80 px-3 py-2">
<div class="text-xs text-slate-500">返回异常</div>
<div class="text-lg font-bold text-slate-700">{{ run.judgement?.invalid_result_count || 0 }}</div>
</div>
</div>
</div>
<div v-if="run.knowledge_base?.sync_status || run.error_message" class="rounded-xl bg-white/70 px-3 py-2 text-xs text-slate-600">
<div v-if="run.knowledge_base?.sync_status">知识库同步:{{ run.knowledge_base.sync_status }}</div>
<div v-if="run.knowledge_base?.error_message" class="text-amber-700">同步错误:{{ run.knowledge_base.error_message }}</div>
<div v-if="run.error_message" class="text-rose-700">错误信息:{{ run.error_message }}</div>
<div v-if="run.knowledge_base?.error_message" class="rounded-xl bg-amber-50 px-3 py-2 text-xs text-amber-700">
知识库同步错误:{{ run.knowledge_base.error_message }}
</div>
</div>
</section>
@@ -7,6 +7,7 @@ export interface ToolRunProgressConfig {
poll_interval_seconds?: number;
active_url?: string;
detail_url_template?: string;
run_id?: number | string | null;
lock_input_when_running?: boolean;
lock_message?: string;
}
@@ -23,7 +24,7 @@ export function useToolRunProgress(configRef: Ref<ToolRunProgressConfig | null>)
const error = ref('');
let timer: number | undefined;
const enabled = computed(() => !!configRef.value?.active_url);
const enabled = computed(() => !!configRef.value?.active_url || (!!configRef.value?.detail_url_template && !!configRef.value?.run_id));
const isRunning = computed(() => run.value?.status === 'running');
const shouldLockInput = computed(() => Boolean(configRef.value?.lock_input_when_running) && isRunning.value);
const lockMessage = computed(() => configRef.value?.lock_message || '当前任务执行中,请等待完成');
@@ -44,9 +45,18 @@ export function useToolRunProgress(configRef: Ref<ToolRunProgressConfig | null>)
}, interval);
};
const resolveProgressUrl = (cfg: ToolRunProgressConfig) => {
const runId = String(cfg.run_id || '').trim();
if (runId && cfg.detail_url_template) {
return cfg.detail_url_template.replace('{run_id}', encodeURIComponent(runId));
}
return cfg.active_url || '';
};
const refresh = async () => {
const cfg = configRef.value;
if (!cfg?.active_url) {
const url = cfg ? resolveProgressUrl(cfg) : '';
if (!url) {
run.value = null;
error.value = '';
clearTimer();
@@ -54,7 +64,7 @@ export function useToolRunProgress(configRef: Ref<ToolRunProgressConfig | null>)
}
loading.value = true;
try {
const payload = await getToolRunProgress(cfg.active_url);
const payload = await getToolRunProgress(url);
run.value = payload.run;
error.value = '';
} catch (e: any) {
+53 -34
View File
@@ -441,7 +441,7 @@ const handleVoiceFeatureClick = () => {
msg.info(t('chat.devComingSoon'));
return;
}
if (isThinking.value || isVoiceTranscribing.value || toolRunShouldLockInput.value) return;
if (isThinking.value || isVoiceTranscribing.value) return;
const unavailable = getVoiceUnavailableErrorKey();
if (unavailable) {
msg.warning(t(unavailable));
@@ -460,6 +460,30 @@ const showGeneralFeedbackDialog = ref(false);
const LEAVE_FEATURE_AGENT_NAMES = new Set(['通用入口', '人事规章']);
const canUseLeaveFeature = computed(() => LEAVE_FEATURE_AGENT_NAMES.has(String(currentAgent.value?.name || '').trim()));
const extractToolRunIdFromContent = (content: unknown): number | null => {
const text = String(content || '');
const match = text.match(/(?:检核批次 ID|当前检核批次 ID|运行 ID|run_id|run id)\s*[::]\s*(\d+)/i);
return match?.[1] ? Number(match[1]) : null;
};
const shouldShowToolRunProgressAfterMessage = (msg: any) => {
if (msg?.role !== 'assistant') return false;
if (!(toolRunProgress.value || toolRunProgressLoading.value || toolRunProgressError.value)) return false;
const messageRunId = extractToolRunIdFromContent(msg.content);
const currentRunId = Number(toolRunProgress.value?.run_id || activeToolRunId.value || 0);
return !!messageRunId && messageRunId === currentRunId;
};
const activeToolRunId = computed(() => {
for (let i = messages.value.length - 1; i >= 0; i -= 1) {
const msg = messages.value[i];
if (msg?.role !== 'assistant') continue;
const runId = extractToolRunIdFromContent(msg.content);
if (runId) return runId;
}
return null;
});
const toolRunProgressConfig = computed<ToolRunProgressConfig | null>(() => {
const extra = currentAgent.value?.extra_config || {};
const capabilities = Array.isArray(extra.capabilities) ? extra.capabilities.map((item: unknown) => String(item)) : [];
@@ -468,19 +492,25 @@ const toolRunProgressConfig = computed<ToolRunProgressConfig | null>(() => {
if (!raw || typeof raw !== 'object') return null;
const cfg = raw as ToolRunProgressConfig;
const cid = String(conversationId.value || '').trim();
const runId = activeToolRunId.value;
if (runId && cfg.detail_url_template) {
return {
...cfg,
run_id: runId,
};
}
if (!cid || !cfg.active_url) return null;
const separator = cfg.active_url.includes('?') ? '&' : '?';
return {
...cfg,
active_url: `${cfg.active_url}${separator}conversation_id=${encodeURIComponent(cid)}`,
run_id: null,
};
});
const {
run: toolRunProgress,
loading: toolRunProgressLoading,
error: toolRunProgressError,
shouldLockInput: toolRunShouldLockInput,
lockMessage: toolRunLockMessage,
refresh: refreshToolRunProgress,
} = useToolRunProgress(toolRunProgressConfig);
@@ -705,7 +735,7 @@ const showAttachmentMenu = ref(false);
const showAttachmentUrlPanel = ref(false);
const canSendMessage = computed(() => {
if (isThinking.value || isUploadingAttachments.value || toolRunShouldLockInput.value) return false;
if (isThinking.value || isUploadingAttachments.value) return false;
if (input.value.trim()) return true;
if (isShippingNoticeAgent.value && attachments.value.length > 0) return true;
return false;
@@ -718,7 +748,7 @@ const closeAttachmentMenu = () => {
};
const toggleAttachmentMenu = async () => {
if (isThinking.value || isUploadingAttachments.value || toolRunShouldLockInput.value) return;
if (isThinking.value || isUploadingAttachments.value) return;
showAttachmentMenu.value = !showAttachmentMenu.value;
if (!showAttachmentMenu.value) {
showAttachmentUrlPanel.value = false;
@@ -727,13 +757,13 @@ const toggleAttachmentMenu = async () => {
};
const selectAttachmentLocal = () => {
if (!attachmentPolicy.value.canLocal || toolRunShouldLockInput.value) return;
if (!attachmentPolicy.value.canLocal) return;
closeAttachmentMenu();
filePickerRef.value?.click();
};
const selectAttachmentUrl = async () => {
if (!attachmentPolicy.value.canRemote || toolRunShouldLockInput.value) return;
if (!attachmentPolicy.value.canRemote) return;
showAttachmentMenu.value = true;
showAttachmentUrlPanel.value = true;
await nextTick();
@@ -3138,10 +3168,6 @@ const reuploadShippingInventoryFromMappingForm = (msgObj: any) => {
*/
const handleSend = async (textOrEvent?: string | Event) => {
if (toolRunShouldLockInput.value) {
msg.info(toolRunLockMessage.value);
return;
}
const content = (typeof textOrEvent === 'string' ? textOrEvent : null) || input.value;
const trimmed = content.trim();
if ((shippingAutoFlowRequested.value || !trimmed) && isShippingNoticeAgent.value && attachments.value.length > 0 && !isThinking.value && !isUploadingAttachments.value) {
@@ -3613,7 +3639,6 @@ const loadConversation = async (id: string, options?: { force?: boolean }) => {
const loaded = await listChatMessages(id, currentAgentId.value);
loadConversationState(id, Array.isArray(loaded) ? loaded : []);
if (!loaded?.length) {
msg.warning(t('chat.historyEmpty'));
if (isShippingNoticeAgent.value && shippingTaskIdFromQuery.value && !isThinking.value) {
await router.replace({ path: route.path, query: { task_id: shippingTaskIdFromQuery.value } });
return;
@@ -4654,6 +4679,15 @@ const showChatRating = ref(false);
</div>
</div>
<ToolRunProgressCard
v-if="shouldShowToolRunProgressAfterMessage(msg)"
:run="toolRunProgress"
:loading="toolRunProgressLoading"
:error="toolRunProgressError"
:fallback-title="toolRunProgressConfig?.title"
/>
</template>
<div v-if="shouldShowThinkingBubble" class="mx-auto flex w-full max-w-4xl justify-start">
@@ -4672,21 +4706,15 @@ const showChatRating = ref(false);
<footer class="safe-bottom sticky bottom-0 z-20 bg-transparent p-3 md:p-6">
<div class="relative mx-auto max-w-4xl">
<ToolRunProgressCard
:run="toolRunProgress"
:loading="toolRunProgressLoading"
:error="toolRunProgressError"
:fallback-title="toolRunProgressConfig?.title"
/>
<div class="flex flex-col rounded-2xl bg-surface p-2 shadow-[0_0_15px_rgba(0,0,0,0.05)] transition-all">
<textarea
v-model="input"
@keydown.enter.prevent="handleSend"
rows="1"
:placeholder="toolRunShouldLockInput ? toolRunLockMessage : isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : $t('chat.askAnything')"
:placeholder="isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : $t('chat.askAnything')"
class="w-full resize-none border-none bg-transparent px-3 py-2 text-[15px] leading-relaxed text-primary placeholder-slate-400 focus:outline-none focus:ring-0 focus:border-transparent"
style="min-height: 44px; max-height: 220px;"
:disabled="isThinking || isVoiceTranscribing || toolRunShouldLockInput"
:disabled="isThinking || isVoiceTranscribing"
spellcheck="false"
autocorrect="off"
autocapitalize="off"
@@ -4697,7 +4725,6 @@ const showChatRating = ref(false);
type="file"
class="hidden"
accept=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv"
:disabled="toolRunShouldLockInput"
@change="handleShippingInventorySelected"
/>
@@ -4707,7 +4734,6 @@ const showChatRating = ref(false);
multiple
class="hidden"
:accept="attachmentPolicy.accept || undefined"
:disabled="toolRunShouldLockInput"
@change="handleLocalFilesSelected"
/>
@@ -4739,19 +4765,12 @@ const showChatRating = ref(false);
</button>
<span>点发送开始处理</span>
</div>
<div
v-if="toolRunShouldLockInput"
class="px-3 pb-1 text-xs font-medium text-amber-700"
>
{{ toolRunLockMessage }}
</div>
<div class="mt-2 flex items-center justify-between px-2 pb-1">
<div class="flex items-center gap-3">
<button
@click="handleVoiceFeatureClick"
type="button"
:disabled="isThinking || isVoiceTranscribing || toolRunShouldLockInput"
:disabled="isThinking || isVoiceTranscribing"
:title="isVoiceRecording ? $t('chat.voiceStop') : isVoiceTranscribing ? $t('chat.voiceTranscribing') : $t('chat.voiceFeature')"
class="transition-colors disabled:cursor-not-allowed disabled:opacity-50"
:class="isVoiceRecording ? 'text-red-500 animate-pulse' : isVoiceTranscribing ? 'text-brand-500' : 'text-muted hover:text-brand-600'"
@@ -4763,7 +4782,7 @@ const showChatRating = ref(false);
<button
@click="toggleAttachmentMenu"
type="button"
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
:disabled="isThinking || isUploadingAttachments"
title="附件"
class="flex h-9 w-9 items-center justify-center rounded-lg text-muted transition-colors hover:text-brand-600 disabled:cursor-not-allowed disabled:opacity-50"
>
@@ -4796,14 +4815,14 @@ const showChatRating = ref(false);
<input
ref="attachmentUrlInputRef"
v-model="attachmentUrlInput"
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
:disabled="isThinking || isUploadingAttachments"
placeholder="粘贴附件 URL(http/https)"
class="flex-1 rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary placeholder-slate-400 focus:outline-none focus:ring-0"
@keydown.enter.prevent="addRemoteUrlAttachment"
/>
<button
type="button"
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
:disabled="isThinking || isUploadingAttachments"
@click="addRemoteUrlAttachment"
class="flex h-9 w-9 items-center justify-center rounded-lg border border-default text-muted transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
title="添加"
@@ -4812,7 +4831,7 @@ const showChatRating = ref(false);
</button>
<button
type="button"
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
:disabled="isThinking || isUploadingAttachments"
@click="closeAttachmentMenu"
class="flex h-9 w-9 items-center justify-center rounded-lg border border-default text-muted transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
title="取消"