mirror of
https://github.com/whyour/qinglong.git
synced 2026-06-30 20:35:09 +08:00
添加最后运行时间和运行时长
This commit is contained in:
@@ -33,6 +33,7 @@ import { request } from '@/utils/http';
|
||||
import CronModal from './modal';
|
||||
import CronLogModal from './logModal';
|
||||
import cron_parser from 'cron-parser';
|
||||
import { diffTime } from '@/utils/date';
|
||||
|
||||
const { Text } = Typography;
|
||||
const { Search } = Input;
|
||||
@@ -123,6 +124,59 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
|
||||
multiple: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '最后运行时间',
|
||||
align: 'center' as const,
|
||||
sorter: {
|
||||
compare: (a: any, b: any) => {
|
||||
return a.last_execution_time - b.last_execution_time;
|
||||
},
|
||||
},
|
||||
render: (text: string, record: any) => {
|
||||
const language = navigator.language || navigator.languages[0];
|
||||
return (
|
||||
<span
|
||||
style={{
|
||||
textAlign: 'left',
|
||||
display: 'block',
|
||||
}}
|
||||
>
|
||||
{record.last_execution_time
|
||||
? new Date(record.last_execution_time * 1000).toLocaleString(
|
||||
language,
|
||||
{
|
||||
hour12: false,
|
||||
},
|
||||
)
|
||||
: '-'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '最后运行时长',
|
||||
align: 'center' as const,
|
||||
sorter: {
|
||||
compare: (a: any, b: any) => {
|
||||
return a.last_running_time - b.last_running_time;
|
||||
},
|
||||
},
|
||||
render: (text: string, record: any) => {
|
||||
const language = navigator.language || navigator.languages[0];
|
||||
return (
|
||||
<span
|
||||
style={{
|
||||
textAlign: 'left',
|
||||
display: 'block',
|
||||
}}
|
||||
>
|
||||
{record.last_running_time
|
||||
? diffTime(record.last_running_time)
|
||||
: '-'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '下次运行时间',
|
||||
align: 'center' as const,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
export function diffTime(num: number) {
|
||||
const diff = num * 1000;
|
||||
|
||||
const days = Math.floor(diff / (24 * 3600 * 1000));
|
||||
|
||||
const leave1 = diff % (24 * 3600 * 1000);
|
||||
const hours = Math.floor(leave1 / (3600 * 1000));
|
||||
|
||||
const leave2 = leave1 % (3600 * 1000);
|
||||
const minutes = Math.floor(leave2 / (60 * 1000));
|
||||
|
||||
const leave3 = leave2 % (60 * 1000);
|
||||
const seconds = Math.round(leave3 / 1000);
|
||||
|
||||
let returnStr = seconds + '秒';
|
||||
if (minutes > 0) {
|
||||
returnStr = minutes + '分' + returnStr;
|
||||
}
|
||||
if (hours > 0) {
|
||||
returnStr = hours + '小时' + returnStr;
|
||||
}
|
||||
if (days > 0) {
|
||||
returnStr = days + '天' + returnStr;
|
||||
}
|
||||
return returnStr;
|
||||
}
|
||||
Reference in New Issue
Block a user