定时任务支持多个定时规则

This commit is contained in:
whyour
2023-09-16 00:15:50 +08:00
parent 042d7d3b8e
commit acc7443004
17 changed files with 305 additions and 274 deletions
+14
View File
@@ -183,6 +183,20 @@ const Crontab = () => {
sorter: {
compare: (a, b) => a.schedule.localeCompare(b.schedule),
},
render: (text, record) => {
return record.extra_schedules?.length ? (
<Popover
placement="right"
content={record.extra_schedules?.map((x) => (
<div>{x.schedule}</div>
))}
>
{text}
</Popover>
) : (
text
);
},
},
{
title: intl.get('最后运行时长'),
+34 -1
View File
@@ -1,10 +1,11 @@
import intl from 'react-intl-universal';
import React, { useEffect, useState } from 'react';
import { Modal, message, Input, Form, Button } from 'antd';
import { Modal, message, Input, Form, Button, Space } from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';
import cronParse from 'cron-parser';
import EditableTagGroup from '@/components/tag';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
const CronModal = ({
cron,
@@ -107,6 +108,38 @@ const CronModal = ({
>
<Input placeholder={intl.get('秒(可选) 分 时 天 月 周')} />
</Form.Item>
<Form.List name="extra_schedules">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map(({ key, name, ...restField }) => (
<Form.Item key={key} noStyle>
<Space className="view-create-modal-sorts" align="baseline">
<Form.Item
{...restField}
name={[name, 'schedule']}
rules={[{ required: true }]}
>
<Input
placeholder={intl.get('秒(可选) 分 时 天 月 周')}
/>
</Form.Item>
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(name)}
/>
</Space>
</Form.Item>
))}
<Form.Item>
<a onClick={() => add({ schedule: '' })}>
<PlusOutlined />
{intl.get('新增定时规则')}
</a>
</Form.Item>
<Form.ErrorList errors={errors} />
</>
)}
</Form.List>
<Form.Item name="labels" label={intl.get('标签')}>
<EditableTagGroup />
</Form.Item>
+2
View File
@@ -35,4 +35,6 @@ export interface ICrontab {
last_running_time?: number;
last_execution_time?: number;
nextRunTime: Date;
sub_id: number;
extra_schedules?: Array<{ schedule: string; }>;
}
+4 -2
View File
@@ -195,7 +195,7 @@ const ViewCreateModal = ({
<Input placeholder={intl.get('请输入视图名称')} />
</Form.Item>
<Form.List name="filters">
{(fields, { add, remove }) => (
{(fields, { add, remove }, { errors }) => (
<div
style={{ position: 'relative' }}
className={`view-filters-container ${
@@ -297,12 +297,13 @@ const ViewCreateModal = ({
{intl.get('新增筛选条件')}
</a>
</Form.Item>
<Form.ErrorList errors={errors} />
</div>
</div>
)}
</Form.List>
<Form.List name="sorts">
{(fields, { add, remove }) => (
{(fields, { add, remove }, { errors }) => (
<div
style={{ position: 'relative' }}
className={`view-filters-container ${
@@ -372,6 +373,7 @@ const ViewCreateModal = ({
{intl.get('新增排序方式')}
</a>
</Form.Item>
<Form.ErrorList errors={errors} />
</div>
</div>
)}