diff --git a/back/loaders/initFile.ts b/back/loaders/initFile.ts index 6013510b..2eab9446 100644 --- a/back/loaders/initFile.ts +++ b/back/loaders/initFile.ts @@ -116,7 +116,9 @@ export default async () => { `Neither content nor source specified for ${item.target}`, ); } - const content = item.content || (await fs.readFile(item.source!)); + const content = + item.content || + (await fs.readFile(item.source!, { encoding: 'utf-8' })); await writeFileWithLock(item.target, content); } } diff --git a/back/services/cron.ts b/back/services/cron.ts index 1d70660d..c08e8599 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -560,7 +560,10 @@ export default class CronService { if (logFileExist) { return await getFileContentByName(`${absolutePath}`); } else { - return '任务未运行'; + return typeof doc.status === 'number' && + [CrontabStatus.queued, CrontabStatus.running].includes(doc.status) + ? '运行中...' + : '任务空闲中'; } } diff --git a/back/shared/utils.ts b/back/shared/utils.ts index 59f9ce33..fb344111 100644 --- a/back/shared/utils.ts +++ b/back/shared/utils.ts @@ -13,7 +13,7 @@ function getUniqueLockPath(filePath: string) { export async function writeFileWithLock( filePath: string, - content: string | Buffer, + content: string, options: Parameters[2] = {}, ) { if (typeof options === 'string') { diff --git a/src/pages/crontab/detail.tsx b/src/pages/crontab/detail.tsx index 82d7e24f..42dd4d8f 100644 --- a/src/pages/crontab/detail.tsx +++ b/src/pages/crontab/detail.tsx @@ -56,12 +56,10 @@ interface LogItem { const CronDetailModal = ({ cron = {}, handleCancel, - visible, theme, isPhone, }: { cron?: any; - visible: boolean; handleCancel: (needUpdate?: boolean) => void; theme: string; isPhone: boolean; @@ -440,7 +438,7 @@ const CronDetailModal = ({ } centered - open={visible} + open={true} forceRender footer={false} onCancel={() => handleCancel()} @@ -559,15 +557,16 @@ const CronDetailModal = ({ {contentList[activeTabKey]} - { - setIsLogModalVisible(false); - }} - cron={cron} - data={log} - logUrl={logUrl} - /> + {isLogModalVisible && ( + { + setIsLogModalVisible(false); + }} + cron={cron} + data={log} + logUrl={logUrl} + /> + )} ); }; diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 7ef02f72..976c0ffa 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -1037,55 +1037,58 @@ const Crontab = () => { components={isPhone || pageConf.size < 50 ? undefined : vt} /> - { - getCronDetail(logCron); - setIsLogModalVisible(false); - }} - cron={logCron} - /> - - { - setIsLabelModalVisible(false); - if (needUpdate) { - getCrons(); - } - }} - ids={selectedRowIds} - /> - { - setIsDetailModalVisible(false); - }} - cron={detailCron} - theme={theme} - isPhone={isPhone} - /> - { - setIsCreateViewModalVisible(false); - getCronViews(); - }} - /> - { - setIsViewManageModalVisible(false); - }} - cronViewChange={(data) => { - getCronViews(); - }} - /> + {isLogModalVisible && ( + { + getCronDetail(logCron); + setIsLogModalVisible(false); + }} + cron={logCron} + /> + )} + {isModalVisible && ( + + )} + {isLabelModalVisible && ( + { + setIsLabelModalVisible(false); + if (needUpdate) { + getCrons(); + } + }} + ids={selectedRowIds} + /> + )} + {isDetailModalVisible && ( + { + setIsDetailModalVisible(false); + }} + cron={detailCron} + theme={theme} + isPhone={isPhone} + /> + )} + {isCreateViewModalVisible && ( + { + setIsCreateViewModalVisible(false); + getCronViews(); + }} + /> + )} + {isViewManageModalVisible && ( + { + setIsViewManageModalVisible(false); + }} + cronViewChange={(data) => { + getCronViews(); + }} + /> + )} ); }; diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index 1c5e6e03..80c2aa86 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -25,12 +25,10 @@ const { Countdown } = Statistic; const CronLogModal = ({ cron, handleCancel, - visible, data, logUrl, }: { cron?: any; - visible: boolean; handleCancel: () => void; data?: string; logUrl?: string; @@ -120,11 +118,10 @@ const CronLogModal = ({ }; useEffect(() => { - if (cron && cron.id && visible) { + if (cron && cron.id) { getCronLog(true); - scrollInfoRef.current.down = true; } - }, [cron, visible]); + }, [cron]); useEffect(() => { if (data) { @@ -139,7 +136,7 @@ const CronLogModal = ({ return ( void; }) => { const [form] = Form.useForm(); @@ -58,11 +56,6 @@ const CronModal = ({ } }; - useEffect(() => { - form.resetFields(); - setScheduleType(getScheduleType(cron?.schedule)); - }, [cron, visible]); - const handleScheduleTypeChange = (type: ScheduleType) => { setScheduleType(type); form.setFieldValue('schedule', ''); @@ -146,7 +139,7 @@ const CronModal = ({ return ( ; - visible: boolean; handleCancel: (needUpdate?: boolean) => void; }) => { const [form] = Form.useForm(); @@ -290,10 +281,6 @@ const CronLabelModal = ({ }); }; - useEffect(() => { - form.resetFields(); - }, [ids, visible]); - const buttons = [ ,