mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-30 00:16:07 +08:00
修复筛选bug
This commit is contained in:
parent
065f1dca01
commit
b83bc8fb0d
|
@ -40,11 +40,12 @@ import { request } from '@/utils/http';
|
||||||
import CronModal from './modal';
|
import CronModal from './modal';
|
||||||
import CronLogModal from './logModal';
|
import CronLogModal from './logModal';
|
||||||
import AddFilterModal from './addFilterModal';
|
import AddFilterModal from './addFilterModal';
|
||||||
|
import { store } from './store';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
|
||||||
type Pane = { title: string; key: string };
|
export type Pane = { title: string; key: string };
|
||||||
|
|
||||||
enum CrontabStatus {
|
enum CrontabStatus {
|
||||||
'running',
|
'running',
|
||||||
|
@ -200,7 +201,7 @@ const Crontab = () => {
|
||||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||||
const [logCron, setLogCron] = useState<any>();
|
const [logCron, setLogCron] = useState<any>();
|
||||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||||
const [panes, setPanes] = useState<Pane[]>([
|
const [paneList, setPaneList] = useState<Pane[]>([
|
||||||
{
|
{
|
||||||
title: '内置命令',
|
title: '内置命令',
|
||||||
key: 'ql',
|
key: 'ql',
|
||||||
|
@ -209,11 +210,19 @@ const Crontab = () => {
|
||||||
const [activeKey, setActiveKey] = useState<string>(KEY_ALL);
|
const [activeKey, setActiveKey] = useState<string>(KEY_ALL);
|
||||||
const addFilterModalRef = useRef(null);
|
const addFilterModalRef = useRef(null);
|
||||||
|
|
||||||
|
const setPanesAndStore = useCallback(
|
||||||
|
(panes: Pane[]) => {
|
||||||
|
setPaneList(panes);
|
||||||
|
store.savePanes(panes);
|
||||||
|
},
|
||||||
|
[setPaneList],
|
||||||
|
);
|
||||||
|
|
||||||
const handleAddFilter = useCallback(
|
const handleAddFilter = useCallback(
|
||||||
(values) => {
|
(values) => {
|
||||||
setPanes([...panes, values]);
|
setPanesAndStore([...paneList, values]);
|
||||||
},
|
},
|
||||||
[panes, setPanes],
|
[paneList, setPanesAndStore],
|
||||||
);
|
);
|
||||||
|
|
||||||
const getCrons = () => {
|
const getCrons = () => {
|
||||||
|
@ -541,25 +550,28 @@ const Crontab = () => {
|
||||||
|
|
||||||
const remove = useCallback(
|
const remove = useCallback(
|
||||||
(targetKey) => {
|
(targetKey) => {
|
||||||
setPanes(panes.filter((pane) => pane.key !== targetKey));
|
setPanesAndStore(paneList.filter((pane) => pane.key !== targetKey));
|
||||||
},
|
},
|
||||||
[panes, setPanes],
|
[paneList, setPanesAndStore],
|
||||||
);
|
);
|
||||||
|
|
||||||
const add = useCallback(() => {
|
const add = useCallback(() => {
|
||||||
(addFilterModalRef.current as any).showModal();
|
(addFilterModalRef.current as any).showModal();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onEdit = useCallback((targetKey: string, action: string) => {
|
const onEdit = useCallback(
|
||||||
if (action === 'remove') {
|
(targetKey: string, action: string) => {
|
||||||
remove(targetKey);
|
if (action === 'remove') {
|
||||||
} else {
|
remove(targetKey);
|
||||||
add();
|
} else {
|
||||||
}
|
add();
|
||||||
}, []);
|
}
|
||||||
|
},
|
||||||
|
[remove],
|
||||||
|
);
|
||||||
|
|
||||||
const onTabChange = useCallback((activeKey: string) => {
|
const onTabChange = useCallback((activeKey: string) => {
|
||||||
activeKey !== KEY_ALL && onSearch(activeKey);
|
onSearch(activeKey !== KEY_ALL ? activeKey : '');
|
||||||
setActiveKey(activeKey);
|
setActiveKey(activeKey);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -574,6 +586,11 @@ const Crontab = () => {
|
||||||
getCrons();
|
getCrons();
|
||||||
}, [searchText]);
|
}, [searchText]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const panes = store.getPanes();
|
||||||
|
panes && setPaneList(panes);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (document.body.clientWidth < 768) {
|
if (document.body.clientWidth < 768) {
|
||||||
setWidth('auto');
|
setWidth('auto');
|
||||||
|
@ -658,7 +675,7 @@ const Crontab = () => {
|
||||||
onChange={onTabChange}
|
onChange={onTabChange}
|
||||||
>
|
>
|
||||||
<Tabs.TabPane key={KEY_ALL} tab="全部" closable={false}></Tabs.TabPane>
|
<Tabs.TabPane key={KEY_ALL} tab="全部" closable={false}></Tabs.TabPane>
|
||||||
{panes.map((pane) => {
|
{paneList.map((pane) => {
|
||||||
return <Tabs.TabPane key={pane.key} tab={pane.title}></Tabs.TabPane>;
|
return <Tabs.TabPane key={pane.key} tab={pane.title}></Tabs.TabPane>;
|
||||||
})}
|
})}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
20
src/pages/crontab/store.ts
Normal file
20
src/pages/crontab/store.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import type { Pane } from './index';
|
||||||
|
|
||||||
|
const KEY_PANES = '__panes__';
|
||||||
|
|
||||||
|
export const store = {
|
||||||
|
savePanes(panes: Pane[]) {
|
||||||
|
localStorage.setItem(KEY_PANES, JSON.stringify({ data: panes }));
|
||||||
|
},
|
||||||
|
|
||||||
|
getPanes() {
|
||||||
|
const panesStr = localStorage.getItem(KEY_PANES);
|
||||||
|
try {
|
||||||
|
if (panesStr) {
|
||||||
|
let panes = JSON.parse(panesStr);
|
||||||
|
return panes.data;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user