Compare commits
No commits in common. "ea62ddf501c27c40b32c4cf18a8fb83d8f12bda9" and "6a443be27bf44dc46598037bb1ace11df6a09675" have entirely different histories.
ea62ddf501
...
6a443be27b
@ -14,11 +14,10 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api/': {
|
'/api/': {
|
||||||
target: 'http://10.39.13.78:8002/',
|
// target: 'http://10.39.13.78:8002/',
|
||||||
// target: 'https://test-admin.linyikj.com.cn/',
|
// target: 'https://test-admin.linyikj.com.cn/',
|
||||||
// target: 'https://admin.linyikj.com.cn/',
|
target: 'https://admin.linyikj.com.cn/',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
|
||||||
pathRewrite: { '^': '' },
|
pathRewrite: { '^': '' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"url": "http://10.39.13.78:8002/api/docs/openapi",
|
"url": "http://10.39.13.78:8001/api/docs/openapi",
|
||||||
"module": "Admin"
|
"module": "Admin"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { MyBetaModalFormProps, MyButtons } from '@/common';
|
import { MyBetaModalFormProps, MyButtons } from '@/common';
|
||||||
import { Apis } from '@/gen/Apis';
|
import { Apis } from '@/gen/Apis';
|
||||||
|
import { SysModuleEnum } from '@/gen/Enums';
|
||||||
import { ProCard } from '@ant-design/pro-components';
|
import { ProCard } from '@ant-design/pro-components';
|
||||||
import { message, Space, Tree, TreeProps } from 'antd';
|
import { message, Space, Tree, TreeProps } from 'antd';
|
||||||
import { DataNode } from 'antd/es/tree';
|
import { DataNode } from 'antd/es/tree';
|
||||||
@ -7,7 +8,9 @@ import { useEffect, useState } from 'react';
|
|||||||
|
|
||||||
export default function Index(props: MyBetaModalFormProps) {
|
export default function Index(props: MyBetaModalFormProps) {
|
||||||
const [treeData, setTreeData] = useState<DataNode[]>([]);
|
const [treeData, setTreeData] = useState<DataNode[]>([]);
|
||||||
const [checkedKeys, setCheckedKeys] = useState<React.Key[]>([]);
|
const [checkedKeys, setCheckedKeys] = useState<string[]>([]);
|
||||||
|
const [guardName, setGuardName] = useState<string>('Company');
|
||||||
|
const [getSysModuleEnum, setSysModuleEnum] = useState<any>({});
|
||||||
const processTree = (item: any): DataNode => {
|
const processTree = (item: any): DataNode => {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
@ -17,33 +20,13 @@ export default function Index(props: MyBetaModalFormProps) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// 提取所有叶子节点的 key,用于过滤 checkedKeys
|
const getPermissions = () => {
|
||||||
const getLeafKeys = (nodes: DataNode[]): React.Key[] => {
|
|
||||||
const keys: React.Key[] = [];
|
|
||||||
const traverse = (node: DataNode) => {
|
|
||||||
if (!node.children || node.children.length === 0) {
|
|
||||||
keys.push(node.key);
|
|
||||||
} else {
|
|
||||||
node.children.forEach(traverse);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
nodes.forEach(traverse);
|
|
||||||
return keys;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getPermissions = (data: DataNode[]) => {
|
|
||||||
//获取已经配置的,菜单
|
//获取已经配置的,菜单
|
||||||
Apis.Company.CompanyPermissions.GetPermissions({
|
Apis.Company.CompanyPermissions.GetPermissions({
|
||||||
companies_id: props?.item?.id || 0,
|
companies_id: props?.item?.id || 0,
|
||||||
}).then((res: any) => {
|
}).then((res: any) => {
|
||||||
const leafKeys = getLeafKeys(data);
|
console.log('res', res);
|
||||||
const leafKeySet = new Set(leafKeys.map(String));
|
setCheckedKeys(res?.data?.permissions_ids);
|
||||||
const ids = res?.data?.permissions_ids || [];
|
|
||||||
// 只保留叶子节点的 key,避免父节点 key 导致 Tree 全选
|
|
||||||
const filteredKeys = ids.filter((id: React.Key) =>
|
|
||||||
leafKeySet.has(String(id)),
|
|
||||||
);
|
|
||||||
setCheckedKeys(filteredKeys);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,16 +35,28 @@ export default function Index(props: MyBetaModalFormProps) {
|
|||||||
Apis.Company.CompanyPermissions.PermissionTree().then((res: any) => {
|
Apis.Company.CompanyPermissions.PermissionTree().then((res: any) => {
|
||||||
const data = res.data?.map(processTree);
|
const data = res.data?.map(processTree);
|
||||||
setTreeData(data);
|
setTreeData(data);
|
||||||
getPermissions(data);
|
getPermissions();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let obj = JSON.parse(JSON.stringify(SysModuleEnum));
|
||||||
|
delete obj.Admin;
|
||||||
|
setSysModuleEnum(obj);
|
||||||
getPermissionTree();
|
getPermissionTree();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onCheck: TreeProps['onCheck'] = (checkedKeysValue) => {
|
const onCheck: TreeProps['onCheck'] = (checkedKeys, info) => {
|
||||||
setCheckedKeys(checkedKeysValue as React.Key[]);
|
console.log('onCheck', checkedKeys, info);
|
||||||
|
const ids: string[] = [];
|
||||||
|
info.checkedNodes?.forEach((item: DataNode) => {
|
||||||
|
if (item.children?.length === 0) {
|
||||||
|
ids.push(item.key as string);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log('ids', ids);
|
||||||
|
setCheckedKeys(ids);
|
||||||
|
// props.onChange?.(ids);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (treeData?.length ?? 0) > 0 ? (
|
return (treeData?.length ?? 0) > 0 ? (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user