mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 07:16:08 +08:00
修复脚本管理搜索
This commit is contained in:
parent
47b06c3487
commit
b849d8b526
|
@ -16,7 +16,6 @@ function getFilterData(keyword: string, data: any) {
|
|||
data.forEach((item: any) => {
|
||||
if (item.title.toLocaleLowerCase().includes(keyword)) {
|
||||
tree.push(item);
|
||||
expandedKeys.push(...item.children.map((x: any) => x.key));
|
||||
} else {
|
||||
const children: any[] = [];
|
||||
(item.children || []).forEach((subItem: any) => {
|
||||
|
@ -29,7 +28,7 @@ function getFilterData(keyword: string, data: any) {
|
|||
...item,
|
||||
children,
|
||||
});
|
||||
expandedKeys.push(...children.map((x) => x.key));
|
||||
expandedKeys.push(item.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -47,6 +46,7 @@ const Log = ({ headerStyle, isPhone, theme }: any) => {
|
|||
const [loading, setLoading] = useState(false);
|
||||
const [height, setHeight] = useState<number>();
|
||||
const treeDom = useRef<any>();
|
||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
||||
|
||||
const getLogs = () => {
|
||||
setLoading(true);
|
||||
|
@ -100,8 +100,12 @@ const Log = ({ headerStyle, isPhone, theme }: any) => {
|
|||
const onSearch = useCallback(
|
||||
(e) => {
|
||||
const keyword = e.target.value;
|
||||
const { tree } = getFilterData(keyword.toLocaleLowerCase(), data);
|
||||
const { tree, expandedKeys } = getFilterData(
|
||||
keyword.toLocaleLowerCase(),
|
||||
data,
|
||||
);
|
||||
setFilterData(tree);
|
||||
setExpandedKeys(expandedKeys);
|
||||
},
|
||||
[data, setFilterData],
|
||||
);
|
||||
|
@ -127,7 +131,6 @@ const Log = ({ headerStyle, isPhone, theme }: any) => {
|
|||
treeData={data}
|
||||
placeholder="请选择日志文件"
|
||||
showSearch
|
||||
key="value"
|
||||
onSelect={onSelect}
|
||||
/>,
|
||||
]
|
||||
|
|
|
@ -35,16 +35,31 @@ import EditScriptNameModal from './editNameModal';
|
|||
const { Text } = Typography;
|
||||
|
||||
function getFilterData(keyword: string, data: any) {
|
||||
const expandedKeys: string[] = [];
|
||||
if (keyword) {
|
||||
const tree: any = [];
|
||||
data.forEach((item: any) => {
|
||||
if (item.title.toLocaleLowerCase().includes(keyword)) {
|
||||
tree.push(item);
|
||||
} else {
|
||||
const children: any[] = [];
|
||||
(item.children || []).forEach((subItem: any) => {
|
||||
if (subItem.title.toLocaleLowerCase().includes(keyword)) {
|
||||
children.push(subItem);
|
||||
}
|
||||
});
|
||||
if (children.length > 0) {
|
||||
tree.push({
|
||||
...item,
|
||||
children,
|
||||
});
|
||||
expandedKeys.push(item.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
return { tree };
|
||||
return { tree, expandedKeys };
|
||||
}
|
||||
return { tree: data };
|
||||
return { tree: data, expandedKeys };
|
||||
}
|
||||
|
||||
const LangMap: any = {
|
||||
|
@ -70,6 +85,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
|||
const editorRef = useRef<any>(null);
|
||||
const [isAddFileModalVisible, setIsAddFileModalVisible] = useState(false);
|
||||
const [currentNode, setCurrentNode] = useState<any>();
|
||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
||||
|
||||
const getScripts = () => {
|
||||
setLoading(true);
|
||||
|
@ -132,7 +148,11 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
|||
(e) => {
|
||||
const keyword = e.target.value;
|
||||
setSearchValue(keyword);
|
||||
const { tree } = getFilterData(keyword.toLocaleLowerCase(), data);
|
||||
const { tree, expandedKeys } = getFilterData(
|
||||
keyword.toLocaleLowerCase(),
|
||||
data,
|
||||
);
|
||||
setExpandedKeys(expandedKeys);
|
||||
setFilterData(tree);
|
||||
},
|
||||
[data, setFilterData],
|
||||
|
@ -323,7 +343,6 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
|||
treeData={data}
|
||||
placeholder="请选择脚本文件"
|
||||
showSearch
|
||||
key="value"
|
||||
onSelect={onSelect}
|
||||
/>,
|
||||
<Dropdown overlay={menu} trigger={['click']}>
|
||||
|
|
Loading…
Reference in New Issue
Block a user