mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
优化定时任务表格渲染
This commit is contained in:
parent
659dddace7
commit
2864845d5b
|
@ -51,6 +51,8 @@ import { FilterValue, SorterResult } from 'antd/lib/table/interface';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
import { getCommandScript } from '@/utils';
|
import { getCommandScript } from '@/utils';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
|
import { ColumnProps } from 'antd/lib/table';
|
||||||
|
|
||||||
const { Text, Paragraph } = Typography;
|
const { Text, Paragraph } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
@ -82,15 +84,30 @@ enum OperationPath {
|
||||||
'unpin',
|
'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 Crontab = () => {
|
||||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||||
const columns: any = [
|
const columns: ColumnProps<ICrontab>[] = [
|
||||||
{
|
{
|
||||||
title: '名称',
|
title: '名称',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
width: 150,
|
width: 150,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord),
|
||||||
render: (text: string, record: any) => (
|
render: (text: string, record: any) => (
|
||||||
<>
|
<>
|
||||||
<a
|
<a
|
||||||
|
@ -137,7 +154,7 @@ const Crontab = () => {
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
sorter: {
|
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',
|
key: 'command',
|
||||||
width: 300,
|
width: 300,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
render: (text: string, record: any) => {
|
shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord),
|
||||||
|
render: (text, record) => {
|
||||||
return (
|
return (
|
||||||
<Paragraph
|
<Paragraph
|
||||||
style={{
|
style={{
|
||||||
|
@ -176,8 +194,9 @@ const Crontab = () => {
|
||||||
key: 'schedule',
|
key: 'schedule',
|
||||||
width: 110,
|
width: 110,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord),
|
||||||
sorter: {
|
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',
|
key: 'last_execution_time',
|
||||||
width: 150,
|
width: 150,
|
||||||
sorter: {
|
sorter: {
|
||||||
compare: (a: any, b: any) => {
|
compare: (a, b) => {
|
||||||
return a.last_execution_time - b.last_execution_time;
|
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];
|
const language = navigator.language || navigator.languages[0];
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
@ -221,7 +241,8 @@ const Crontab = () => {
|
||||||
return a.last_running_time - b.last_running_time;
|
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
|
return record.last_running_time
|
||||||
? diffTime(record.last_running_time)
|
? diffTime(record.last_running_time)
|
||||||
: '-';
|
: '-';
|
||||||
|
@ -236,7 +257,8 @@ const Crontab = () => {
|
||||||
return a.nextRunTime - b.nextRunTime;
|
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];
|
const language = navigator.language || navigator.languages[0];
|
||||||
return record.nextRunTime
|
return record.nextRunTime
|
||||||
.toLocaleString(language, {
|
.toLocaleString(language, {
|
||||||
|
@ -270,14 +292,15 @@ const Crontab = () => {
|
||||||
value: 3,
|
value: 3,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
onFilter: (value: number, record: any) => {
|
onFilter: (value, record) => {
|
||||||
if (record.isDisabled && record.status !== 0) {
|
if (record.isDisabled && record.status !== 0) {
|
||||||
return value === 2;
|
return value === 2;
|
||||||
} else {
|
} else {
|
||||||
return record.status === value;
|
return record.status === value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: (text: string, record: any) => (
|
shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord),
|
||||||
|
render: (text, record) => (
|
||||||
<>
|
<>
|
||||||
{(!record.isDisabled || record.status !== CrontabStatus.idle) && (
|
{(!record.isDisabled || record.status !== CrontabStatus.idle) && (
|
||||||
<>
|
<>
|
||||||
|
@ -314,7 +337,8 @@ const Crontab = () => {
|
||||||
key: 'action',
|
key: 'action',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
width: 100,
|
width: 100,
|
||||||
render: (text: string, record: any, index: number) => {
|
shouldCellUpdate: (record, prevRecord) => isEqual(record, prevRecord),
|
||||||
|
render: (text, record, index) => {
|
||||||
const isPc = !isPhone;
|
const isPc = !isPhone;
|
||||||
return (
|
return (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user