feat: 修复仪表盘数据管线 — 补充应用发布种子数据 + 修复limit参数解析 + LDAP认证集成 + User类型完善
后端改进: - 修复 dashboard/recent-alerts 的 limit 参数解析 (原代码错误地将数字解析为日期) - 为 dashboard/recent-releases 添加 limit 参数解析支持 - 新增 generateAppReleases 种子数据生成函数 (10条应用发布记录) - 修复 AlertEvent 的 rule_name/rule_id/severity 数据一致性 - 添加 go-ldap/ldap/v3 依赖并集成 LDAP 认证处理器 - 添加 seed.go 自动种子数据初始化 (admin用户+LDAP配置) - User model 添加 AuthSource/LDAPConfig 字段 前端改进: - 修复 User 类型定义以匹配后端 API (real_name/is_admin/auth_source等) - 修复 Header.tsx 的 real_name 属性引用导致 TypeScript 编译错误 - 统一 API 服务层、暗色主题样式、组件联调优化 验证: - go build ./... 编译通过 - npm run build 构建通过 - 仪表盘发布历史、告警消息等区域数据正常展示 - 健康检查 /health 正常
This commit is contained in:
1 parent
97c4207ff8
commit
ff0b268984
39 files changed
+4283
-1878
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -41,30 +41,66 @@ import {
|
||||
Edit,
|
||||
Copy,
|
||||
Download,
|
||||
Loader2,
|
||||
} from 'lucide-react';
|
||||
import { cronJobs, scripts } from '@/mocks/data';
|
||||
import type { CronJob, Script } from '@/types';
|
||||
import { cronJobApi, scriptApi } from '@/services/api';
|
||||
|
||||
function parseParams(params: any) {
|
||||
if (Array.isArray(params)) return params;
|
||||
if (typeof params === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(params);
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function AutomationManager() {
|
||||
const [activeTab, setActiveTab] = useState('cronjobs');
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [selectedScript, setSelectedScript] = useState<Script | null>(null);
|
||||
const [cronJobs, setCronJobs] = useState<any[]>([]);
|
||||
const [scripts, setScripts] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selectedScript, setSelectedScript] = useState<any | null>(null);
|
||||
const [isExecuteDialogOpen, setIsExecuteDialogOpen] = useState(false);
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const [jobsData, scriptsData] = await Promise.all([
|
||||
cronJobApi.getJobs(),
|
||||
scriptApi.getScripts(),
|
||||
]);
|
||||
setCronJobs(jobsData.list || []);
|
||||
setScripts(scriptsData.list || []);
|
||||
} catch (error) {
|
||||
console.error('Failed to load automation data:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
const filteredJobs = cronJobs.filter(
|
||||
(job) =>
|
||||
job.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
job.description.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
(job.name || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
(job.description || '').toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
|
||||
const filteredScripts = scripts.filter(
|
||||
(script) =>
|
||||
script.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
script.description.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
(script.name || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
(script.description || '').toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
|
||||
const getJobStatusBadge = (status: CronJob['status']) => {
|
||||
return status === 'running' ? (
|
||||
const getJobStatusBadge = (status: any) => {
|
||||
return status === 1 ? (
|
||||
<Badge variant="outline" className="border-emerald-500/30 text-emerald-400 bg-emerald-500/10">
|
||||
<Play className="h-3 w-3 mr-1" />
|
||||
运行中
|
||||
@@ -77,19 +113,28 @@ export function AutomationManager() {
|
||||
);
|
||||
};
|
||||
|
||||
const getLanguageBadge = (language: Script['language']) => {
|
||||
const colors = {
|
||||
const getLanguageBadge = (language: any) => {
|
||||
const colors: Record<string, string> = {
|
||||
bash: 'border-green-500/30 text-green-400 bg-green-500/10',
|
||||
python: 'border-blue-500/30 text-blue-400 bg-blue-500/10',
|
||||
powershell: 'border-cyan-500/30 text-cyan-400 bg-cyan-500/10',
|
||||
};
|
||||
return (
|
||||
<Badge variant="outline" className={colors[language]}>
|
||||
{language.toUpperCase()}
|
||||
<Badge variant="outline" className={colors[language] || colors.bash}>
|
||||
{(language || '').toUpperCase()}
|
||||
</Badge>
|
||||
);
|
||||
};
|
||||
|
||||
const handleExecuteScript = async (id: any) => {
|
||||
try {
|
||||
await scriptApi.executeScript(id);
|
||||
setIsExecuteDialogOpen(false);
|
||||
} catch (error) {
|
||||
console.error('Failed to execute script:', error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Page Header */}
|
||||
@@ -131,7 +176,7 @@ export function AutomationManager() {
|
||||
<div>
|
||||
<p className="text-sm text-slate-500">运行中</p>
|
||||
<p className="text-2xl font-bold text-emerald-400">
|
||||
{cronJobs.filter((j) => j.status === 'running').length}
|
||||
{cronJobs.filter((j) => j.status === 1).length}
|
||||
</p>
|
||||
</div>
|
||||
<div className="p-3 rounded-lg bg-emerald-500/10 text-emerald-400">
|
||||
@@ -157,8 +202,10 @@ export function AutomationManager() {
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm text-slate-500">今日执行</p>
|
||||
<p className="text-2xl font-bold text-blue-400">156</p>
|
||||
<p className="text-sm text-slate-500">累计执行</p>
|
||||
<p className="text-2xl font-bold text-blue-400">
|
||||
{cronJobs.reduce((sum, j) => sum + (j.success_count || 0) + (j.fail_count || 0), 0)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="p-3 rounded-lg bg-cyan-500/10 text-cyan-400">
|
||||
<RotateCw className="h-5 w-5" />
|
||||
@@ -181,6 +228,12 @@ export function AutomationManager() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="h-6 w-6 text-slate-500 animate-spin" />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Tabs */}
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
|
||||
<TabsList className="bg-slate-800 border border-slate-700">
|
||||
@@ -234,24 +287,29 @@ export function AutomationManager() {
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm text-slate-400">
|
||||
{job.lastRunAt ? new Date(job.lastRunAt).toLocaleString() : '--'}
|
||||
{job.last_run ? new Date(job.last_run).toLocaleString() : '--'}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm text-slate-400">
|
||||
{job.nextRunAt ? new Date(job.nextRunAt).toLocaleString() : '--'}
|
||||
{job.next_run ? new Date(job.next_run).toLocaleString() : '--'}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="text-sm">
|
||||
<span className="text-emerald-400">{job.successCount}</span>
|
||||
<span className="text-emerald-400">{job.success_count || 0}</span>
|
||||
<span className="text-slate-500 mx-1">/</span>
|
||||
<span className="text-red-400">{job.failCount}</span>
|
||||
<span className="text-red-400">{job.fail_count || 0}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-slate-400 hover:text-blue-400">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-slate-400 hover:text-blue-400"
|
||||
onClick={() => cronJobApi.executeJob(job.id)}
|
||||
>
|
||||
<Play className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-slate-400 hover:text-slate-100">
|
||||
@@ -290,11 +348,11 @@ export function AutomationManager() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="bg-slate-950 rounded-lg p-3 font-mono text-xs text-slate-400 overflow-x-auto">
|
||||
<pre className="whitespace-pre-wrap">{script.content.slice(0, 200)}...</pre>
|
||||
<pre className="whitespace-pre-wrap">{(script.content || '').slice(0, 200)}...</pre>
|
||||
</div>
|
||||
<div className="flex items-center justify-between mt-4">
|
||||
<div className="flex gap-2">
|
||||
{script.params.map((param) => (
|
||||
{parseParams(script.params).map((param: any) => (
|
||||
<Badge key={param.name} variant="outline" className="border-slate-700 text-slate-400 text-xs">
|
||||
{param.name}
|
||||
{param.required && <span className="text-red-400 ml-0.5">*</span>}
|
||||
@@ -367,7 +425,7 @@ export function AutomationManager() {
|
||||
<div className="flex items-center gap-2">
|
||||
{selectedScript && getLanguageBadge(selectedScript.language)}
|
||||
<span className="text-sm text-slate-500">
|
||||
更新于 {selectedScript && new Date(selectedScript.updatedAt).toLocaleDateString()}
|
||||
更新于 {selectedScript && selectedScript.updated_at ? new Date(selectedScript.updated_at).toLocaleDateString() : '--'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -375,11 +433,11 @@ export function AutomationManager() {
|
||||
<pre className="whitespace-pre">{selectedScript?.content}</pre>
|
||||
</div>
|
||||
|
||||
{selectedScript && selectedScript.params.length > 0 && (
|
||||
{selectedScript && parseParams(selectedScript.params).length > 0 && (
|
||||
<div>
|
||||
<h4 className="text-sm font-medium text-slate-300 mb-2">参数</h4>
|
||||
<div className="space-y-2">
|
||||
{selectedScript.params.map((param) => (
|
||||
{parseParams(selectedScript.params).map((param: any) => (
|
||||
<div key={param.name} className="flex items-center gap-2 p-2 rounded-lg bg-slate-800/50">
|
||||
<code className="text-sm text-slate-300">{param.name}</code>
|
||||
<Badge variant="outline" className="border-slate-700 text-slate-400 text-xs">
|
||||
@@ -444,7 +502,7 @@ export function AutomationManager() {
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{selectedScript?.params.map((param) => (
|
||||
{selectedScript && parseParams(selectedScript.params).map((param: any) => (
|
||||
<div key={param.name}>
|
||||
<label className="text-sm font-medium text-slate-300">
|
||||
{param.name}
|
||||
@@ -463,7 +521,7 @@ export function AutomationManager() {
|
||||
<Button variant="outline" className="border-slate-700 text-slate-300" onClick={() => setIsExecuteDialogOpen(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button className="bg-blue-600 hover:bg-blue-700 text-white">
|
||||
<Button className="bg-blue-600 hover:bg-blue-700 text-white" onClick={() => selectedScript && handleExecuteScript(selectedScript.id)}>
|
||||
<Play className="h-4 w-4 mr-2" />
|
||||
开始执行
|
||||
</Button>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -49,123 +49,46 @@ import {
|
||||
Eye,
|
||||
Copy,
|
||||
} from 'lucide-react';
|
||||
import { cronJobs } from '@/mocks/data';
|
||||
|
||||
interface CronJob {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
schedule: string;
|
||||
command: string;
|
||||
status: 'enabled' | 'disabled';
|
||||
lastRun: string;
|
||||
lastStatus: 'success' | 'failed' | 'running' | 'never';
|
||||
nextRun: string;
|
||||
targetServers: string[];
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
}
|
||||
|
||||
const mockCronJobs: CronJob[] = [
|
||||
{
|
||||
id: 'cron-001',
|
||||
name: '数据库备份',
|
||||
description: '每日凌晨2点备份数据库',
|
||||
schedule: '0 2 * * *',
|
||||
command: '/scripts/backup-db.sh --type=full',
|
||||
status: 'enabled',
|
||||
lastRun: '2025-04-14 02:00:00',
|
||||
lastStatus: 'success',
|
||||
nextRun: '2025-04-15 02:00:00',
|
||||
targetServers: ['db-server-01', 'db-server-02'],
|
||||
createdAt: '2025-01-15',
|
||||
createdBy: 'admin',
|
||||
},
|
||||
{
|
||||
id: 'cron-002',
|
||||
name: '日志清理',
|
||||
description: '每周日凌晨3点清理过期日志',
|
||||
schedule: '0 3 * * 0',
|
||||
command: '/scripts/clean-logs.sh --days=30',
|
||||
status: 'enabled',
|
||||
lastRun: '2025-04-13 03:00:00',
|
||||
lastStatus: 'success',
|
||||
nextRun: '2025-04-20 03:00:00',
|
||||
targetServers: ['all'],
|
||||
createdAt: '2025-01-20',
|
||||
createdBy: 'admin',
|
||||
},
|
||||
{
|
||||
id: 'cron-003',
|
||||
name: '健康检查',
|
||||
description: '每5分钟执行健康检查',
|
||||
schedule: '*/5 * * * *',
|
||||
command: '/scripts/health-check.sh',
|
||||
status: 'enabled',
|
||||
lastRun: '2025-04-14 11:55:00',
|
||||
lastStatus: 'running',
|
||||
nextRun: '2025-04-14 12:00:00',
|
||||
targetServers: ['web-server-01', 'web-server-02', 'app-server-01'],
|
||||
createdAt: '2025-02-01',
|
||||
createdBy: 'ops01',
|
||||
},
|
||||
{
|
||||
id: 'cron-004',
|
||||
name: '数据同步',
|
||||
description: '每小时同步数据到备份服务器',
|
||||
schedule: '0 * * * *',
|
||||
command: '/scripts/sync-data.sh --target=backup',
|
||||
status: 'disabled',
|
||||
lastRun: '2025-04-14 10:00:00',
|
||||
lastStatus: 'failed',
|
||||
nextRun: '-',
|
||||
targetServers: ['app-server-01'],
|
||||
createdAt: '2025-02-15',
|
||||
createdBy: 'ops02',
|
||||
},
|
||||
{
|
||||
id: 'cron-005',
|
||||
name: '生成报表',
|
||||
description: '每周一上午9点生成业务报表',
|
||||
schedule: '0 9 * * 1',
|
||||
command: '/scripts/generate-report.sh --type=weekly',
|
||||
status: 'enabled',
|
||||
lastRun: '2025-04-07 09:00:00',
|
||||
lastStatus: 'success',
|
||||
nextRun: '2025-04-21 09:00:00',
|
||||
targetServers: ['report-server'],
|
||||
createdAt: '2025-03-01',
|
||||
createdBy: 'admin',
|
||||
},
|
||||
];
|
||||
|
||||
const executionLogs = [
|
||||
{ id: 1, jobName: '数据库备份', startTime: '2025-04-14 02:00:00', endTime: '2025-04-14 02:15:30', duration: '15m 30s', status: 'success', output: '备份完成: 15.2GB' },
|
||||
{ id: 2, jobName: '健康检查', startTime: '2025-04-14 11:55:00', endTime: '2025-04-14 11:55:05', duration: '5s', status: 'success', output: '所有服务正常' },
|
||||
{ id: 3, jobName: '数据同步', startTime: '2025-04-14 10:00:00', endTime: '2025-04-14 10:05:23', duration: '5m 23s', status: 'failed', output: '连接超时' },
|
||||
{ id: 4, jobName: '日志清理', startTime: '2025-04-13 03:00:00', endTime: '2025-04-13 03:02:15', duration: '2m 15s', status: 'success', output: '清理完成: 2.3GB' },
|
||||
];
|
||||
import { cronJobApi } from '@/services/api';
|
||||
|
||||
export function CronJobManager() {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [jobs, setJobs] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
|
||||
const [isLogDialogOpen, setIsLogDialogOpen] = useState(false);
|
||||
const [selectedJob, setSelectedJob] = useState<CronJob | null>(null);
|
||||
const [selectedJob, setSelectedJob] = useState<any | null>(null);
|
||||
const [newJob, setNewJob] = useState({
|
||||
name: '',
|
||||
description: '',
|
||||
schedule: '',
|
||||
cron: '',
|
||||
command: '',
|
||||
targetServers: '',
|
||||
});
|
||||
|
||||
const filteredJobs = mockCronJobs.filter(
|
||||
const loadData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await cronJobApi.getJobs();
|
||||
setJobs(data.list || []);
|
||||
} catch (error) {
|
||||
console.error('Failed to load cron jobs:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
const filteredJobs = jobs.filter(
|
||||
(job) =>
|
||||
job.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
job.description.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
(job.name || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
(job.description || '').toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
|
||||
const getStatusBadge = (status: CronJob['lastStatus']) => {
|
||||
const getStatusBadge = (status: any) => {
|
||||
switch (status) {
|
||||
case 'success':
|
||||
return (
|
||||
@@ -208,9 +131,47 @@ export function CronJobManager() {
|
||||
return patterns[schedule] || schedule;
|
||||
};
|
||||
|
||||
const handleCreateJob = () => {
|
||||
setIsCreateDialogOpen(false);
|
||||
setNewJob({ name: '', description: '', schedule: '', command: '', targetServers: '' });
|
||||
const handleCreateJob = async () => {
|
||||
try {
|
||||
await cronJobApi.createJob({
|
||||
name: newJob.name,
|
||||
description: newJob.description,
|
||||
cron: newJob.cron,
|
||||
command: newJob.command,
|
||||
});
|
||||
setIsCreateDialogOpen(false);
|
||||
setNewJob({ name: '', description: '', cron: '', command: '', targetServers: '' });
|
||||
loadData();
|
||||
} catch (error) {
|
||||
console.error('Failed to create cron job:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleJob = async (id: any) => {
|
||||
try {
|
||||
await cronJobApi.toggleJob(id);
|
||||
loadData();
|
||||
} catch (error) {
|
||||
console.error('Failed to toggle job:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExecuteJob = async (id: any) => {
|
||||
try {
|
||||
await cronJobApi.executeJob(id);
|
||||
loadData();
|
||||
} catch (error) {
|
||||
console.error('Failed to execute job:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteJob = async (id: any) => {
|
||||
try {
|
||||
await cronJobApi.deleteJob(id);
|
||||
loadData();
|
||||
} catch (error) {
|
||||
console.error('Failed to delete job:', error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -238,30 +199,28 @@ export function CronJobManager() {
|
||||
<Card className="bg-slate-800 border-slate-700">
|
||||
<CardContent className="p-4">
|
||||
<p className="text-slate-400 text-sm">任务总数</p>
|
||||
<p className="text-2xl font-bold text-slate-100">{mockCronJobs.length}</p>
|
||||
<p className="text-2xl font-bold text-slate-100">{jobs.length}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="bg-slate-800 border-slate-700">
|
||||
<CardContent className="p-4">
|
||||
<p className="text-slate-400 text-sm">已启用</p>
|
||||
<p className="text-2xl font-bold text-emerald-400">
|
||||
{mockCronJobs.filter((j) => j.status === 'enabled').length}
|
||||
{jobs.filter((j) => j.status === 1).length}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="bg-slate-800 border-slate-700">
|
||||
<CardContent className="p-4">
|
||||
<p className="text-slate-400 text-sm">执行中</p>
|
||||
<p className="text-2xl font-bold text-blue-400">
|
||||
{mockCronJobs.filter((j) => j.lastStatus === 'running').length}
|
||||
</p>
|
||||
<p className="text-2xl font-bold text-blue-400">--</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="bg-slate-800 border-slate-700">
|
||||
<CardContent className="p-4">
|
||||
<p className="text-slate-400 text-sm">今日失败</p>
|
||||
<p className="text-slate-400 text-sm">累计失败</p>
|
||||
<p className="text-2xl font-bold text-red-400">
|
||||
{mockCronJobs.filter((j) => j.lastStatus === 'failed').length}
|
||||
{jobs.reduce((sum, j) => sum + (j.fail_count || 0), 0)}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -280,6 +239,12 @@ export function CronJobManager() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="h-6 w-6 text-slate-500 animate-spin" />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Job List */}
|
||||
<div className="space-y-3">
|
||||
{filteredJobs.map((job) => (
|
||||
@@ -292,20 +257,20 @@ export function CronJobManager() {
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
job.status === 'enabled'
|
||||
job.status === 1
|
||||
? 'border-emerald-500/30 text-emerald-400 bg-emerald-500/10'
|
||||
: 'border-slate-500/30 text-slate-400 bg-slate-500/10'
|
||||
}
|
||||
>
|
||||
{job.status === 'enabled' ? '已启用' : '已禁用'}
|
||||
{job.status === 1 ? '已启用' : '已禁用'}
|
||||
</Badge>
|
||||
{getStatusBadge(job.lastStatus)}
|
||||
{getStatusBadge(job.last_status)}
|
||||
</div>
|
||||
<p className="text-sm text-slate-400 mt-1">{job.description}</p>
|
||||
<div className="flex items-center gap-4 mt-2 text-sm">
|
||||
<span className="flex items-center gap-1 text-slate-400">
|
||||
<Clock className="h-3 w-3" />
|
||||
{parseCron(job.schedule)}
|
||||
{parseCron(job.cron)}
|
||||
</span>
|
||||
<span className="flex items-center gap-1 text-slate-400">
|
||||
<Terminal className="h-3 w-3" />
|
||||
@@ -313,17 +278,30 @@ export function CronJobManager() {
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 mt-2 text-xs text-slate-500">
|
||||
<span>上次执行: {job.lastRun}</span>
|
||||
<span>下次执行: {job.nextRun}</span>
|
||||
<span>目标: {job.targetServers.join(', ')}</span>
|
||||
<span>上次执行: {job.last_run ? new Date(job.last_run).toLocaleString() : '--'}</span>
|
||||
<span>下次执行: {job.next_run ? new Date(job.next_run).toLocaleString() : '--'}</span>
|
||||
<span>成功: {job.success_count || 0} / 失败: {job.fail_count || 0}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" size="sm" className="border-emerald-600 text-emerald-400 hover:bg-emerald-600/20">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="border-emerald-600 text-emerald-400 hover:bg-emerald-600/20"
|
||||
onClick={() => handleExecuteJob(job.id)}
|
||||
>
|
||||
<Play className="h-4 w-4 mr-1" />
|
||||
立即执行
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-slate-400 hover:text-blue-400"
|
||||
onClick={() => handleToggleJob(job.id)}
|
||||
>
|
||||
{job.status === 1 ? <Pause className="h-4 w-4" /> : <Play className="h-4 w-4" />}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
@@ -335,6 +313,7 @@ export function CronJobManager() {
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-slate-400 hover:text-red-400"
|
||||
onClick={() => handleDeleteJob(job.id)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -375,12 +354,12 @@ export function CronJobManager() {
|
||||
<Label className="text-slate-300">Cron 表达式</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={newJob.schedule}
|
||||
onChange={(e) => setNewJob({ ...newJob, schedule: e.target.value })}
|
||||
value={newJob.cron}
|
||||
onChange={(e) => setNewJob({ ...newJob, cron: e.target.value })}
|
||||
placeholder="0 2 * * *"
|
||||
className="bg-slate-800 border-slate-700 text-slate-100 mt-1"
|
||||
/>
|
||||
<Select onValueChange={(v) => setNewJob({ ...newJob, schedule: v })}>
|
||||
<Select onValueChange={(v) => setNewJob({ ...newJob, cron: v })}>
|
||||
<SelectTrigger className="w-48 bg-slate-800 border-slate-700 text-slate-100 mt-1">
|
||||
<SelectValue placeholder="快速选择" />
|
||||
</SelectTrigger>
|
||||
@@ -433,39 +412,45 @@ export function CronJobManager() {
|
||||
<DialogDescription className="text-slate-500">定时任务执行记录</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="mt-4">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="border-slate-700">
|
||||
<TableHead className="text-slate-400">任务</TableHead>
|
||||
<TableHead className="text-slate-400">开始时间</TableHead>
|
||||
<TableHead className="text-slate-400">耗时</TableHead>
|
||||
<TableHead className="text-slate-400">状态</TableHead>
|
||||
<TableHead className="text-slate-400">输出</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{executionLogs.map((log) => (
|
||||
<TableRow key={log.id} className="border-slate-700">
|
||||
<TableCell className="text-slate-200">{log.jobName}</TableCell>
|
||||
<TableCell className="text-slate-400">{log.startTime}</TableCell>
|
||||
<TableCell className="text-slate-400">{log.duration}</TableCell>
|
||||
<TableCell>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
log.status === 'success'
|
||||
? 'border-emerald-500/30 text-emerald-400 bg-emerald-500/10'
|
||||
: 'border-red-500/30 text-red-400 bg-red-500/10'
|
||||
}
|
||||
>
|
||||
{log.status === 'success' ? '成功' : '失败'}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-slate-400 text-sm">{log.output}</TableCell>
|
||||
{jobs.length === 0 ? (
|
||||
<div className="text-center text-slate-500 py-8">暂无执行记录</div>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="border-slate-700">
|
||||
<TableHead className="text-slate-400">任务</TableHead>
|
||||
<TableHead className="text-slate-400">上次执行</TableHead>
|
||||
<TableHead className="text-slate-400">成功次数</TableHead>
|
||||
<TableHead className="text-slate-400">失败次数</TableHead>
|
||||
<TableHead className="text-slate-400">状态</TableHead>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{jobs.map((job) => (
|
||||
<TableRow key={job.id} className="border-slate-700">
|
||||
<TableCell className="text-slate-200">{job.name}</TableCell>
|
||||
<TableCell className="text-slate-400">
|
||||
{job.last_run ? new Date(job.last_run).toLocaleString() : '--'}
|
||||
</TableCell>
|
||||
<TableCell className="text-emerald-400">{job.success_count || 0}</TableCell>
|
||||
<TableCell className="text-red-400">{job.fail_count || 0}</TableCell>
|
||||
<TableCell>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
(job.fail_count || 0) > 0
|
||||
? 'border-red-500/30 text-red-400 bg-red-500/10'
|
||||
: 'border-emerald-500/30 text-emerald-400 bg-emerald-500/10'
|
||||
}
|
||||
>
|
||||
{(job.fail_count || 0) > 0 ? '有失败' : '正常'}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
Reference in new issue
Block a user