排程管理及排程记录查看功能

This commit is contained in:
hugo committed 2026-05-18 14:55:01 +08:00
1 parent 3b31867319
commit 08776feef2
28 files changed
+3040 -8

No files matched your search

+207 -1
View File
@@ -50,6 +50,8 @@ import {
} from 'lucide-vue-next';
import KbWorkspaceView from './KbWorkspaceView.vue';
import { listWorkspaceScheduleRuns, workspaceRunExcelUrl, type ScheduleRun } from '../api/schedule';
import { Clock, Download, Search, RefreshCw } from 'lucide-vue-next';
const { t, locale } = useI18n();
const { showMessageDialog } = useGlobalMessageDialog();
@@ -758,7 +760,7 @@ const handleRegister = async () => {
}
};
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates' | 'knowledge_base'>('applications');
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates' | 'knowledge_base' | 'schedule_runs'>('applications');
const isProfileLoading = ref(false);
const isProfileSaving = ref(false);
const isProfileEditing = ref(false);
@@ -982,6 +984,99 @@ const navigateToKnowledgeBase = () => {
activeSidebarItem.value = 'knowledge_base';
};
const navigateToScheduleRuns = () => {
activeSidebarItem.value = 'schedule_runs';
loadWorkspaceScheduleRuns();
};
const workspaceScheduleRuns = ref<ScheduleRun[]>([]);
const workspaceScheduleLoading = ref(false);
const wsScheduleStatusFilter = ref('all');
const wsScheduleNameFilter = ref('');
const wsScheduleStartedAfter = ref('');
const wsScheduleStartedBefore = ref('');
const wsScheduleStatusOptions = [
{ value: 'all', label: '全部状态' },
{ value: 'success', label: '成功' },
{ value: 'partial_failed', label: '部分成功' },
{ value: 'failed', label: '失败' },
{ value: 'running', label: '执行中' },
];
const getWsScheduleStatusBadge = (status: string) => {
const map: Record<string, { cls: string; label: string }> = {
success: { cls: 'bg-emerald-100 text-emerald-700', label: '成功' },
partial_failed: { cls: 'bg-blue-100 text-blue-700', label: '部分成功' },
failed: { cls: 'bg-rose-100 text-rose-700', label: '失败' },
running: { cls: 'bg-amber-100 text-amber-700', label: '执行中' },
queued: { cls: 'bg-slate-100 text-slate-600', label: '排队中' },
};
return map[status] || { cls: 'bg-slate-100 text-slate-600', label: status };
};
const formatDateTime = (iso?: string | null) => {
if (!iso) return '-';
const d = new Date(iso);
if (isNaN(d.getTime())) return iso;
const pad = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
};
const todayStart = () => {
const d = new Date();
d.setHours(0, 0, 0, 0);
return d.toISOString();
};
const todayEnd = () => {
const d = new Date();
d.setHours(23, 59, 59, 0);
return d.toISOString();
};
const loadWorkspaceScheduleRuns = async () => {
workspaceScheduleLoading.value = true;
try {
const params: { status?: string; schedule_name?: string; started_after?: string; started_before?: string } = {};
if (wsScheduleStatusFilter.value !== 'all') params.status = wsScheduleStatusFilter.value;
if (wsScheduleNameFilter.value.trim()) params.schedule_name = wsScheduleNameFilter.value.trim();
if (wsScheduleStartedAfter.value) params.started_after = new Date(wsScheduleStartedAfter.value).toISOString();
if (wsScheduleStartedBefore.value) params.started_before = new Date(wsScheduleStartedBefore.value).toISOString();
workspaceScheduleRuns.value = await listWorkspaceScheduleRuns(params);
} catch {
workspaceScheduleRuns.value = [];
} finally {
workspaceScheduleLoading.value = false;
}
};
const resetWsScheduleFilters = () => {
wsScheduleStatusFilter.value = 'all';
wsScheduleNameFilter.value = '';
wsScheduleStartedAfter.value = todayStart().slice(0, 16);
wsScheduleStartedBefore.value = todayEnd().slice(0, 16);
loadWorkspaceScheduleRuns();
};
const downloadWsScheduleExcel = async (runId: number) => {
const res = await fetch(workspaceRunExcelUrl(runId), { headers: getAuthHeaders() });
if (!res.ok) {
showMessageDialog('error', '下载 Excel 失败');
return;
}
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const disposition = res.headers.get('content-disposition');
a.download = disposition?.match(/filename\*?=(?:UTF-8'')?["']?([^;"'\n]+)/)?.[1] || 'result.xlsx';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
const navigateToGeneralChat = () => {
router.push(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
};
@@ -1397,6 +1492,14 @@ onMounted(async () => {
<FileText class="h-4 w-4" />
<span>知识库管理</span>
</button>
<button
@click="navigateToScheduleRuns"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'schedule_runs' ? 'bg-brand-50 text-brand-700 shadow-sm' : 'text-slate-600 hover:bg-slate-50 hover:text-slate-900'"
>
<Clock class="h-4 w-4" />
<span>排程记录</span>
</button>
<button
@click="openGeneralFeedback"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
@@ -1616,6 +1719,109 @@ onMounted(async () => {
<KbWorkspaceView :embedded="true" />
</template>
<template v-else-if="activeSidebarItem === 'schedule_runs'">
<div class="space-y-5 animate-fade-in-up">
<div class="flex items-center justify-between">
<h2 class="text-2xl font-bold text-slate-900">排程记录</h2>
<button
@click="loadWorkspaceScheduleRuns"
class="inline-flex items-center gap-1.5 rounded-xl border border-slate-200 px-3 py-1.5 text-sm font-medium text-slate-600 transition-colors hover:bg-slate-50"
>
<RefreshCw class="h-3.5 w-3.5" />
刷新
</button>
</div>
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-slate-200 bg-slate-50/40 px-4 py-3">
<div>
<label class="mb-1 block text-xs font-medium text-slate-500">排程名称</label>
<input type="text" v-model="wsScheduleNameFilter" placeholder="输入排程名称" class="!w-[150px] !py-1 !px-2 !text-xs rounded-lg border border-slate-200 bg-white" />
</div>
<div>
<label class="mb-1 block text-xs font-medium text-slate-500">开始时间</label>
<input type="datetime-local" step="1" v-model="wsScheduleStartedAfter" class="!w-[170px] !py-1 !px-2 !text-xs rounded-lg border border-slate-200 bg-white" />
</div>
<div>
<label class="mb-1 block text-xs font-medium text-slate-500">结束时间</label>
<input type="datetime-local" step="1" v-model="wsScheduleStartedBefore" class="!w-[170px] !py-1 !px-2 !text-xs rounded-lg border border-slate-200 bg-white" />
</div>
<div>
<label class="mb-1 block text-xs font-medium text-slate-500">状态</label>
<select v-model="wsScheduleStatusFilter" class="!w-[120px] !py-1 !px-2 !text-xs rounded-lg border border-slate-200 bg-white">
<option v-for="o in wsScheduleStatusOptions" :key="o.value" :value="o.value">{{ o.label }}</option>
</select>
</div>
<button
@click="loadWorkspaceScheduleRuns"
class="inline-flex items-center gap-1 rounded-xl bg-brand-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-brand-700"
>
<Search class="h-3.5 w-3.5" />
查询
</button>
<button
@click="resetWsScheduleFilters"
class="rounded-xl border border-slate-200 px-3 py-1.5 text-sm font-medium text-slate-600 transition-colors hover:bg-slate-50"
>
重置
</button>
</div>
<div v-if="workspaceScheduleLoading" class="py-10 text-center text-sm text-slate-400">正在加载...</div>
<div v-else-if="workspaceScheduleRuns.length === 0" class="py-10 text-center text-sm text-slate-400">暂无排程记录</div>
<div v-else class="overflow-hidden rounded-2xl border border-slate-200 bg-white">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-slate-100 bg-slate-50/60">
<th class="px-4 py-3 text-left font-semibold text-slate-600">排程名称</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">运行编号</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">触发方式</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">开始时间</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">结束时间</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">耗时</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">状态</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">处理笔数</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">成功笔数</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">失败笔数</th>
<th class="px-4 py-3 text-left font-semibold text-slate-600">明细</th>
</tr>
</thead>
<tbody>
<tr v-for="r in workspaceScheduleRuns" :key="r.id" class="border-b border-slate-50 transition-colors hover:bg-slate-50/50">
<td class="px-4 py-3 font-medium text-slate-900">{{ r.schedule_name || '-' }}</td>
<td class="px-4 py-3 text-slate-500 font-mono text-xs">{{ r.run_no }}</td>
<td class="px-4 py-3 text-slate-500">{{ r.trigger_type === 'manual' ? '手动' : '定时' }}</td>
<td class="px-4 py-3 text-slate-500 whitespace-nowrap">{{ formatDateTime(r.started_at) }}</td>
<td class="px-4 py-3 text-slate-500 whitespace-nowrap">{{ formatDateTime(r.finished_at) }}</td>
<td class="px-4 py-3 text-slate-500 whitespace-nowrap">{{ r.duration_ms != null ? (r.duration_ms >= 1000 ? (r.duration_ms / 1000).toFixed(1) + 's' : r.duration_ms + 'ms') : '-' }}</td>
<td class="px-4 py-3">
<span class="inline-flex shrink-0 items-center whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-semibold" :class="getWsScheduleStatusBadge(r.status).cls">
{{ getWsScheduleStatusBadge(r.status).label }}
</span>
<span v-if="r.error_message && r.error_message !== '无待处理数据'" class="ml-1 text-xs text-slate-400" :title="r.error_message">...</span>
<span v-else-if="r.error_message === '无待处理数据'" class="ml-1 text-xs text-slate-400">(无待处理数据)</span>
</td>
<td class="px-4 py-3 text-slate-500">{{ r.total_count || 0 }}</td>
<td class="px-4 py-3 text-emerald-600 font-medium">{{ r.success_count ?? 0 }}</td>
<td class="px-4 py-3 text-rose-600 font-medium">{{ r.failed_count ?? 0 }}</td>
<td class="px-4 py-3">
<a
v-if="r.total_count > 0 && r.excel_file_name"
href="#"
@click.prevent="downloadWsScheduleExcel(r.id)"
class="inline-flex items-center gap-1 rounded-lg border border-slate-200 px-2 py-1 text-xs font-medium text-slate-600 transition-colors hover:bg-slate-50"
>
<Download class="h-3 w-3" />
下载
</a>
<span v-else class="text-xs text-slate-300">-</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<template v-else>
<div v-if="wecomEntryHint" class="rounded-2xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-700">
{{ wecomEntryHint }}