定时任务添加下次运行时间

This commit is contained in:
hanhh 2021-09-21 20:11:39 +08:00
parent 6619374571
commit 5b585e0cda
3 changed files with 54 additions and 12 deletions

View File

@ -141,7 +141,13 @@ export default class OpenService {
}); });
} }
public async authToken({ client_id, client_secret }): Promise<any> { public async authToken({
client_id,
client_secret,
}: {
client_id: string;
client_secret: string;
}): Promise<any> {
const token = uuidV4(); const token = uuidV4();
const expiration = Math.round(Date.now() / 1000) + 2592000; // 2592000 30天 const expiration = Math.round(Date.now() / 1000) + 2592000; // 2592000 30天
return new Promise((resolve) => { return new Promise((resolve) => {

View File

@ -32,6 +32,7 @@ import { PageContainer } from '@ant-design/pro-layout';
import { request } from '@/utils/http'; import { request } from '@/utils/http';
import CronModal from './modal'; import CronModal from './modal';
import CronLogModal from './logModal'; import CronLogModal from './logModal';
import cron_parser from 'cron-parser';
const { Text } = Typography; const { Text } = Typography;
const { Search } = Input; const { Search } = Input;
@ -122,6 +123,31 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
multiple: 1, 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 (
<span
style={{
textAlign: 'left',
display: 'block',
}}
>
{record.nextRunTime.toLocaleString(language, {
hour12: false,
})}
</span>
);
},
},
{ {
title: '状态', title: '状态',
key: 'status', key: 'status',
@ -248,7 +274,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
.get(`${config.apiPrefix}crons?searchValue=${searchText}`) .get(`${config.apiPrefix}crons?searchValue=${searchText}`)
.then((data: any) => { .then((data: any) => {
setValue( setValue(
data.data.sort((a: any, b: any) => { data.data
.sort((a: any, b: any) => {
const sortA = a.isDisabled ? 4 : a.status; const sortA = a.isDisabled ? 4 : a.status;
const sortB = b.isDisabled ? 4 : b.status; const sortB = b.isDisabled ? 4 : b.status;
a.isPinned = a.isPinned ? a.isPinned : 0; a.isPinned = a.isPinned ? a.isPinned : 0;
@ -257,6 +284,15 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
return CrontabSort[sortA] - CrontabSort[sortB]; return CrontabSort[sortA] - CrontabSort[sortB];
} }
return b.isPinned - a.isPinned; return b.isPinned - a.isPinned;
})
.map((x) => {
return {
...x,
nextRunTime: cron_parser
.parseExpression(x.schedule)
.next()
.toDate(),
};
}), }),
); );
setCurrentPage(1); setCurrentPage(1);

View File

@ -8,7 +8,7 @@ const EditScriptNameModal = ({
visible, visible,
}: { }: {
visible: boolean; visible: boolean;
handleCancel: (file: { filename: string }) => void; handleCancel: (file?: { filename: string }) => void;
}) => { }) => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);