排程管理及排程记录查看功能
This commit is contained in:
1 parent
3b31867319
commit
08776feef2
28 files changed
+3040
-8
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
|
||||
export interface ScheduleTask {
|
||||
id: number;
|
||||
schedule_no: string;
|
||||
name: string;
|
||||
schedule_type: string;
|
||||
owner_user_id: number;
|
||||
owner_username?: string | null;
|
||||
cron_expr: string;
|
||||
wait_seconds: number;
|
||||
dify_agent_id?: number | null;
|
||||
platform_api_path?: string | null;
|
||||
notify_user_ids_json: number[];
|
||||
notify_enabled: boolean;
|
||||
enabled: boolean;
|
||||
next_run_at?: string | null;
|
||||
last_run_at?: string | null;
|
||||
last_status?: string | null;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ScheduleRun {
|
||||
id: number;
|
||||
run_no: string;
|
||||
schedule_task_id: number;
|
||||
schedule_name?: string | null;
|
||||
trigger_type: string;
|
||||
started_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
duration_ms: number;
|
||||
status: string;
|
||||
total_count: number;
|
||||
success_count: number;
|
||||
failed_count: number;
|
||||
skipped_count: number;
|
||||
api_request_json?: Record<string, any> | null;
|
||||
api_response_json?: Record<string, any> | null;
|
||||
response_summary_json?: Record<string, any> | null;
|
||||
error_message?: string | null;
|
||||
excel_file_name?: string | null;
|
||||
excel_file_size?: number | null;
|
||||
mail_sent: boolean;
|
||||
mail_sent_at?: string | null;
|
||||
mail_error?: string | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
async function getJson<T>(url: string): Promise<T> {
|
||||
const res = await fetch(url, { headers: getAuthHeaders() });
|
||||
if (!res.ok) throw new Error((await res.json().catch(() => ({})))?.error || 'Request failed');
|
||||
return (await res.json()) as T;
|
||||
}
|
||||
|
||||
export const listAdminSchedules = () => getJson<ScheduleTask[]>('/api/admin/schedules');
|
||||
export const createAdminSchedule = (payload: Partial<ScheduleTask>) =>
|
||||
fetch('/api/admin/schedules', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const updateAdminSchedule = (id: number, payload: Partial<ScheduleTask>) =>
|
||||
fetch(`/api/admin/schedules/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const deleteAdminSchedule = (id: number) =>
|
||||
fetch(`/api/admin/schedules/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
export const runAdminSchedule = (id: number) =>
|
||||
fetch(`/api/admin/schedules/${id}/run`, { method: 'POST', headers: getAuthHeaders() });
|
||||
export const toggleAdminSchedule = (id: number, enabled: boolean) =>
|
||||
fetch(`/api/admin/schedules/${id}/${enabled ? 'enable' : 'disable'}`, { method: 'POST', headers: getAuthHeaders() });
|
||||
export const listAdminScheduleRuns = (taskId: number, params?: { status?: string; started_after?: string; started_before?: string }) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.status) sp.set('status', params.status);
|
||||
if (params?.started_after) sp.set('started_after', params.started_after);
|
||||
if (params?.started_before) sp.set('started_before', params.started_before);
|
||||
const qs = sp.toString();
|
||||
return getJson<ScheduleRun[]>(`/api/admin/schedules/${taskId}/runs${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
export const adminRunExcelUrl = (runId: number) => `/api/admin/schedule-runs/${runId}/excel`;
|
||||
|
||||
export const listWorkspaceScheduleRuns = (params?: { status?: string; schedule_name?: string; started_after?: string; started_before?: string }) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.status) sp.set('status', params.status);
|
||||
if (params?.schedule_name) sp.set('schedule_name', params.schedule_name);
|
||||
if (params?.started_after) sp.set('started_after', params.started_after);
|
||||
if (params?.started_before) sp.set('started_before', params.started_before);
|
||||
const qs = sp.toString();
|
||||
return getJson<ScheduleRun[]>(`/api/workspace/schedule-runs${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
export const workspaceRunExcelUrl = (runId: number) => `/api/workspace/schedule-runs/${runId}/excel`;
|
||||
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { listWorkspaceScheduleRuns, workspaceRunExcelUrl, type ScheduleRun } from '../api/schedule';
|
||||
|
||||
const isLoading = ref(false);
|
||||
const error = ref('');
|
||||
const runs = ref<ScheduleRun[]>([]);
|
||||
|
||||
const loadRuns = async () => {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
runs.value = await listWorkspaceScheduleRuns();
|
||||
} catch (e: any) {
|
||||
error.value = e?.message || '加载排程记录失败';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
void loadRuns();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mt-6 rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h3 class="text-lg font-semibold text-slate-900">排程记录</h3>
|
||||
<button class="rounded-lg border border-slate-300 px-3 py-1.5 text-sm text-slate-700 hover:bg-slate-50" @click="loadRuns">
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
<p class="mb-3 text-xs text-slate-500">仅展示你是 owner 或在通知名单中的记录</p>
|
||||
<div v-if="isLoading" class="py-6 text-sm text-slate-500">加载中...</div>
|
||||
<div v-else-if="error" class="py-6 text-sm text-rose-500">{{ error }}</div>
|
||||
<div v-else-if="runs.length === 0" class="py-6 text-sm text-slate-400">暂无可见记录</div>
|
||||
<div v-else class="overflow-x-auto">
|
||||
<table class="w-full min-w-[920px] text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-slate-200 text-left text-slate-500">
|
||||
<th class="px-2 py-2">执行单号</th>
|
||||
<th class="px-2 py-2">排程</th>
|
||||
<th class="px-2 py-2">开始</th>
|
||||
<th class="px-2 py-2">结束</th>
|
||||
<th class="px-2 py-2">状态</th>
|
||||
<th class="px-2 py-2">处理</th>
|
||||
<th class="px-2 py-2">成功</th>
|
||||
<th class="px-2 py-2">失败</th>
|
||||
<th class="px-2 py-2">Excel</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="run in runs" :key="run.id" class="border-b border-slate-100 text-slate-700">
|
||||
<td class="px-2 py-2">{{ run.run_no }}</td>
|
||||
<td class="px-2 py-2">{{ run.schedule_name || '-' }}</td>
|
||||
<td class="px-2 py-2">{{ run.started_at || '-' }}</td>
|
||||
<td class="px-2 py-2">{{ run.finished_at || '-' }}</td>
|
||||
<td class="px-2 py-2">{{ run.status }}</td>
|
||||
<td class="px-2 py-2">{{ run.total_count }}</td>
|
||||
<td class="px-2 py-2">{{ run.success_count }}</td>
|
||||
<td class="px-2 py-2">{{ run.failed_count }}</td>
|
||||
<td class="px-2 py-2">
|
||||
<a class="text-brand-600 hover:underline" :href="workspaceRunExcelUrl(run.id)" target="_blank">查看Excel</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -4,7 +4,7 @@ export const config = {
|
||||
// Login mode switch:
|
||||
// - 'casdoor': submit username/password to backend Casdoor password-login API.
|
||||
// - 'password': submit to legacy local /api/user/login.
|
||||
loginMode: 'casdoor',
|
||||
loginMode: 'password',
|
||||
casdoor: {
|
||||
enabled: true,
|
||||
authorizeApi: '/api/user/casdoor/authorize-url',
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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 }}
|
||||
|
||||
Reference in new issue
Block a user