From f8ef1a94eaa94b6fd45841e5bf79511c4d9c03f7 Mon Sep 17 00:00:00 2001 From: uiujun Date: Wed, 22 Apr 2026 14:58:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .umirc.ts | 3 +- gencode.json | 2 +- src/pages/company/list/table/Roles.tsx | 49 ++++++++++++++------------ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.umirc.ts b/.umirc.ts index 1caa088..03f738c 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -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: { '^': '' }, }, }, diff --git a/gencode.json b/gencode.json index b5fb778..f38b7d9 100644 --- a/gencode.json +++ b/gencode.json @@ -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" } diff --git a/src/pages/company/list/table/Roles.tsx b/src/pages/company/list/table/Roles.tsx index 52b272a..186ce3f 100644 --- a/src/pages/company/list/table/Roles.tsx +++ b/src/pages/company/list/table/Roles.tsx @@ -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([]); - const [checkedKeys, setCheckedKeys] = useState([]); - const [guardName, setGuardName] = useState('Company'); - const [getSysModuleEnum, setSysModuleEnum] = useState({}); + const [checkedKeys, setCheckedKeys] = useState([]); 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 ? (