From 42fd7e123a4018f02bbcc72f8ce1de9e8a8040e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Tue, 4 Apr 2023 12:10:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=BA=BA=E5=91=98=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=9B=B8=E5=85=B3=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/adminroles/compenents/create.tsx | 97 +++++++++++++++---- .../system/adminroles/compenents/update.tsx | 97 +++++++++++++++---- 2 files changed, 160 insertions(+), 34 deletions(-) diff --git a/src/pages/system/adminroles/compenents/create.tsx b/src/pages/system/adminroles/compenents/create.tsx index 329407f..c37e4b5 100644 --- a/src/pages/system/adminroles/compenents/create.tsx +++ b/src/pages/system/adminroles/compenents/create.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { Drawer, Select, Space, Button, Form, Input, message } from "antd"; +import { Drawer, TreeSelect, Space, Button, Form, Input, message } from "antd"; import styles from "./create.module.less"; import { adminRole } from "../../../../api/index"; @@ -8,6 +8,12 @@ interface PropInterface { onCancel: () => void; } +interface Option { + value: string | number; + title: string; + children?: Option[]; +} + export const SystemAdminrolesCreate: React.FC = ({ open, onCancel, @@ -31,20 +37,75 @@ export const SystemAdminrolesCreate: React.FC = ({ const getParams = () => { adminRole.createAdminRole().then((res: any) => { - const arr = []; - const arr2 = []; + const arr: Option[] = [ + { + title: "学员", + value: "学员-n", + children: [], + }, + { + title: "管理员", + value: "管理员-n", + children: [], + }, + ]; + const arr2: Option[] = [ + { + title: "学员", + value: "学员-n", + children: [], + }, + { + title: "管理员", + value: "管理员-n", + children: [], + }, + { + title: "管理员角色", + value: "管理员角色-n", + children: [], + }, + { + title: "线上课", + value: "线上课-n", + children: [], + }, + { + title: "资源", + value: "资源-n", + children: [], + }, + { + title: "资源分类", + value: "资源分类-n", + children: [], + }, + { + title: "部门", + value: "部门-n", + children: [], + }, + ]; let actions = res.data.perm_action.action; let permissions = res.data.perm_action.data; for (let i = 0; i < permissions.length; i++) { - arr.push({ - label: permissions[i].group_name + "-" + permissions[i].name, - value: permissions[i].id, + arr.map((item: any) => { + if (item.title === permissions[i].group_name) { + item.children.push({ + title: permissions[i].name, + value: permissions[i].id, + }); + } }); } for (let j = 0; j < actions.length; j++) { - arr2.push({ - label: actions[j].group_name + "-" + actions[j].name, - value: actions[j].id, + arr2.map((item: any) => { + if (item.title === actions[j].group_name) { + item.children.push({ + title: actions[j].name, + value: actions[j].id, + }); + } }); } setPermissions(arr); @@ -111,21 +172,23 @@ export const SystemAdminrolesCreate: React.FC = ({ /> - diff --git a/src/pages/system/adminroles/compenents/update.tsx b/src/pages/system/adminroles/compenents/update.tsx index 9a2b17c..fd015b1 100644 --- a/src/pages/system/adminroles/compenents/update.tsx +++ b/src/pages/system/adminroles/compenents/update.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { Drawer, Select, Space, Button, Form, Input, message } from "antd"; +import { Drawer, TreeSelect, Space, Button, Form, Input, message } from "antd"; import styles from "./update.module.less"; import { adminRole } from "../../../../api/index"; @@ -9,6 +9,12 @@ interface PropInterface { onCancel: () => void; } +interface Option { + value: string | number; + title: string; + children?: Option[]; +} + export const SystemAdminrolesUpdate: React.FC = ({ id, open, @@ -32,20 +38,75 @@ export const SystemAdminrolesUpdate: React.FC = ({ const getParams = () => { adminRole.createAdminRole().then((res: any) => { - const arr = []; - const arr2 = []; + const arr: Option[] = [ + { + title: "学员", + value: "学员-n", + children: [], + }, + { + title: "管理员", + value: "管理员-n", + children: [], + }, + ]; + const arr2: Option[] = [ + { + title: "学员", + value: "学员-n", + children: [], + }, + { + title: "管理员", + value: "管理员-n", + children: [], + }, + { + title: "管理员角色", + value: "管理员角色-n", + children: [], + }, + { + title: "线上课", + value: "线上课-n", + children: [], + }, + { + title: "资源", + value: "资源-n", + children: [], + }, + { + title: "资源分类", + value: "资源分类-n", + children: [], + }, + { + title: "部门", + value: "部门-n", + children: [], + }, + ]; let actions = res.data.perm_action.action; let permissions = res.data.perm_action.data; for (let i = 0; i < permissions.length; i++) { - arr.push({ - label: permissions[i].group_name + "-" + permissions[i].name, - value: permissions[i].id, + arr.map((item: any) => { + if (item.title === permissions[i].group_name) { + item.children.push({ + title: permissions[i].name, + value: permissions[i].id, + }); + } }); } for (let j = 0; j < actions.length; j++) { - arr2.push({ - label: actions[j].group_name + "-" + actions[j].name, - value: actions[j].id, + arr2.map((item: any) => { + if (item.title === actions[j].group_name) { + item.children.push({ + title: actions[j].name, + value: actions[j].id, + }); + } }); } setPermissions(arr); @@ -120,21 +181,23 @@ export const SystemAdminrolesUpdate: React.FC = ({ -