|
@@ -1,42 +1,65 @@
|
|
|
-import { Modal, Tree } from 'antd';
|
|
|
|
|
|
|
+import { onlyMessage } from '@/utils/util';
|
|
|
|
|
+import { Modal, Tree, Select } from 'antd';
|
|
|
import { useEffect, useState } from 'react';
|
|
import { useEffect, useState } from 'react';
|
|
|
import { service } from '../index';
|
|
import { service } from '../index';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
close: Function;
|
|
close: Function;
|
|
|
- data: string;
|
|
|
|
|
|
|
+ data: any;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const MenuPage = (props: Props) => {
|
|
const MenuPage = (props: Props) => {
|
|
|
- const [treeData, setTreeData] = useState<undefined | any[]>(undefined);
|
|
|
|
|
|
|
+ const { data } = props;
|
|
|
|
|
+ const { Option } = Select;
|
|
|
|
|
+ const [treeData, setTreeData] = useState<any[]>([]);
|
|
|
const [keys, setKeys] = useState<any>([]);
|
|
const [keys, setKeys] = useState<any>([]);
|
|
|
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
|
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
|
|
|
|
+ const [half, setHalf] = useState<string[]>([]);
|
|
|
|
|
+ const [owner, setOwner] = useState<string>('iot');
|
|
|
|
|
+ const [ownerList, setOwenrList] = useState<any>([]);
|
|
|
|
|
+ // const [menu,setMenu] = useState<string>('')
|
|
|
|
|
|
|
|
const getTree = async () => {
|
|
const getTree = async () => {
|
|
|
const res = await service.queryOwner(['iot']);
|
|
const res = await service.queryOwner(['iot']);
|
|
|
if (res.status === 200) {
|
|
if (res.status === 200) {
|
|
|
|
|
+ if (data.provider !== 'internal-standalone') {
|
|
|
|
|
+ setOwner(res.result?.[0]);
|
|
|
|
|
+ setOwenrList(res.result);
|
|
|
|
|
+ }
|
|
|
const resp = await service.queryOwnerTree(res.result?.[0]);
|
|
const resp = await service.queryOwnerTree(res.result?.[0]);
|
|
|
if (resp.status === 200) {
|
|
if (resp.status === 200) {
|
|
|
setTreeData(resp.result);
|
|
setTreeData(resp.result);
|
|
|
- // console.log(resp.result)
|
|
|
|
|
|
|
+ const pid = resp.result.map((item: any) => item.id);
|
|
|
|
|
+ setExpandedKeys(pid);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // const filterTree = (tree:any[],parms: any[]) => {
|
|
|
|
|
- // return tree.filter(item=>{
|
|
|
|
|
- // console.log(item)
|
|
|
|
|
- // return parms?.indexOf(item.id) > -1
|
|
|
|
|
- // }).map(i=>{
|
|
|
|
|
- // i = Object.assign({},i)
|
|
|
|
|
- // if(i.children){
|
|
|
|
|
- // i.children = filterTree(i.children,parms)
|
|
|
|
|
- // }
|
|
|
|
|
- // return i
|
|
|
|
|
- // })
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ const save = async (datalist: any) => {
|
|
|
|
|
+ const res = await service.saveOwnerTree(owner, data.id, datalist);
|
|
|
|
|
+ if (res?.status === 200) {
|
|
|
|
|
+ onlyMessage('操作成功');
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ //过滤节点-默认带上父节点
|
|
|
|
|
+ const filterTree = (nodes: any[], list: any[]) => {
|
|
|
|
|
+ if (!nodes?.length) {
|
|
|
|
|
+ return nodes;
|
|
|
|
|
+ }
|
|
|
|
|
+ return nodes.filter((it) => {
|
|
|
|
|
+ // 不符合条件的直接砍掉
|
|
|
|
|
+ if (list.indexOf(it.id) <= -1) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 符合条件的保留,并且需要递归处理其子节点
|
|
|
|
|
+ it.children = filterTree(it.children, list);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ console.log(data);
|
|
|
getTree();
|
|
getTree();
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
@@ -45,31 +68,41 @@ const MenuPage = (props: Props) => {
|
|
|
visible
|
|
visible
|
|
|
maskClosable={false}
|
|
maskClosable={false}
|
|
|
title="集成菜单"
|
|
title="集成菜单"
|
|
|
- width={800}
|
|
|
|
|
|
|
+ width={600}
|
|
|
onCancel={() => {
|
|
onCancel={() => {
|
|
|
props.close();
|
|
props.close();
|
|
|
}}
|
|
}}
|
|
|
onOk={() => {
|
|
onOk={() => {
|
|
|
- // if(treeData && treeData.length!==0){
|
|
|
|
|
- // const item = filterTree(treeData,keys.checked)
|
|
|
|
|
- // console.log(item)
|
|
|
|
|
- // }
|
|
|
|
|
- // console.log(keys)
|
|
|
|
|
|
|
+ const items = filterTree(treeData, [...keys, ...half]);
|
|
|
|
|
+ if (items && items.length !== 0) {
|
|
|
|
|
+ save(items);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ onlyMessage('请勾选配置菜单', 'warning');
|
|
|
|
|
+ }
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
|
|
+ <Select
|
|
|
|
|
+ style={{ width: 200, marginBottom: 20 }}
|
|
|
|
|
+ placeholder="请选择集成系统"
|
|
|
|
|
+ defaultValue={owner}
|
|
|
|
|
+ >
|
|
|
|
|
+ {ownerList.map((item: any) => (
|
|
|
|
|
+ <Option value={item}>{item}</Option>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </Select>
|
|
|
<Tree
|
|
<Tree
|
|
|
fieldNames={{
|
|
fieldNames={{
|
|
|
title: 'name',
|
|
title: 'name',
|
|
|
key: 'id',
|
|
key: 'id',
|
|
|
}}
|
|
}}
|
|
|
checkable
|
|
checkable
|
|
|
- // checkStrictly={true}
|
|
|
|
|
treeData={treeData}
|
|
treeData={treeData}
|
|
|
checkedKeys={keys}
|
|
checkedKeys={keys}
|
|
|
autoExpandParent={true}
|
|
autoExpandParent={true}
|
|
|
- onCheck={(_keys: any, e) => {
|
|
|
|
|
|
|
+ onCheck={(_keys: any, e: any) => {
|
|
|
console.log(e);
|
|
console.log(e);
|
|
|
setKeys(_keys);
|
|
setKeys(_keys);
|
|
|
|
|
+ setHalf(e.halfCheckedKeys);
|
|
|
}}
|
|
}}
|
|
|
expandedKeys={expandedKeys}
|
|
expandedKeys={expandedKeys}
|
|
|
onExpand={(_keys: any[]) => {
|
|
onExpand={(_keys: any[]) => {
|