import React, { useState, useMemo, useEffect, useRef } from 'react'; import { useTheme } from '../contexts/ThemeContext'; import { Search, Clock, ChevronRight, Download, Send, Trash2, FileText, User, MessageSquare, Network, Target, BookOpen, History, Filter, Calendar, AlertTriangle, CheckCircle2, Eye, } from 'lucide-react'; import { LightAppType } from './LightAppSquare'; import { requestCrudService } from '@/service/request-axios-service'; import { DateRangePicker, DateRangePickerProps, DateRangeValue, Pagination, Select } from 'tdesign-react'; import dayjs from 'dayjs'; // 运行记录类型 interface RunRecord { id: string; appId: LightAppType; appName: string; appIcon: React.ElementType; iconColor: string; input: string; runTime: string; resultSummary: string; status: number; riskLevel?: 'low' | 'medium' | 'high'; sentiment?: string; inputObject?: string; } interface stateData { startTime: string; endTime: string; pageNum: number; pageSize: number; status: string | number; } // 应用信息映射 const appInfoMap: Record = { 'info-ty': { name: '信息TY', icon: FileText, iconColor: 'text-blue-500' }, 'info-pg': { name: '信息PG', icon: User, iconColor: 'text-cyan-500' }, 'info-spread': { name: '信息传播分析', icon: Network, iconColor: 'text-teal-500' }, 'account-pg': { name: '账号PG', icon: User, iconColor: 'text-purple-500' }, 'sentiment': { name: '三情分析', icon: MessageSquare, iconColor: 'text-orange-500' }, 'event': { name: '事件分析', icon: Target, iconColor: 'text-red-500' }, 'topic': { name: '专题分析', icon: BookOpen, iconColor: 'text-green-500' }, }; interface LightAppRecordsProps { onNavigate: (page: string, appId?: string) => void; } const appIconList = [ { appIcon: MessageSquare, iconColor: 'text-orange-500', }, { appIcon: Target, iconColor: 'text-red-500', }, { appIcon: User, iconColor: 'text-purple-500', }, { appIcon: Network, iconColor: 'text-teal-500', }, { appIcon: BookOpen, iconColor: 'text-green-500', }, { appIcon: FileText, iconColor: 'text-blue-500', }, ] const service = requestCrudService; const zncmUrl = import.meta.env.VITE_API_BASE_URL || ''; const LightAppRecords: React.FC = ({ onNavigate }) => { const { theme } = useTheme(); const isDark = theme === 'dark'; const [searchQuery, setSearchQuery] = useState(''); const [appFilter, setAppFilter] = useState('all'); const [timeFilter, setTimeFilter] = useState('all'); const [records, setRecords] = useState([]); const [loading, setLoading] = useState(false); const [pageNum, setPageNum] = useState(1); const [pageSize, setPageSize] = useState(10); // 每页显示 10 条 const [total, setTotal] = useState(0); const [presets] = useState({ 最近7天: [dayjs().subtract(6, 'day').toDate(), dayjs().toDate()], 最近3天: [dayjs().subtract(2, 'day').toDate(), dayjs().toDate()], 今天: [dayjs().toDate(), dayjs().toDate()], }); const [range, setRange] = useState([]); const state = useRef({ startTime: '', endTime: '', pageNum: 1, pageSize: 10, status: '' }) const [statusValue, setStatusValue] = useState(''); // 执行状态,0=执行中, 1=成功, 2=失败, 3=部分成功 const [statusList] = useState([ { value: '', label: '全部' }, { value: 0, label: '执行中' }, { value: 1, label: '成功' }, { value: 2, label: '失败' }, { value: 3, label: '部分成功' }, ]) const statusChange = async (val) => { state.current.status = val; setStatusValue(val); await historyPageSearch(); } // 时间日期选择器查询 const setRangeChange = async (val) => { setRange(val); console.log('时间日期', val); state.current.startTime = ''; state.current.endTime = ''; if (val.length > 0) { state.current.startTime = val[0]; state.current.endTime = val[1]; } await historyPageSearch(); } // 过滤记录 // const filteredRecords = useMemo(() => { // return records.filter(record => { // // 搜索过滤 // const matchesSearch = searchQuery === '' || // record.input.toLowerCase().includes(searchQuery.toLowerCase()) || // record.appName.toLowerCase().includes(searchQuery.toLowerCase()) || // record.resultSummary.toLowerCase().includes(searchQuery.toLowerCase()); // // 应用类型过滤 // const matchesApp = appFilter === 'all' || record.appId === appFilter; // // 时间过滤 // let matchesTime = true; // if (timeFilter !== 'all') { // const recordDate = new Date(record.runTime); // const now = new Date(); // if (timeFilter === '7d') { // const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); // matchesTime = recordDate >= weekAgo; // } else if (timeFilter === '30d') { // const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000); // matchesTime = recordDate >= monthAgo; // } // } // return matchesSearch && matchesApp && matchesTime; // }); // }, [records, searchQuery, appFilter, timeFilter]); // 查看详情 const handleView = (record: RunRecord) => { console.log('查看详情:', record); onNavigate('light-app-run', record.appId); }; // 导出 const handleExport = (record: RunRecord) => { const data = JSON.stringify(record, null, 2); const blob = new Blob([data], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${record.appName}_${record.runTime.replace(/[: ]/g, '-')}.json`; a.click(); }; // 转正式任务 const handleConvert = (record: RunRecord) => { onNavigate('task-create'); }; // 获取状态颜色 const getStatusColor = (status: number) => { switch (status) { case 1: return { bg: 'bg-green-500/10', text: 'text-green-500', border: 'border-green-500/30' }; case 2: return { bg: 'bg-red-500/10', text: 'text-red-500', border: 'border-red-500/30' }; case 3: return { bg: 'bg-yellow-500/10', text: 'text-yellow-500', border: 'border-yellow-500/30' }; default: return { bg: 'bg-gray-500/10', text: 'text-gray-500', border: 'border-gray-500/30' }; } }; // 获取状态标签 const getStatusLabel = (status: number) => { switch (status) { case 0: return '执行中'; case 1: return '成功'; case 2: return '失败'; case 3: return '部分'; default: return status; } }; // 回车处理 const handleKeyDown = async (e) => { if ((e.metaKey || e.ctrlKey || e.shiftKey) && e.key === "Enter") { e.preventDefault(); } else if (e.keyCode === 13) { e.preventDefault(); await historyPageSearch(); } else if (e.key === "/") { e.preventDefault(); } }; const historyPageSearch = async () => { const parmy = { appName: searchQuery, keyword: '', pageNum: state.current.pageNum, pageSize: state.current.pageSize, startTime: state.current.startTime, endTime: state.current.endTime, status: state.current.status } setLoading(true); const res = await service.post(`${zncmUrl}/app/history/page`, parmy); console.log('res', res); setLoading(false); const result = res.data; result.records.forEach((item: RunRecord, index: number) => { const realIndex = index % appIconList.length; item.appIcon = appIconList[realIndex].appIcon; item.iconColor = appIconList[realIndex].iconColor; }) setTotal(result.total); setRecords(result.records || ''); } const pageIndexChange = async (value: number) => { state.current.pageNum = value; setPageNum(value); await historyPageSearch(); } const pageSizeChange = async (value: number) => { state.current.pageSize = value; setPageSize(value); await historyPageSearch(); } useEffect(() => { fetch('https://ch1.b.uat.4.cn/zncmweb/templates/index.json') // 注意:不需要 public 前缀 .then(response => { if (!response.ok) { throw new Error('网络请求失败'); } return response.json(); }) .then(jsonData => { console.log('jsonData', jsonData); }) .catch(err => { console.log(err); }); historyPageSearch(); }, []); return (
{/* 顶部工具栏 */}
{/* 面包屑和标题 */}
轻应用中心 / 运行记录
{/* 搜索框 */}
handleKeyDown(e)} onChange={(e) => setSearchQuery(e.target.value)} placeholder="搜索记录..." className={`w-full pl-10 pr-4 py-2 rounded-lg border transition-colors focus:outline-none focus:ring-2 ${isDark ? 'bg-slate-900 border-slate-600 text-slate-200 placeholder-slate-500 focus:border-blue-500 focus:ring-blue-500/20' : 'bg-gray-50 border-gray-300 text-gray-900 placeholder-gray-400 focus:border-red-500 focus:ring-red-500/20' }`} />
{/* 筛选 */}
{/* */}