develop #31

Merged
uiujun merged 2 commits from develop into main 2026-04-24 13:44:45 +08:00
3 changed files with 30 additions and 24 deletions
Showing only changes of commit f8ef1a94ea - Show all commits

View File

@ -14,10 +14,11 @@ export default defineConfig({
},
proxy: {
'/api/': {
target: 'http://10.39.13.78:8001/',
target: 'http://10.39.13.78:8002/',
// target: 'https://test-admin.linyikj.com.cn/',
// target: 'https://admin.linyikj.com.cn/',
changeOrigin: true,
secure: false,
pathRewrite: { '^': '' },
},
},

View File

@ -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"
}

View File

@ -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 ? (