feat(rohs-check): 新增 RoHS 检核工具进度查询功能及相关接口
This commit is contained in:
1 parent
fee33f69d9
commit
a18a07ef1a
19 files changed
+654
-58
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { requestJson } from './client';
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
|
||||
export interface ToolRunProgress {
|
||||
run_id: number;
|
||||
run_no: string;
|
||||
task_id?: number;
|
||||
title: string;
|
||||
status: string;
|
||||
total_count: number;
|
||||
processed_count: number;
|
||||
success_count: number;
|
||||
failed_count: number;
|
||||
skipped_count: number;
|
||||
progress_percent: number;
|
||||
started_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
duration_ms?: number | null;
|
||||
error_message?: string | null;
|
||||
excel?: {
|
||||
file_name?: string | null;
|
||||
file_size?: number | null;
|
||||
download_url?: string | null;
|
||||
};
|
||||
knowledge_base?: {
|
||||
sync_status?: string | null;
|
||||
error_message?: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ToolRunProgressResponse {
|
||||
ok: boolean;
|
||||
run: ToolRunProgress | null;
|
||||
}
|
||||
|
||||
export const getToolRunProgress = (url: string) =>
|
||||
requestJson<ToolRunProgressResponse>(url, { headers: getAuthHeaders() });
|
||||
@@ -0,0 +1,105 @@
|
||||
<script setup lang="ts">
|
||||
import { AlertCircle, CheckCircle2, Clock3, Download, Loader2 } from 'lucide-vue-next';
|
||||
import type { ToolRunProgress } from '@/api/toolRunProgress';
|
||||
|
||||
const props = defineProps<{
|
||||
run: ToolRunProgress | null;
|
||||
loading?: boolean;
|
||||
error?: string;
|
||||
fallbackTitle?: string;
|
||||
}>();
|
||||
|
||||
const statusLabel = (status?: string) => {
|
||||
const map: Record<string, string> = {
|
||||
running: '执行中',
|
||||
success: '已完成',
|
||||
partial_failed: '部分失败',
|
||||
failed: '失败',
|
||||
cancelled: '已取消',
|
||||
canceled: '已取消',
|
||||
};
|
||||
return map[String(status || '')] || status || '等待中';
|
||||
};
|
||||
|
||||
const formatTime = (value?: string | null) => {
|
||||
if (!value) return '-';
|
||||
return String(value).replace('T', ' ').slice(0, 19);
|
||||
};
|
||||
|
||||
const percent = () => Math.max(0, Math.min(Number(props.run?.progress_percent || 0), 100));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
v-if="run || loading || error"
|
||||
class="mx-auto mb-4 w-full max-w-4xl overflow-hidden rounded-2xl border border-sky-100 bg-gradient-to-br from-sky-50 via-white to-emerald-50 shadow-sm"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3 border-b border-sky-100/80 px-4 py-3">
|
||||
<div>
|
||||
<div class="flex items-center gap-2 text-sm font-semibold text-slate-800">
|
||||
<Loader2 v-if="run?.status === 'running'" class="h-4 w-4 animate-spin text-sky-600" />
|
||||
<CheckCircle2 v-else-if="run?.status === 'success'" class="h-4 w-4 text-emerald-600" />
|
||||
<AlertCircle v-else-if="run?.status === 'failed' || run?.status === 'partial_failed'" class="h-4 w-4 text-amber-600" />
|
||||
<Clock3 v-else class="h-4 w-4 text-sky-600" />
|
||||
{{ 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-else-if="loading">正在查询任务进度...</template>
|
||||
<template v-else>{{ error }}</template>
|
||||
</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>
|
||||
|
||||
<div v-if="run" class="space-y-3 px-4 py-4">
|
||||
<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"
|
||||
:style="{ width: `${percent()}%` }"
|
||||
></div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2 text-xs text-slate-500">
|
||||
<span>进度 {{ percent() }}%</span>
|
||||
<span>开始:{{ formatTime(run.started_at) }} · 完成:{{ formatTime(run.finished_at) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-2 md:grid-cols-5">
|
||||
<div class="rounded-xl bg-white/80 px-3 py-2">
|
||||
<div class="text-xs text-slate-500">总数</div>
|
||||
<div class="text-lg font-bold text-slate-800">{{ run.total_count }}</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-white/80 px-3 py-2">
|
||||
<div class="text-xs text-slate-500">已处理</div>
|
||||
<div class="text-lg font-bold text-sky-700">{{ run.processed_count }}</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-white/80 px-3 py-2">
|
||||
<div class="text-xs text-slate-500">成功</div>
|
||||
<div class="text-lg font-bold text-emerald-700">{{ run.success_count }}</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-white/80 px-3 py-2">
|
||||
<div class="text-xs text-slate-500">失败</div>
|
||||
<div class="text-lg font-bold text-rose-700">{{ run.failed_count }}</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-white/80 px-3 py-2">
|
||||
<div class="text-xs text-slate-500">跳过</div>
|
||||
<div class="text-lg font-bold text-amber-700">{{ run.skipped_count }}</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>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,97 @@
|
||||
import { computed, onBeforeUnmount, ref, type Ref, watch } from 'vue';
|
||||
import { getToolRunProgress, type ToolRunProgress } from '@/api/toolRunProgress';
|
||||
|
||||
export interface ToolRunProgressConfig {
|
||||
type?: string;
|
||||
title?: string;
|
||||
poll_interval_seconds?: number;
|
||||
active_url?: string;
|
||||
detail_url_template?: string;
|
||||
lock_input_when_running?: boolean;
|
||||
lock_message?: string;
|
||||
}
|
||||
|
||||
const TERMINAL_STATUSES = new Set(['success', 'partial_failed', 'failed', 'cancelled', 'canceled']);
|
||||
|
||||
const clampPollMs = (seconds: unknown) => {
|
||||
const raw = Number(seconds);
|
||||
const safe = Number.isFinite(raw) ? raw : 2;
|
||||
return Math.max(1, Math.min(safe, 30)) * 1000;
|
||||
};
|
||||
|
||||
export function useToolRunProgress(configRef: Ref<ToolRunProgressConfig | null>) {
|
||||
const run = ref<ToolRunProgress | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
let timer: number | undefined;
|
||||
|
||||
const enabled = computed(() => !!configRef.value?.active_url);
|
||||
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 || '当前任务执行中,请等待完成');
|
||||
|
||||
const clearTimer = () => {
|
||||
if (timer !== undefined) {
|
||||
window.clearTimeout(timer);
|
||||
timer = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleNext = () => {
|
||||
clearTimer();
|
||||
if (!enabled.value) return;
|
||||
const interval = clampPollMs(configRef.value?.poll_interval_seconds);
|
||||
timer = window.setTimeout(() => {
|
||||
void refresh();
|
||||
}, interval);
|
||||
};
|
||||
|
||||
const refresh = async () => {
|
||||
const cfg = configRef.value;
|
||||
if (!cfg?.active_url) {
|
||||
run.value = null;
|
||||
error.value = '';
|
||||
clearTimer();
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const payload = await getToolRunProgress(cfg.active_url);
|
||||
run.value = payload.run;
|
||||
error.value = '';
|
||||
} catch (e: any) {
|
||||
error.value = e?.message || '任务进度查询失败';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
if (!run.value || run.value.status === 'running' || !TERMINAL_STATUSES.has(run.value.status)) {
|
||||
scheduleNext();
|
||||
} else {
|
||||
clearTimer();
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => JSON.stringify(configRef.value || {}),
|
||||
() => {
|
||||
run.value = null;
|
||||
error.value = '';
|
||||
clearTimer();
|
||||
if (enabled.value) void refresh();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
onBeforeUnmount(clearTimer);
|
||||
|
||||
return {
|
||||
run,
|
||||
loading,
|
||||
error,
|
||||
isRunning,
|
||||
shouldLockInput,
|
||||
lockMessage,
|
||||
refresh,
|
||||
};
|
||||
}
|
||||
@@ -12,9 +12,11 @@ import LocaleToggleButton from '@/components/LocaleToggleButton.vue';
|
||||
import FilePreviewModal from '@/components/FilePreviewModal.vue';
|
||||
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog.vue';
|
||||
import GeneralFeedbackDialog from '@/components/GeneralFeedbackDialog.vue';
|
||||
import ToolRunProgressCard from '@/features/chat/components/ToolRunProgressCard.vue';
|
||||
import ChatShell from '@/layouts/ChatShell.vue';
|
||||
import { useChat } from '@/features/chat/composables/useChat';
|
||||
import { useChatSourceFiles } from '@/features/chat/composables/useChatSourceFiles';
|
||||
import { useToolRunProgress, type ToolRunProgressConfig } from '@/features/chat/composables/useToolRunProgress';
|
||||
import { config } from '@/config';
|
||||
import {
|
||||
listChatSessions,
|
||||
@@ -439,7 +441,7 @@ const handleVoiceFeatureClick = () => {
|
||||
msg.info(t('chat.devComingSoon'));
|
||||
return;
|
||||
}
|
||||
if (isThinking.value || isVoiceTranscribing.value) return;
|
||||
if (isThinking.value || isVoiceTranscribing.value || toolRunShouldLockInput.value) return;
|
||||
const unavailable = getVoiceUnavailableErrorKey();
|
||||
if (unavailable) {
|
||||
msg.warning(t(unavailable));
|
||||
@@ -458,6 +460,22 @@ 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 toolRunProgressConfig = computed<ToolRunProgressConfig | null>(() => {
|
||||
const extra = currentAgent.value?.extra_config || {};
|
||||
const capabilities = Array.isArray(extra.capabilities) ? extra.capabilities.map((item: unknown) => String(item)) : [];
|
||||
if (!capabilities.includes('tool_run_progress')) return null;
|
||||
const raw = extra.tool_run_progress;
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
return raw as ToolRunProgressConfig;
|
||||
});
|
||||
const {
|
||||
run: toolRunProgress,
|
||||
loading: toolRunProgressLoading,
|
||||
error: toolRunProgressError,
|
||||
shouldLockInput: toolRunShouldLockInput,
|
||||
lockMessage: toolRunLockMessage,
|
||||
} = useToolRunProgress(toolRunProgressConfig);
|
||||
|
||||
type AgentSuggestedQuestionItem = {
|
||||
question: string;
|
||||
group: string;
|
||||
@@ -674,7 +692,7 @@ const showAttachmentMenu = ref(false);
|
||||
const showAttachmentUrlPanel = ref(false);
|
||||
|
||||
const canSendMessage = computed(() => {
|
||||
if (isThinking.value || isUploadingAttachments.value) return false;
|
||||
if (isThinking.value || isUploadingAttachments.value || toolRunShouldLockInput.value) return false;
|
||||
if (input.value.trim()) return true;
|
||||
if (isShippingNoticeAgent.value && attachments.value.length > 0) return true;
|
||||
return false;
|
||||
@@ -687,7 +705,7 @@ const closeAttachmentMenu = () => {
|
||||
};
|
||||
|
||||
const toggleAttachmentMenu = async () => {
|
||||
if (isThinking.value || isUploadingAttachments.value) return;
|
||||
if (isThinking.value || isUploadingAttachments.value || toolRunShouldLockInput.value) return;
|
||||
showAttachmentMenu.value = !showAttachmentMenu.value;
|
||||
if (!showAttachmentMenu.value) {
|
||||
showAttachmentUrlPanel.value = false;
|
||||
@@ -696,13 +714,13 @@ const toggleAttachmentMenu = async () => {
|
||||
};
|
||||
|
||||
const selectAttachmentLocal = () => {
|
||||
if (!attachmentPolicy.value.canLocal) return;
|
||||
if (!attachmentPolicy.value.canLocal || toolRunShouldLockInput.value) return;
|
||||
closeAttachmentMenu();
|
||||
filePickerRef.value?.click();
|
||||
};
|
||||
|
||||
const selectAttachmentUrl = async () => {
|
||||
if (!attachmentPolicy.value.canRemote) return;
|
||||
if (!attachmentPolicy.value.canRemote || toolRunShouldLockInput.value) return;
|
||||
showAttachmentMenu.value = true;
|
||||
showAttachmentUrlPanel.value = true;
|
||||
await nextTick();
|
||||
@@ -3107,6 +3125,10 @@ 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) {
|
||||
@@ -4063,6 +4085,12 @@ const showChatRating = ref(false);
|
||||
<div
|
||||
:class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'"
|
||||
>
|
||||
<ToolRunProgressCard
|
||||
:run="toolRunProgress"
|
||||
:loading="toolRunProgressLoading"
|
||||
:error="toolRunProgressError"
|
||||
:fallback-title="toolRunProgressConfig?.title"
|
||||
/>
|
||||
<div v-if="messages.length === 0" class="flex h-full min-h-0 w-full flex-col items-center px-4 pt-2 pb-2 md:pb-3">
|
||||
<template v-if="suggestedQuestionsStyle === 'styled' && styledSuggestedQuestionSections.length > 0">
|
||||
<div class="mb-6 mt-2 flex h-16 w-16 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||
@@ -4640,10 +4668,10 @@ const showChatRating = ref(false);
|
||||
v-model="input"
|
||||
@keydown.enter.prevent="handleSend"
|
||||
rows="1"
|
||||
:placeholder="isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : $t('chat.askAnything')"
|
||||
:placeholder="toolRunShouldLockInput ? toolRunLockMessage : 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"
|
||||
:disabled="isThinking || isVoiceTranscribing || toolRunShouldLockInput"
|
||||
spellcheck="false"
|
||||
autocorrect="off"
|
||||
autocapitalize="off"
|
||||
@@ -4654,6 +4682,7 @@ 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"
|
||||
/>
|
||||
|
||||
@@ -4663,6 +4692,7 @@ const showChatRating = ref(false);
|
||||
multiple
|
||||
class="hidden"
|
||||
:accept="attachmentPolicy.accept || undefined"
|
||||
:disabled="toolRunShouldLockInput"
|
||||
@change="handleLocalFilesSelected"
|
||||
/>
|
||||
|
||||
@@ -4694,13 +4724,19 @@ 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"
|
||||
:disabled="isThinking || isVoiceTranscribing || toolRunShouldLockInput"
|
||||
: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'"
|
||||
@@ -4712,7 +4748,7 @@ const showChatRating = ref(false);
|
||||
<button
|
||||
@click="toggleAttachmentMenu"
|
||||
type="button"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
|
||||
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"
|
||||
>
|
||||
@@ -4745,14 +4781,14 @@ const showChatRating = ref(false);
|
||||
<input
|
||||
ref="attachmentUrlInputRef"
|
||||
v-model="attachmentUrlInput"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
|
||||
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"
|
||||
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
|
||||
@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="添加"
|
||||
@@ -4761,7 +4797,7 @@ const showChatRating = ref(false);
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
:disabled="isThinking || isUploadingAttachments || toolRunShouldLockInput"
|
||||
@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="取消"
|
||||
|
||||
Reference in new issue
Block a user