点击任务名跳转脚本管理编辑脚本 (#929)

* 增加捷径:点击任务名跳转脚本管理编辑脚本

* 修正树节点选中,父节点自动展开
This commit is contained in:
kilo5hz
2021-11-19 22:42:11 +08:00
committed by whyour
parent 417ae8bbde
commit 5e94be21aa
3 changed files with 64 additions and 3 deletions
+36 -2
View File
@@ -31,6 +31,8 @@ import {
UserOutlined,
} from '@ant-design/icons';
import EditScriptNameModal from './editNameModal';
import debounce from 'lodash/debounce';
import { history } from 'umi';
const { Text } = Typography;
@@ -95,7 +97,10 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
setData(data.data);
setFilterData(data.data);
})
.finally(() => setLoading(false));
.finally(() => {
setLoading(false);
initGetScript();
});
};
const getDetail = (node: any) => {
@@ -106,6 +111,22 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
});
};
const initGetScript = () => {
const { p, s } = history.location.query as any;
if (s) {
const obj = {
node: {
title: s,
value: s,
key: p ? `${p}-${s}` : s,
parent: p,
},
};
setExpandedKeys([p]);
onTreeSelect([`${p}-${s}`], obj);
}
};
const onSelect = (value: any, node: any) => {
if (node.key === select || !value) {
return;
@@ -119,6 +140,10 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
getDetail(node);
};
const onExpand = (expKeys: any) => {
setExpandedKeys(expKeys);
};
const onTreeSelect = useCallback(
(keys: Key[], e: any) => {
const content = editorRef.current
@@ -147,6 +172,13 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
const onSearch = useCallback(
(e) => {
const keyword = e.target.value;
debounceSearch(keyword);
},
[data, setFilterData],
);
const debounceSearch = useCallback(
debounce((keyword) => {
setSearchValue(keyword);
const { tree, expandedKeys } = getFilterData(
keyword.toLocaleLowerCase(),
@@ -154,7 +186,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
);
setExpandedKeys(expandedKeys);
setFilterData(tree);
},
}, 300),
[data, setFilterData],
);
@@ -451,6 +483,8 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
showIcon={true}
height={height}
selectedKeys={[select]}
expandedKeys={expandedKeys}
onExpand={onExpand}
showLine={{ showLeafIcon: true }}
onSelect={onTreeSelect}
></Tree>