diff --git a/back/api/cron.ts b/back/api/cron.ts index 4e44e6c4..2567cc24 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -15,7 +15,9 @@ export default (app: Router) => { const logger: Logger = Container.get('logger'); try { const cookieService = Container.get(CronService); - const data = await cookieService.crontabs(); + const data = await cookieService.crontabs( + req.query.searchValue as string, + ); return res.send({ code: 200, data }); } catch (e) { logger.error('🔥 error: %o', e); diff --git a/back/services/cron.ts b/back/services/cron.ts index 8515e46c..71ec835f 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -48,10 +48,24 @@ export default class CronService { await this.set_crontab(); } - public async crontabs(): Promise { + public async crontabs(searchText?: string): Promise { + let query = {}; + if (searchText) { + const reg = new RegExp(searchText); + query = { + $or: [ + { + name: reg, + }, + { + command: reg, + }, + ], + }; + } return new Promise((resolve) => { this.cronDb - .find({}) + .find(query) .sort({ created: -1 }) .exec((err, docs) => { resolve(docs); diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 62ba252d..d518af85 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -10,6 +10,7 @@ import { Dropdown, Menu, Typography, + Input, } from 'antd'; import { ClockCircleOutlined, @@ -29,6 +30,7 @@ import { request } from '@/utils/http'; import CronModal from './modal'; const { Text } = Typography; +const { Search } = Input; enum CrontabStatus { 'running', @@ -122,10 +124,10 @@ const Crontab = () => { const [isModalVisible, setIsModalVisible] = useState(false); const [editedCron, setEditedCron] = useState(); - const getCrons = () => { + const getCrons = (text: string = '') => { setLoading(true); request - .get(`${config.apiPrefix}crons`) + .get(`${config.apiPrefix}crons?searchValue=${text}`) .then((data: any) => { setValue(data.data.sort((a: any, b: any) => a.status - b.status)); }) @@ -310,6 +312,10 @@ const Crontab = () => { } }; + const onSearch = (value: string) => { + getCrons(value); + }; + useEffect(() => { if (document.body.clientWidth < 768) { setWdith('auto'); @@ -329,6 +335,13 @@ const Crontab = () => { title="定时任务" loading={loading} extra={[ + , ,