From 2864845d5b2870c238ad9902eb23c4949452a982 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 8 Jan 2023 18:15:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=A1=A8=E6=A0=BC=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/crontab/index.tsx | 48 +++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 638aa1a5..2dacf35f 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -51,6 +51,8 @@ import { FilterValue, SorterResult } from 'antd/lib/table/interface'; import { SharedContext } from '@/layouts'; import useTableScrollHeight from '@/hooks/useTableScrollHeight'; import { getCommandScript } from '@/utils'; +import { isEqual } from 'lodash'; +import { ColumnProps } from 'antd/lib/table'; const { Text, Paragraph } = Typography; const { Search } = Input; @@ -82,15 +84,30 @@ enum OperationPath { 'unpin', } +export interface ICrontab { + name: string; + command: string; + schedule: string; + id: number; + status: number; + isDisabled?: 1 | 0; + isPinned?: 1 | 0; + labels?: string[]; + last_running_time?: number; + last_execution_time?: number; + nextRunTime: Date; +} + const Crontab = () => { const { headerStyle, isPhone, theme } = useOutletContext(); - const columns: any = [ + const columns: ColumnProps[] = [ { title: '名称', dataIndex: 'name', key: 'name', width: 150, align: 'center' as const, + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), render: (text: string, record: any) => ( <> { ), sorter: { - compare: (a: any, b: any) => a?.name?.localeCompare(b?.name), + compare: (a, b) => a?.name?.localeCompare(b?.name), }, }, { @@ -146,7 +163,8 @@ const Crontab = () => { key: 'command', width: 300, align: 'center' as const, - render: (text: string, record: any) => { + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), + render: (text, record) => { return ( { key: 'schedule', width: 110, align: 'center' as const, + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), sorter: { - compare: (a: any, b: any) => a.schedule.localeCompare(b.schedule), + compare: (a, b) => a.schedule.localeCompare(b.schedule), }, }, { @@ -187,11 +206,12 @@ const Crontab = () => { key: 'last_execution_time', width: 150, sorter: { - compare: (a: any, b: any) => { - return a.last_execution_time - b.last_execution_time; + compare: (a, b) => { + return (a.last_execution_time || 0) - (b.last_execution_time || 0); }, }, - render: (text: string, record: any) => { + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), + render: (text, record) => { const language = navigator.language || navigator.languages[0]; return ( { return a.last_running_time - b.last_running_time; }, }, - render: (text: string, record: any) => { + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), + render: (text, record) => { return record.last_running_time ? diffTime(record.last_running_time) : '-'; @@ -236,7 +257,8 @@ const Crontab = () => { return a.nextRunTime - b.nextRunTime; }, }, - render: (text: string, record: any) => { + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), + render: (text, record) => { const language = navigator.language || navigator.languages[0]; return record.nextRunTime .toLocaleString(language, { @@ -270,14 +292,15 @@ const Crontab = () => { value: 3, }, ], - onFilter: (value: number, record: any) => { + onFilter: (value, record) => { if (record.isDisabled && record.status !== 0) { return value === 2; } else { return record.status === value; } }, - render: (text: string, record: any) => ( + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), + render: (text, record) => ( <> {(!record.isDisabled || record.status !== CrontabStatus.idle) && ( <> @@ -314,7 +337,8 @@ const Crontab = () => { key: 'action', align: 'center' as const, width: 100, - render: (text: string, record: any, index: number) => { + shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord), + render: (text, record, index) => { const isPc = !isPhone; return (