From f970322f0afedf2fb5276b98b772f9cfaeacf6c8 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 2 Jul 2023 12:19:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=8A=B6=E6=80=81=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 2 +- src/pages/crontab/detail.tsx | 2 +- src/pages/crontab/index.tsx | 50 +++------------------------ src/pages/crontab/logModal.tsx | 7 +--- src/pages/crontab/type.ts | 38 ++++++++++++++++++++ src/pages/crontab/viewCreateModal.tsx | 7 ++-- 6 files changed, 50 insertions(+), 56 deletions(-) create mode 100644 src/pages/crontab/type.ts diff --git a/back/services/cron.ts b/back/services/cron.ts index f55cb941..e377240c 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -267,7 +267,7 @@ export default class CronService { let q: any = {}; if (!filterQuery[key]) continue; if (key === 'status') { - if (filterQuery[key].includes(2)) { + if (filterQuery[key].includes(CrontabStatus.disabled)) { q = { [Op.or]: [{ [key]: filterQuery[key] }, { isDisabled: 1 }] }; } else { q = { [Op.and]: [{ [key]: filterQuery[key] }, { isDisabled: 0 }] }; diff --git a/src/pages/crontab/detail.tsx b/src/pages/crontab/detail.tsx index 1587e891..6c9cbd6e 100644 --- a/src/pages/crontab/detail.tsx +++ b/src/pages/crontab/detail.tsx @@ -22,7 +22,7 @@ import { PauseCircleOutlined, FullscreenOutlined, } from '@ant-design/icons'; -import { CrontabStatus } from './index'; +import { CrontabStatus } from './type'; import { diffTime } from '@/utils/date'; import { request } from '@/utils/http'; import config from '@/utils/config'; diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 0192ce12..4e3ca3bf 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -54,51 +54,11 @@ import useTableScrollHeight from '@/hooks/useTableScrollHeight'; import { getCommandScript, parseCrontab } from '@/utils'; import { ColumnProps } from 'antd/lib/table'; import { useVT } from 'virtualizedtableforantd4'; +import { ICrontab, OperationName, OperationPath, CrontabStatus } from './type'; const { Text, Paragraph } = Typography; const { Search } = Input; -export enum CrontabStatus { - 'running', - 'queued', - 'idle', - 'disabled', -} - -const CrontabSort: any = { 0: 0, 5: 1, 3: 2, 1: 3, 4: 4 }; - -enum OperationName { - '启用', - '禁用', - '运行', - '停止', - '置顶', - '取消置顶', -} - -enum OperationPath { - 'enable', - 'disable', - 'run', - 'stop', - 'pin', - '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: ColumnProps[] = [ @@ -264,19 +224,19 @@ const Crontab = () => { filters: [ { text: '运行中', - value: 0, + value: CrontabStatus.running, }, { text: '空闲中', - value: 1, + value: CrontabStatus.idle, }, { text: '已禁用', - value: 2, + value: CrontabStatus.disabled, }, { text: '队列中', - value: 3, + value: CrontabStatus.queued, }, ], render: (text, record) => ( diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index d85100ed..e8d9bd04 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -8,13 +8,8 @@ import { } from '@ant-design/icons'; import { PageLoading } from '@ant-design/pro-layout'; import { logEnded } from '@/utils'; +import { CrontabStatus } from './type'; -enum CrontabStatus { - 'running', - 'idle', - 'disabled', - 'queued', -} const { Countdown } = Statistic; const CronLogModal = ({ diff --git a/src/pages/crontab/type.ts b/src/pages/crontab/type.ts new file mode 100644 index 00000000..cdc8f175 --- /dev/null +++ b/src/pages/crontab/type.ts @@ -0,0 +1,38 @@ +export enum CrontabStatus { + 'running', + 'queued', + 'idle', + 'disabled', +} + +export enum OperationName { + '启用', + '禁用', + '运行', + '停止', + '置顶', + '取消置顶', +} + +export enum OperationPath { + 'enable', + 'disable', + 'run', + 'stop', + 'pin', + '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; +} diff --git a/src/pages/crontab/viewCreateModal.tsx b/src/pages/crontab/viewCreateModal.tsx index 778a03f5..98538f2a 100644 --- a/src/pages/crontab/viewCreateModal.tsx +++ b/src/pages/crontab/viewCreateModal.tsx @@ -14,6 +14,7 @@ import config from '@/utils/config'; import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import IconFont from '@/components/iconfont'; import get from 'lodash/get'; +import { CrontabStatus } from './type'; const PROPERTIES = [ { name: '命令', value: 'command' }, @@ -47,9 +48,9 @@ const SORTTYPES = [ const STATUS_MAP = { status: [ - { name: '运行中', value: 0 }, - { name: '空闲中', value: 1 }, - { name: '已禁用', value: 2 }, + { name: '运行中', value: CrontabStatus.running }, + { name: '空闲中', value: CrontabStatus.idle }, + { name: '已禁用', value: CrontabStatus.disabled }, ], };