Skip to content

Commit

Permalink
定时任务详情增加额外定时展示
Browse files Browse the repository at this point in the history
  • Loading branch information
whyour committed Sep 29, 2023
1 parent 4c19054 commit 9d55cb1
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 210 deletions.
366 changes: 210 additions & 156 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions src/pages/crontab/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import IconFont from '@/components/iconfont';
import { getCommandScript, getEditorMode } from '@/utils';
import VirtualList from 'rc-virtual-list';
import useScrollHeight from '@/hooks/useScrollHeight';
import dayjs from 'dayjs';

const { Text } = Typography;

Expand All @@ -52,8 +53,6 @@ interface LogItem {
filename: string;
}

const language = navigator.language || navigator.languages[0];

const CronDetailModal = ({
cron = {},
handleCancel,
Expand Down Expand Up @@ -498,19 +497,22 @@ const CronDetailModal = ({
</div>
<div className="cron-detail-info-item">
<div className="cron-detail-info-title">{intl.get('定时')}</div>
<div className="cron-detail-info-value">{currentCron.schedule}</div>
<div className="cron-detail-info-value">
<div>{currentCron.schedule}</div>
{currentCron.extra_schedules?.map((x) => (
<div key={x.schedule}>{x.schedule}</div>
))}
</div>
</div>
<div className="cron-detail-info-item">
<div className="cron-detail-info-title">
{intl.get('最后运行时间')}
</div>
<div className="cron-detail-info-value">
{currentCron.last_execution_time
? new Date(currentCron.last_execution_time * 1000)
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:')
? dayjs(currentCron.last_execution_time * 1000).format(
'YYYY-MM-DD HH:mm:ss',
)
: '-'}
</div>
</div>
Expand All @@ -530,11 +532,7 @@ const CronDetailModal = ({
</div>
<div className="cron-detail-info-value">
{currentCron.nextRunTime &&
currentCron.nextRunTime
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:')}
dayjs(currentCron.nextRunTime).format('YYYY-MM-DD HH:mm:ss')}
</div>
</div>
</Card>
Expand Down
5 changes: 2 additions & 3 deletions src/pages/crontab/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
overflow: auto;

.ant-card-body {
min-width: 600px;
min-width: 1000px;
}

.cron-detail-info-item {
Expand All @@ -58,7 +58,7 @@
.ant-card-body {
display: flex;
justify-content: space-between;
min-width: 600px;
min-width: 1000px;
}
}

Expand All @@ -78,7 +78,6 @@
display: flex;
align-items: center;
justify-content: space-between;
margin-right: 32px;

.operations {
display: flex;
Expand Down
63 changes: 36 additions & 27 deletions src/pages/crontab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ import ViewManageModal from './viewManageModal';
import { FilterValue, SorterResult } from 'antd/lib/table/interface';
import { SharedContext } from '@/layouts';
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
import { getCommandScript, parseCrontab } from '@/utils';
import { getCommandScript, getCrontabsNextDate, parseCrontab } from '@/utils';
import { ColumnProps } from 'antd/lib/table';
import { useVT } from 'virtualizedtableforantd4';
import { ICrontab, OperationName, OperationPath, CrontabStatus } from './type';
import Name from '@/components/name';
import dayjs from 'dayjs';

const { Text, Paragraph } = Typography;
const { Text, Paragraph, Link } = Typography;
const { Search } = Input;

const Crontab = () => {
Expand All @@ -74,17 +75,18 @@ const Crontab = () => {
style={{
wordBreak: 'break-all',
marginBottom: 0,
color: '#1890ff'
}}
ellipsis={{ tooltip: text, rows: 2 }}
>
<a
<Link
onClick={() => {
setDetailCron(record);
setIsDetailModalVisible(true);
}}
>
{record.name || '-'}
</a>
</Link>
</Paragraph>
),
sorter: {
Expand Down Expand Up @@ -183,17 +185,29 @@ const Crontab = () => {
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>
))}
return (
<Paragraph
style={{
wordBreak: 'break-all',
marginBottom: 0,
}}
ellipsis={{
tooltip: {
placement: 'right',
title: (
<>
<div>{text}</div>
{record.extra_schedules?.map((x) => (
<div key={x.schedule}>{x.schedule}</div>
))}
</>
),
},
rows: 2,
}}
>
{text}
</Popover>
) : (
text
</Paragraph>
);
},
},
Expand Down Expand Up @@ -224,19 +238,16 @@ const Crontab = () => {
},
},
render: (text, record) => {
const language = navigator.language || navigator.languages[0];
return (
<span
style={{
display: 'block',
}}
>
{record.last_execution_time
? new Date(record.last_execution_time * 1000)
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:')
? dayjs(record.last_execution_time * 1000).format(
'YYYY-MM-DD HH:mm:ss',
)
: '-'}
</span>
);
Expand All @@ -251,12 +262,7 @@ const Crontab = () => {
},
},
render: (text, record) => {
const language = navigator.language || navigator.languages[0];
return record.nextRunTime
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:');
return dayjs(record.nextRunTime).format('YYYY-MM-DD HH:mm:ss');
},
},
{
Expand Down Expand Up @@ -389,7 +395,7 @@ const Crontab = () => {
data.map((x) => {
return {
...x,
nextRunTime: parseCrontab(x.schedule),
nextRunTime: getCrontabsNextDate(x.schedule, x.extra_schedules),
};
}),
);
Expand Down Expand Up @@ -677,7 +683,10 @@ const Crontab = () => {
if (code === 200) {
const index = value.findIndex((x) => x.id === cron.id);
const result = [...value];
data.nextRunTime = parseCrontab(data.schedule);
data.nextRunTime = getCrontabsNextDate(
data.schedule,
data.extra_schedules,
);
if (index !== -1) {
result.splice(index, 1, {
...cron,
Expand Down
11 changes: 4 additions & 7 deletions src/pages/env/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SharedContext } from '@/layouts';
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
import Copy from '../../components/copy';
import { useVT } from 'virtualizedtableforantd4';
import dayjs from 'dayjs';

const { Paragraph } = Typography;
const { Search } = Input;
Expand Down Expand Up @@ -137,13 +138,9 @@ const Env = () => {
},
},
render: (text: string, record: any) => {
const language = navigator.language || navigator.languages[0];
const time = record.updatedAt || record.timestamp;
const date = new Date(time)
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:');
const date = dayjs(record.updatedAt || record.timestamp).format(
'YYYY-MM-DD HH:mm:ss',
);
return (
<Tooltip
placement="topLeft"
Expand Down
3 changes: 2 additions & 1 deletion src/pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { request } from '@/utils/http';
import { useTheme } from '@/utils/hooks';
import { MobileOutlined } from '@ant-design/icons';
import { SharedContext } from '@/layouts';
import dayjs from 'dayjs';

const FormItem = Form.Item;
const { Countdown } = Statistic;
Expand Down Expand Up @@ -86,7 +87,7 @@ const Login = () => {
<>
<div>
{intl.get('上次登录时间:')}
{lastlogon ? new Date(lastlogon).toLocaleString() : '-'}
{lastlogon ? dayjs(lastlogon).format('YYYY-MM-DD HH:mm:ss') : '-'}
</div>
<div>
{intl.get('上次登录地点:')}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/setting/loginLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react';
import { Typography, Table, Tag, Button, Spin, message } from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';
import dayjs from 'dayjs';

const { Text, Link } = Typography;

Expand Down Expand Up @@ -30,7 +31,7 @@ const columns = [
key: 'timestamp',
width: 120,
render: (text: string, record: any) => {
return new Date(record.timestamp).toLocaleString();
return dayjs(record.timestamp).format('YYYY-MM-DD HH:mm:ss');
},
},
{
Expand Down
17 changes: 15 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,28 @@ export function getCommandScript(
return [s, p];
}

export function parseCrontab(schedule: string): Date {
export function parseCrontab(schedule: string): Date | null {
try {
const time = cron_parser.parseExpression(schedule);
if (time) {
return time.next().toDate();
}
} catch (error) { }

return new Date('1970');
return null;
}

export function getCrontabsNextDate(schedule: string, extra_schedules: string[]): Date | null {
let date = parseCrontab(schedule)
if (extra_schedules?.length) {
extra_schedules.forEach(x => {
const _date = parseCrontab(x)
if (_date && (!date || _date < date)) {
date = _date;
}
})
}
return date;
}

export function getExtension(filename: string) {
Expand Down

0 comments on commit 9d55cb1

Please sign in to comment.