TaskLogsTable.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. import React, { useEffect, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import {
  4. Music,
  5. FileText,
  6. HelpCircle,
  7. CheckCircle,
  8. Pause,
  9. Clock,
  10. Play,
  11. XCircle,
  12. Loader,
  13. List,
  14. Hash,
  15. Video,
  16. Sparkles
  17. } from 'lucide-react';
  18. import {
  19. API,
  20. copy,
  21. isAdmin,
  22. showError,
  23. showSuccess,
  24. timestamp2string
  25. } from '../../helpers';
  26. import {
  27. Button,
  28. Card,
  29. Checkbox,
  30. Divider,
  31. Empty,
  32. Form,
  33. Layout,
  34. Modal,
  35. Progress,
  36. Skeleton,
  37. Table,
  38. Tag,
  39. Typography
  40. } from '@douyinfe/semi-ui';
  41. import {
  42. IllustrationNoResult,
  43. IllustrationNoResultDark
  44. } from '@douyinfe/semi-illustrations';
  45. import { ITEMS_PER_PAGE } from '../../constants';
  46. import {
  47. IconEyeOpened,
  48. IconSearch,
  49. } from '@douyinfe/semi-icons';
  50. import { useTableCompactMode } from '../../hooks/useTableCompactMode';
  51. const { Text } = Typography;
  52. const colors = [
  53. 'amber',
  54. 'blue',
  55. 'cyan',
  56. 'green',
  57. 'grey',
  58. 'indigo',
  59. 'light-blue',
  60. 'lime',
  61. 'orange',
  62. 'pink',
  63. 'purple',
  64. 'red',
  65. 'teal',
  66. 'violet',
  67. 'yellow',
  68. ];
  69. // 定义列键值常量
  70. const COLUMN_KEYS = {
  71. SUBMIT_TIME: 'submit_time',
  72. FINISH_TIME: 'finish_time',
  73. DURATION: 'duration',
  74. CHANNEL: 'channel',
  75. PLATFORM: 'platform',
  76. TYPE: 'type',
  77. TASK_ID: 'task_id',
  78. TASK_STATUS: 'task_status',
  79. PROGRESS: 'progress',
  80. FAIL_REASON: 'fail_reason',
  81. RESULT_URL: 'result_url',
  82. };
  83. const renderTimestamp = (timestampInSeconds) => {
  84. const date = new Date(timestampInSeconds * 1000); // 从秒转换为毫秒
  85. const year = date.getFullYear(); // 获取年份
  86. const month = ('0' + (date.getMonth() + 1)).slice(-2); // 获取月份,从0开始需要+1,并保证两位数
  87. const day = ('0' + date.getDate()).slice(-2); // 获取日期,并保证两位数
  88. const hours = ('0' + date.getHours()).slice(-2); // 获取小时,并保证两位数
  89. const minutes = ('0' + date.getMinutes()).slice(-2); // 获取分钟,并保证两位数
  90. const seconds = ('0' + date.getSeconds()).slice(-2); // 获取秒钟,并保证两位数
  91. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 格式化输出
  92. };
  93. function renderDuration(submit_time, finishTime) {
  94. if (!submit_time || !finishTime) return 'N/A';
  95. const durationSec = finishTime - submit_time;
  96. const color = durationSec > 60 ? 'red' : 'green';
  97. // 返回带有样式的颜色标签
  98. return (
  99. <Tag color={color} size='large' prefixIcon={<Clock size={14} />}>
  100. {durationSec} 秒
  101. </Tag>
  102. );
  103. }
  104. const LogsTable = () => {
  105. const { t } = useTranslation();
  106. const [isModalOpen, setIsModalOpen] = useState(false);
  107. const [modalContent, setModalContent] = useState('');
  108. // 列可见性状态
  109. const [visibleColumns, setVisibleColumns] = useState({});
  110. const [showColumnSelector, setShowColumnSelector] = useState(false);
  111. const isAdminUser = isAdmin();
  112. const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
  113. // 加载保存的列偏好设置
  114. useEffect(() => {
  115. const savedColumns = localStorage.getItem('task-logs-table-columns');
  116. if (savedColumns) {
  117. try {
  118. const parsed = JSON.parse(savedColumns);
  119. const defaults = getDefaultColumnVisibility();
  120. const merged = { ...defaults, ...parsed };
  121. setVisibleColumns(merged);
  122. } catch (e) {
  123. console.error('Failed to parse saved column preferences', e);
  124. initDefaultColumns();
  125. }
  126. } else {
  127. initDefaultColumns();
  128. }
  129. }, []);
  130. // 获取默认列可见性
  131. const getDefaultColumnVisibility = () => {
  132. return {
  133. [COLUMN_KEYS.SUBMIT_TIME]: true,
  134. [COLUMN_KEYS.FINISH_TIME]: true,
  135. [COLUMN_KEYS.DURATION]: true,
  136. [COLUMN_KEYS.CHANNEL]: isAdminUser,
  137. [COLUMN_KEYS.PLATFORM]: true,
  138. [COLUMN_KEYS.TYPE]: true,
  139. [COLUMN_KEYS.TASK_ID]: true,
  140. [COLUMN_KEYS.TASK_STATUS]: true,
  141. [COLUMN_KEYS.PROGRESS]: true,
  142. [COLUMN_KEYS.FAIL_REASON]: true,
  143. [COLUMN_KEYS.RESULT_URL]: true,
  144. };
  145. };
  146. // 初始化默认列可见性
  147. const initDefaultColumns = () => {
  148. const defaults = getDefaultColumnVisibility();
  149. setVisibleColumns(defaults);
  150. localStorage.setItem('task-logs-table-columns', JSON.stringify(defaults));
  151. };
  152. // 处理列可见性变化
  153. const handleColumnVisibilityChange = (columnKey, checked) => {
  154. const updatedColumns = { ...visibleColumns, [columnKey]: checked };
  155. setVisibleColumns(updatedColumns);
  156. };
  157. // 处理全选
  158. const handleSelectAll = (checked) => {
  159. const allKeys = Object.keys(COLUMN_KEYS).map((key) => COLUMN_KEYS[key]);
  160. const updatedColumns = {};
  161. allKeys.forEach((key) => {
  162. if (key === COLUMN_KEYS.CHANNEL && !isAdminUser) {
  163. updatedColumns[key] = false;
  164. } else {
  165. updatedColumns[key] = checked;
  166. }
  167. });
  168. setVisibleColumns(updatedColumns);
  169. };
  170. // 更新表格时保存列可见性
  171. useEffect(() => {
  172. if (Object.keys(visibleColumns).length > 0) {
  173. localStorage.setItem('task-logs-table-columns', JSON.stringify(visibleColumns));
  174. }
  175. }, [visibleColumns]);
  176. const renderType = (type) => {
  177. switch (type) {
  178. case 'MUSIC':
  179. return (
  180. <Tag color='grey' size='large' shape='circle' prefixIcon={<Music size={14} />}>
  181. {t('生成音乐')}
  182. </Tag>
  183. );
  184. case 'LYRICS':
  185. return (
  186. <Tag color='pink' size='large' shape='circle' prefixIcon={<FileText size={14} />}>
  187. {t('生成歌词')}
  188. </Tag>
  189. );
  190. case 'generate':
  191. return (
  192. <Tag color='blue' size='large' shape='circle' prefixIcon={<Sparkles size={14} />}>
  193. {t('图生视频')}
  194. </Tag>
  195. );
  196. case 'textGenerate':
  197. return (
  198. <Tag color='blue' size='large' shape='circle' prefixIcon={<Sparkles size={14} />}>
  199. {t('文生视频')}
  200. </Tag>
  201. );
  202. default:
  203. return (
  204. <Tag color='white' size='large' shape='circle' prefixIcon={<HelpCircle size={14} />}>
  205. {t('未知')}
  206. </Tag>
  207. );
  208. }
  209. };
  210. const renderPlatform = (platform) => {
  211. switch (platform) {
  212. case 'suno':
  213. return (
  214. <Tag color='green' size='large' shape='circle' prefixIcon={<Music size={14} />}>
  215. Suno
  216. </Tag>
  217. );
  218. case 'kling':
  219. return (
  220. <Tag color='orange' size='large' shape='circle' prefixIcon={<Video size={14} />}>
  221. Kling
  222. </Tag>
  223. );
  224. case 'jimeng':
  225. return (
  226. <Tag color='purple' size='large' shape='circle' prefixIcon={<Video size={14} />}>
  227. Jimeng
  228. </Tag>
  229. );
  230. default:
  231. return (
  232. <Tag color='white' size='large' shape='circle' prefixIcon={<HelpCircle size={14} />}>
  233. {t('未知')}
  234. </Tag>
  235. );
  236. }
  237. };
  238. const renderStatus = (type) => {
  239. switch (type) {
  240. case 'SUCCESS':
  241. return (
  242. <Tag color='green' size='large' shape='circle' prefixIcon={<CheckCircle size={14} />}>
  243. {t('成功')}
  244. </Tag>
  245. );
  246. case 'NOT_START':
  247. return (
  248. <Tag color='grey' size='large' shape='circle' prefixIcon={<Pause size={14} />}>
  249. {t('未启动')}
  250. </Tag>
  251. );
  252. case 'SUBMITTED':
  253. return (
  254. <Tag color='yellow' size='large' shape='circle' prefixIcon={<Clock size={14} />}>
  255. {t('队列中')}
  256. </Tag>
  257. );
  258. case 'IN_PROGRESS':
  259. return (
  260. <Tag color='blue' size='large' shape='circle' prefixIcon={<Play size={14} />}>
  261. {t('执行中')}
  262. </Tag>
  263. );
  264. case 'FAILURE':
  265. return (
  266. <Tag color='red' size='large' shape='circle' prefixIcon={<XCircle size={14} />}>
  267. {t('失败')}
  268. </Tag>
  269. );
  270. case 'QUEUED':
  271. return (
  272. <Tag color='orange' size='large' shape='circle' prefixIcon={<List size={14} />}>
  273. {t('排队中')}
  274. </Tag>
  275. );
  276. case 'UNKNOWN':
  277. return (
  278. <Tag color='white' size='large' shape='circle' prefixIcon={<HelpCircle size={14} />}>
  279. {t('未知')}
  280. </Tag>
  281. );
  282. case '':
  283. return (
  284. <Tag color='grey' size='large' shape='circle' prefixIcon={<Loader size={14} />}>
  285. {t('正在提交')}
  286. </Tag>
  287. );
  288. default:
  289. return (
  290. <Tag color='white' size='large' shape='circle' prefixIcon={<HelpCircle size={14} />}>
  291. {t('未知')}
  292. </Tag>
  293. );
  294. }
  295. };
  296. // 定义所有列
  297. const allColumns = [
  298. {
  299. key: COLUMN_KEYS.SUBMIT_TIME,
  300. title: t('提交时间'),
  301. dataIndex: 'submit_time',
  302. render: (text, record, index) => {
  303. return <div>{text ? renderTimestamp(text) : '-'}</div>;
  304. },
  305. },
  306. {
  307. key: COLUMN_KEYS.FINISH_TIME,
  308. title: t('结束时间'),
  309. dataIndex: 'finish_time',
  310. render: (text, record, index) => {
  311. return <div>{text ? renderTimestamp(text) : '-'}</div>;
  312. },
  313. },
  314. {
  315. key: COLUMN_KEYS.DURATION,
  316. title: t('花费时间'),
  317. dataIndex: 'finish_time',
  318. render: (finish, record) => {
  319. return <>{finish ? renderDuration(record.submit_time, finish) : '-'}</>;
  320. },
  321. },
  322. {
  323. key: COLUMN_KEYS.CHANNEL,
  324. title: t('渠道'),
  325. dataIndex: 'channel_id',
  326. className: isAdminUser ? 'tableShow' : 'tableHiddle',
  327. render: (text, record, index) => {
  328. return isAdminUser ? (
  329. <div>
  330. <Tag
  331. color={colors[parseInt(text) % colors.length]}
  332. size='large'
  333. shape='circle'
  334. prefixIcon={<Hash size={14} />}
  335. onClick={() => {
  336. copyText(text);
  337. }}
  338. >
  339. {text}
  340. </Tag>
  341. </div>
  342. ) : (
  343. <></>
  344. );
  345. },
  346. },
  347. {
  348. key: COLUMN_KEYS.PLATFORM,
  349. title: t('平台'),
  350. dataIndex: 'platform',
  351. render: (text, record, index) => {
  352. return <div>{renderPlatform(text)}</div>;
  353. },
  354. },
  355. {
  356. key: COLUMN_KEYS.TYPE,
  357. title: t('类型'),
  358. dataIndex: 'action',
  359. render: (text, record, index) => {
  360. return <div>{renderType(text)}</div>;
  361. },
  362. },
  363. {
  364. key: COLUMN_KEYS.TASK_ID,
  365. title: t('任务ID'),
  366. dataIndex: 'task_id',
  367. render: (text, record, index) => {
  368. return (
  369. <Typography.Text
  370. ellipsis={{ showTooltip: true }}
  371. onClick={() => {
  372. setModalContent(JSON.stringify(record, null, 2));
  373. setIsModalOpen(true);
  374. }}
  375. >
  376. <div>{text}</div>
  377. </Typography.Text>
  378. );
  379. },
  380. },
  381. {
  382. key: COLUMN_KEYS.TASK_STATUS,
  383. title: t('任务状态'),
  384. dataIndex: 'status',
  385. render: (text, record, index) => {
  386. return <div>{renderStatus(text)}</div>;
  387. },
  388. },
  389. {
  390. key: COLUMN_KEYS.PROGRESS,
  391. title: t('进度'),
  392. dataIndex: 'progress',
  393. render: (text, record, index) => {
  394. return (
  395. <div>
  396. {
  397. isNaN(text?.replace('%', '')) ? (
  398. text || '-'
  399. ) : (
  400. <Progress
  401. stroke={
  402. record.status === 'FAILURE'
  403. ? 'var(--semi-color-warning)'
  404. : null
  405. }
  406. percent={text ? parseInt(text.replace('%', '')) : 0}
  407. showInfo={true}
  408. aria-label='task progress'
  409. style={{ minWidth: '160px' }}
  410. />
  411. )
  412. }
  413. </div>
  414. );
  415. },
  416. },
  417. {
  418. key: COLUMN_KEYS.FAIL_REASON,
  419. title: t('详情'),
  420. dataIndex: 'fail_reason',
  421. fixed: 'right',
  422. render: (text, record, index) => {
  423. // 仅当为视频生成任务且成功,且 fail_reason 是 URL 时显示可点击链接
  424. const isVideoTask = record.action === 'generate' || record.action === 'textGenerate';
  425. const isSuccess = record.status === 'SUCCESS';
  426. const isUrl = typeof text === 'string' && /^https?:\/\//.test(text);
  427. if (isSuccess && isVideoTask && isUrl) {
  428. return (
  429. <a href={text} target="_blank" rel="noopener noreferrer">
  430. {t('点击预览视频')}
  431. </a>
  432. );
  433. }
  434. if (!text) {
  435. return t('无');
  436. }
  437. return (
  438. <Typography.Text
  439. ellipsis={{ showTooltip: true }}
  440. style={{ width: 100 }}
  441. onClick={() => {
  442. setModalContent(text);
  443. setIsModalOpen(true);
  444. }}
  445. >
  446. {text}
  447. </Typography.Text>
  448. );
  449. },
  450. },
  451. ];
  452. // 根据可见性设置过滤列
  453. const getVisibleColumns = () => {
  454. return allColumns.filter((column) => visibleColumns[column.key]);
  455. };
  456. const [activePage, setActivePage] = useState(1);
  457. const [logCount, setLogCount] = useState(0);
  458. const [logs, setLogs] = useState([]);
  459. const [loading, setLoading] = useState(false);
  460. const [compactMode, setCompactMode] = useTableCompactMode('taskLogs');
  461. useEffect(() => {
  462. const localPageSize = parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE;
  463. setPageSize(localPageSize);
  464. loadLogs(1, localPageSize).then();
  465. }, []);
  466. let now = new Date();
  467. // 初始化start_timestamp为前一天
  468. let zeroNow = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  469. // Form 初始值
  470. const formInitValues = {
  471. channel_id: '',
  472. task_id: '',
  473. dateRange: [
  474. timestamp2string(zeroNow.getTime() / 1000),
  475. timestamp2string(now.getTime() / 1000 + 3600)
  476. ],
  477. };
  478. // Form API 引用
  479. const [formApi, setFormApi] = useState(null);
  480. // 获取表单值的辅助函数
  481. const getFormValues = () => {
  482. const formValues = formApi ? formApi.getValues() : {};
  483. // 处理时间范围
  484. let start_timestamp = timestamp2string(zeroNow.getTime() / 1000);
  485. let end_timestamp = timestamp2string(now.getTime() / 1000 + 3600);
  486. if (formValues.dateRange && Array.isArray(formValues.dateRange) && formValues.dateRange.length === 2) {
  487. start_timestamp = formValues.dateRange[0];
  488. end_timestamp = formValues.dateRange[1];
  489. }
  490. return {
  491. channel_id: formValues.channel_id || '',
  492. task_id: formValues.task_id || '',
  493. start_timestamp,
  494. end_timestamp,
  495. };
  496. };
  497. const enrichLogs = (items) => {
  498. return items.map((log) => ({
  499. ...log,
  500. timestamp2string: timestamp2string(log.created_at),
  501. key: '' + log.id,
  502. }));
  503. };
  504. const syncPageData = (payload) => {
  505. const items = enrichLogs(payload.items || []);
  506. setLogs(items);
  507. setLogCount(payload.total || 0);
  508. setActivePage(payload.page || 1);
  509. setPageSize(payload.page_size || pageSize);
  510. };
  511. const loadLogs = async (page = 1, size = pageSize) => {
  512. setLoading(true);
  513. const { channel_id, task_id, start_timestamp, end_timestamp } = getFormValues();
  514. let localStartTimestamp = parseInt(Date.parse(start_timestamp) / 1000);
  515. let localEndTimestamp = parseInt(Date.parse(end_timestamp) / 1000);
  516. let url = isAdminUser
  517. ? `/api/task/?p=${page}&page_size=${size}&channel_id=${channel_id}&task_id=${task_id}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}`
  518. : `/api/task/self?p=${page}&page_size=${size}&task_id=${task_id}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}`;
  519. const res = await API.get(url);
  520. const { success, message, data } = res.data;
  521. if (success) {
  522. syncPageData(data);
  523. } else {
  524. showError(message);
  525. }
  526. setLoading(false);
  527. };
  528. const pageData = logs;
  529. const handlePageChange = (page) => {
  530. loadLogs(page, pageSize).then();
  531. };
  532. const handlePageSizeChange = async (size) => {
  533. localStorage.setItem('task-page-size', size + '');
  534. await loadLogs(1, size);
  535. };
  536. const refresh = async () => {
  537. await loadLogs(1, pageSize);
  538. };
  539. const copyText = async (text) => {
  540. if (await copy(text)) {
  541. showSuccess(t('已复制:') + text);
  542. } else {
  543. Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
  544. }
  545. };
  546. // 列选择器模态框
  547. const renderColumnSelector = () => {
  548. return (
  549. <Modal
  550. title={t('列设置')}
  551. visible={showColumnSelector}
  552. onCancel={() => setShowColumnSelector(false)}
  553. footer={
  554. <div className="flex justify-end">
  555. <Button
  556. theme="light"
  557. onClick={() => initDefaultColumns()}
  558. >
  559. {t('重置')}
  560. </Button>
  561. <Button
  562. theme="light"
  563. onClick={() => setShowColumnSelector(false)}
  564. >
  565. {t('取消')}
  566. </Button>
  567. <Button
  568. type='primary'
  569. onClick={() => setShowColumnSelector(false)}
  570. >
  571. {t('确定')}
  572. </Button>
  573. </div>
  574. }
  575. >
  576. <div style={{ marginBottom: 20 }}>
  577. <Checkbox
  578. checked={Object.values(visibleColumns).every((v) => v === true)}
  579. indeterminate={
  580. Object.values(visibleColumns).some((v) => v === true) &&
  581. !Object.values(visibleColumns).every((v) => v === true)
  582. }
  583. onChange={(e) => handleSelectAll(e.target.checked)}
  584. >
  585. {t('全选')}
  586. </Checkbox>
  587. </div>
  588. <div className="flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4" style={{ border: '1px solid var(--semi-color-border)' }}>
  589. {allColumns.map((column) => {
  590. // 为非管理员用户跳过管理员专用列
  591. if (!isAdminUser && column.key === COLUMN_KEYS.CHANNEL) {
  592. return null;
  593. }
  594. return (
  595. <div key={column.key} className="w-1/2 mb-4 pr-2">
  596. <Checkbox
  597. checked={!!visibleColumns[column.key]}
  598. onChange={(e) =>
  599. handleColumnVisibilityChange(column.key, e.target.checked)
  600. }
  601. >
  602. {column.title}
  603. </Checkbox>
  604. </div>
  605. );
  606. })}
  607. </div>
  608. </Modal>
  609. );
  610. };
  611. return (
  612. <>
  613. {renderColumnSelector()}
  614. <Layout>
  615. <Card
  616. className="!rounded-2xl mb-4"
  617. title={
  618. <div className="flex flex-col w-full">
  619. <div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full">
  620. <div className="flex items-center text-orange-500 mb-2 md:mb-0">
  621. <IconEyeOpened className="mr-2" />
  622. {loading ? (
  623. <Skeleton.Title
  624. style={{
  625. width: 300,
  626. marginBottom: 0,
  627. marginTop: 0
  628. }}
  629. />
  630. ) : (
  631. <Text>{t('任务记录')}</Text>
  632. )}
  633. </div>
  634. <Button
  635. theme='light'
  636. type='secondary'
  637. className="w-full md:w-auto"
  638. onClick={() => setCompactMode(!compactMode)}
  639. >
  640. {compactMode ? t('自适应列表') : t('紧凑列表')}
  641. </Button>
  642. </div>
  643. <Divider margin="12px" />
  644. {/* 搜索表单区域 */}
  645. <Form
  646. initValues={formInitValues}
  647. getFormApi={(api) => setFormApi(api)}
  648. onSubmit={refresh}
  649. allowEmpty={true}
  650. autoComplete="off"
  651. layout="vertical"
  652. trigger="change"
  653. stopValidateWithError={false}
  654. >
  655. <div className="flex flex-col gap-4">
  656. <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
  657. {/* 时间选择器 */}
  658. <div className="col-span-1 lg:col-span-2">
  659. <Form.DatePicker
  660. field='dateRange'
  661. className="w-full"
  662. type='dateTimeRange'
  663. placeholder={[t('开始时间'), t('结束时间')]}
  664. showClear
  665. pure
  666. />
  667. </div>
  668. {/* 任务 ID */}
  669. <Form.Input
  670. field='task_id'
  671. prefix={<IconSearch />}
  672. placeholder={t('任务 ID')}
  673. showClear
  674. pure
  675. />
  676. {/* 渠道 ID - 仅管理员可见 */}
  677. {isAdminUser && (
  678. <Form.Input
  679. field='channel_id'
  680. prefix={<IconSearch />}
  681. placeholder={t('渠道 ID')}
  682. showClear
  683. pure
  684. />
  685. )}
  686. </div>
  687. {/* 操作按钮区域 */}
  688. <div className="flex justify-between items-center">
  689. <div></div>
  690. <div className="flex gap-2">
  691. <Button
  692. type='primary'
  693. htmlType='submit'
  694. loading={loading}
  695. >
  696. {t('查询')}
  697. </Button>
  698. <Button
  699. theme='light'
  700. onClick={() => {
  701. if (formApi) {
  702. formApi.reset();
  703. // 重置后立即查询,使用setTimeout确保表单重置完成
  704. setTimeout(() => {
  705. refresh();
  706. }, 100);
  707. }
  708. }}
  709. >
  710. {t('重置')}
  711. </Button>
  712. <Button
  713. theme='light'
  714. type='tertiary'
  715. onClick={() => setShowColumnSelector(true)}
  716. >
  717. {t('列设置')}
  718. </Button>
  719. </div>
  720. </div>
  721. </div>
  722. </Form>
  723. </div>
  724. }
  725. shadows='always'
  726. bordered={false}
  727. >
  728. <Table
  729. columns={compactMode ? getVisibleColumns().map(({ fixed, ...rest }) => rest) : getVisibleColumns()}
  730. dataSource={logs}
  731. rowKey='key'
  732. loading={loading}
  733. scroll={compactMode ? undefined : { x: 'max-content' }}
  734. className="rounded-xl overflow-hidden"
  735. size="middle"
  736. empty={
  737. <Empty
  738. image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
  739. darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />}
  740. description={t('搜索无结果')}
  741. style={{ padding: 30 }}
  742. />
  743. }
  744. pagination={{
  745. formatPageText: (page) =>
  746. t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
  747. start: page.currentStart,
  748. end: page.currentEnd,
  749. total: logCount,
  750. }),
  751. currentPage: activePage,
  752. pageSize: pageSize,
  753. total: logCount,
  754. pageSizeOptions: [10, 20, 50, 100],
  755. showSizeChanger: true,
  756. onPageSizeChange: handlePageSizeChange,
  757. onPageChange: handlePageChange,
  758. }}
  759. />
  760. </Card>
  761. <Modal
  762. visible={isModalOpen}
  763. onOk={() => setIsModalOpen(false)}
  764. onCancel={() => setIsModalOpen(false)}
  765. closable={null}
  766. bodyStyle={{ height: '400px', overflow: 'auto' }} // 设置模态框内容区域样式
  767. width={800} // 设置模态框宽度
  768. >
  769. <p style={{ whiteSpace: 'pre-line' }}>{modalContent}</p>
  770. </Modal>
  771. </Layout>
  772. </>
  773. );
  774. };
  775. export default LogsTable;