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