mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 20:06:08 +08:00
增加cron搜索
This commit is contained in:
parent
f46e20fc81
commit
a7d652c86e
|
@ -15,7 +15,9 @@ export default (app: Router) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
const cookieService = Container.get(CronService);
|
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 });
|
return res.send({ code: 200, data });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('🔥 error: %o', e);
|
logger.error('🔥 error: %o', e);
|
||||||
|
|
|
@ -48,10 +48,24 @@ export default class CronService {
|
||||||
await this.set_crontab();
|
await this.set_crontab();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async crontabs(): Promise<Crontab[]> {
|
public async crontabs(searchText?: string): Promise<Crontab[]> {
|
||||||
|
let query = {};
|
||||||
|
if (searchText) {
|
||||||
|
const reg = new RegExp(searchText);
|
||||||
|
query = {
|
||||||
|
$or: [
|
||||||
|
{
|
||||||
|
name: reg,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
command: reg,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.cronDb
|
this.cronDb
|
||||||
.find({})
|
.find(query)
|
||||||
.sort({ created: -1 })
|
.sort({ created: -1 })
|
||||||
.exec((err, docs) => {
|
.exec((err, docs) => {
|
||||||
resolve(docs);
|
resolve(docs);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
Dropdown,
|
Dropdown,
|
||||||
Menu,
|
Menu,
|
||||||
Typography,
|
Typography,
|
||||||
|
Input,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
ClockCircleOutlined,
|
ClockCircleOutlined,
|
||||||
|
@ -29,6 +30,7 @@ import { request } from '@/utils/http';
|
||||||
import CronModal from './modal';
|
import CronModal from './modal';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
const { Search } = Input;
|
||||||
|
|
||||||
enum CrontabStatus {
|
enum CrontabStatus {
|
||||||
'running',
|
'running',
|
||||||
|
@ -122,10 +124,10 @@ const Crontab = () => {
|
||||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||||
const [editedCron, setEditedCron] = useState();
|
const [editedCron, setEditedCron] = useState();
|
||||||
|
|
||||||
const getCrons = () => {
|
const getCrons = (text: string = '') => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}crons`)
|
.get(`${config.apiPrefix}crons?searchValue=${text}`)
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
setValue(data.data.sort((a: any, b: any) => a.status - b.status));
|
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(() => {
|
useEffect(() => {
|
||||||
if (document.body.clientWidth < 768) {
|
if (document.body.clientWidth < 768) {
|
||||||
setWdith('auto');
|
setWdith('auto');
|
||||||
|
@ -329,6 +335,13 @@ const Crontab = () => {
|
||||||
title="定时任务"
|
title="定时任务"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
extra={[
|
extra={[
|
||||||
|
<Search
|
||||||
|
placeholder="请输入名称或者关键词"
|
||||||
|
style={{ width: 'auto' }}
|
||||||
|
enterButton
|
||||||
|
loading={loading}
|
||||||
|
onSearch={onSearch}
|
||||||
|
/>,
|
||||||
<Button key="2" type="primary" onClick={() => addCron()}>
|
<Button key="2" type="primary" onClick={() => addCron()}>
|
||||||
添加定时
|
添加定时
|
||||||
</Button>,
|
</Button>,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user