超级管理员角色不显示角色权限和角色删除按钮

This commit is contained in:
禺狨 2023-06-13 09:30:18 +08:00
parent 69b87930da
commit 097cbe6b63
2 changed files with 16 additions and 4 deletions

View File

@ -13,13 +13,14 @@ interface PropInterface {
roleDelSuccess: boolean; roleDelSuccess: boolean;
type: string; type: string;
text: string; text: string;
onUpdate: (keys: any, title: any) => void; onUpdate: (keys: any, title: any, isSuper: boolean) => void;
} }
export const TreeAdminroles = (props: PropInterface) => { export const TreeAdminroles = (props: PropInterface) => {
const [treeData, setTreeData] = useState<any>([]); const [treeData, setTreeData] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<any>([]); const [selectKey, setSelectKey] = useState<any>([]);
const [superId, setSuperId] = useState(0);
useEffect(() => { useEffect(() => {
onSelect([], ""); onSelect([], "");
@ -28,6 +29,7 @@ export const TreeAdminroles = (props: PropInterface) => {
useEffect(() => { useEffect(() => {
adminRole.adminRoleList().then((res: any) => { adminRole.adminRoleList().then((res: any) => {
let adminrole = res.data; let adminrole = res.data;
let superId = 0;
if (adminrole.length > 0) { if (adminrole.length > 0) {
const new_arr: Option[] = []; const new_arr: Option[] = [];
for (let i = 0; i < adminrole.length; i++) { for (let i = 0; i < adminrole.length; i++) {
@ -36,9 +38,13 @@ export const TreeAdminroles = (props: PropInterface) => {
key: adminrole[i].id, key: adminrole[i].id,
children: [], children: [],
}); });
if (adminrole[i].slug === "super-role") {
superId = adminrole[i].id;
}
} }
setTreeData(new_arr); setTreeData(new_arr);
} }
setSuperId(superId);
}); });
}, [props.refresh]); }, [props.refresh]);
@ -47,7 +53,11 @@ export const TreeAdminroles = (props: PropInterface) => {
if (info) { if (info) {
label = info.node.title; label = info.node.title;
} }
props.onUpdate(selectedKeys, label); let isSuper = false;
if (selectedKeys[0] === superId && superId !== 0) {
isSuper = true;
}
props.onUpdate(selectedKeys, label, isSuper);
setSelectKey(selectedKeys); setSelectKey(selectedKeys);
}; };

View File

@ -40,6 +40,7 @@ const SystemAdministratorPage = () => {
const [role_ids, setRoleIds] = useState<any>([]); const [role_ids, setRoleIds] = useState<any>([]);
const [selLabel, setLabel] = useState<string>("全部管理员"); const [selLabel, setLabel] = useState<string>("全部管理员");
const [roleDelSuccess, setRoleDelSuccess] = useState(false); const [roleDelSuccess, setRoleDelSuccess] = useState(false);
const [isSuper, setIsSuper] = useState(false);
const [name, setName] = useState<string>(""); const [name, setName] = useState<string>("");
@ -216,9 +217,10 @@ const SystemAdministratorPage = () => {
refresh={refresh} refresh={refresh}
type="" type=""
text={"管理员"} text={"管理员"}
onUpdate={(keys: any, title: any) => { onUpdate={(keys: any, title: any, isSuper: boolean) => {
setRoleIds(keys); setRoleIds(keys);
setLabel(title); setLabel(title);
setIsSuper(isSuper);
}} }}
/> />
</div> </div>
@ -248,7 +250,7 @@ const SystemAdministratorPage = () => {
disabled={null} disabled={null}
/> />
)} )}
{role_ids.length > 0 && ( {!isSuper && role_ids.length > 0 && (
<> <>
<PerButton <PerButton
text="角色权限" text="角色权限"