From 5b585e0cda49e516fb78a4c2c0c00af28b5d57e0 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Tue, 21 Sep 2021 20:11:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=8B=E6=AC=A1=E8=BF=90=E8=A1=8C=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/open.ts | 8 ++++- src/pages/crontab/index.tsx | 56 ++++++++++++++++++++++++------ src/pages/script/editNameModal.tsx | 2 +- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/back/services/open.ts b/back/services/open.ts index 17f406da..d83024b1 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -141,7 +141,13 @@ export default class OpenService { }); } - public async authToken({ client_id, client_secret }): Promise { + public async authToken({ + client_id, + client_secret, + }: { + client_id: string; + client_secret: string; + }): Promise { const token = uuidV4(); const expiration = Math.round(Date.now() / 1000) + 2592000; // 2592000 30天 return new Promise((resolve) => { diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index dcd8d22d..dd49a11f 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -32,6 +32,7 @@ import { PageContainer } from '@ant-design/pro-layout'; import { request } from '@/utils/http'; import CronModal from './modal'; import CronLogModal from './logModal'; +import cron_parser from 'cron-parser'; const { Text } = Typography; const { Search } = Input; @@ -122,6 +123,31 @@ const Crontab = ({ headerStyle, isPhone }: any) => { multiple: 1, }, }, + { + title: '下次运行时间', + align: 'center' as const, + sorter: { + compare: (a: any, b: any) => { + return a.nextRunTime - b.nextRunTime; + }, + }, + render: (text: string, record: any) => { + const language = navigator.language || navigator.languages[0]; + return ( + + {record.nextRunTime.toLocaleString(language, { + hour12: false, + })} + + ); + }, + }, + { title: '状态', key: 'status', @@ -248,16 +274,26 @@ const Crontab = ({ headerStyle, isPhone }: any) => { .get(`${config.apiPrefix}crons?searchValue=${searchText}`) .then((data: any) => { setValue( - data.data.sort((a: any, b: any) => { - const sortA = a.isDisabled ? 4 : a.status; - const sortB = b.isDisabled ? 4 : b.status; - a.isPinned = a.isPinned ? a.isPinned : 0; - b.isPinned = b.isPinned ? b.isPinned : 0; - if (a.isPinned === b.isPinned) { - return CrontabSort[sortA] - CrontabSort[sortB]; - } - return b.isPinned - a.isPinned; - }), + data.data + .sort((a: any, b: any) => { + const sortA = a.isDisabled ? 4 : a.status; + const sortB = b.isDisabled ? 4 : b.status; + a.isPinned = a.isPinned ? a.isPinned : 0; + b.isPinned = b.isPinned ? b.isPinned : 0; + if (a.isPinned === b.isPinned) { + return CrontabSort[sortA] - CrontabSort[sortB]; + } + return b.isPinned - a.isPinned; + }) + .map((x) => { + return { + ...x, + nextRunTime: cron_parser + .parseExpression(x.schedule) + .next() + .toDate(), + }; + }), ); setCurrentPage(1); }) diff --git a/src/pages/script/editNameModal.tsx b/src/pages/script/editNameModal.tsx index 0fc331fa..75528428 100644 --- a/src/pages/script/editNameModal.tsx +++ b/src/pages/script/editNameModal.tsx @@ -8,7 +8,7 @@ const EditScriptNameModal = ({ visible, }: { visible: boolean; - handleCancel: (file: { filename: string }) => void; + handleCancel: (file?: { filename: string }) => void; }) => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false);