管理人员角色相关重构

This commit is contained in:
禺狨 2023-04-04 12:10:06 +08:00
parent 7f58a02f6f
commit 42fd7e123a
2 changed files with 160 additions and 34 deletions

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react"; 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 styles from "./create.module.less";
import { adminRole } from "../../../../api/index"; import { adminRole } from "../../../../api/index";
@ -8,6 +8,12 @@ interface PropInterface {
onCancel: () => void; onCancel: () => void;
} }
interface Option {
value: string | number;
title: string;
children?: Option[];
}
export const SystemAdminrolesCreate: React.FC<PropInterface> = ({ export const SystemAdminrolesCreate: React.FC<PropInterface> = ({
open, open,
onCancel, onCancel,
@ -31,22 +37,77 @@ export const SystemAdminrolesCreate: React.FC<PropInterface> = ({
const getParams = () => { const getParams = () => {
adminRole.createAdminRole().then((res: any) => { adminRole.createAdminRole().then((res: any) => {
const arr = []; const arr: Option[] = [
const arr2 = []; {
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 actions = res.data.perm_action.action;
let permissions = res.data.perm_action.data; let permissions = res.data.perm_action.data;
for (let i = 0; i < permissions.length; i++) { for (let i = 0; i < permissions.length; i++) {
arr.push({ arr.map((item: any) => {
label: permissions[i].group_name + "-" + permissions[i].name, if (item.title === permissions[i].group_name) {
item.children.push({
title: permissions[i].name,
value: permissions[i].id, value: permissions[i].id,
}); });
} }
});
}
for (let j = 0; j < actions.length; j++) { for (let j = 0; j < actions.length; j++) {
arr2.push({ arr2.map((item: any) => {
label: actions[j].group_name + "-" + actions[j].name, if (item.title === actions[j].group_name) {
item.children.push({
title: actions[j].name,
value: actions[j].id, value: actions[j].id,
}); });
} }
});
}
setPermissions(arr); setPermissions(arr);
setActions(arr2); setActions(arr2);
}); });
@ -111,21 +172,23 @@ export const SystemAdminrolesCreate: React.FC<PropInterface> = ({
/> />
</Form.Item> </Form.Item>
<Form.Item label="操作权限" name="action_ids"> <Form.Item label="操作权限" name="action_ids">
<Select <TreeSelect
style={{ width: 424 }} style={{ width: 424 }}
mode="multiple" treeCheckable={true}
allowClear
placeholder="请选择权限" placeholder="请选择权限"
options={actions} multiple
allowClear
treeData={actions}
/> />
</Form.Item> </Form.Item>
<Form.Item label="数据权限" name="permission_ids"> <Form.Item label="数据权限" name="permission_ids">
<Select <TreeSelect
style={{ width: 424 }} style={{ width: 424 }}
mode="multiple" treeCheckable={true}
allowClear
placeholder="请选择权限" placeholder="请选择权限"
options={permissions} multiple
allowClear
treeData={permissions}
/> />
</Form.Item> </Form.Item>
</Form> </Form>

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react"; 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 styles from "./update.module.less";
import { adminRole } from "../../../../api/index"; import { adminRole } from "../../../../api/index";
@ -9,6 +9,12 @@ interface PropInterface {
onCancel: () => void; onCancel: () => void;
} }
interface Option {
value: string | number;
title: string;
children?: Option[];
}
export const SystemAdminrolesUpdate: React.FC<PropInterface> = ({ export const SystemAdminrolesUpdate: React.FC<PropInterface> = ({
id, id,
open, open,
@ -32,22 +38,77 @@ export const SystemAdminrolesUpdate: React.FC<PropInterface> = ({
const getParams = () => { const getParams = () => {
adminRole.createAdminRole().then((res: any) => { adminRole.createAdminRole().then((res: any) => {
const arr = []; const arr: Option[] = [
const arr2 = []; {
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 actions = res.data.perm_action.action;
let permissions = res.data.perm_action.data; let permissions = res.data.perm_action.data;
for (let i = 0; i < permissions.length; i++) { for (let i = 0; i < permissions.length; i++) {
arr.push({ arr.map((item: any) => {
label: permissions[i].group_name + "-" + permissions[i].name, if (item.title === permissions[i].group_name) {
item.children.push({
title: permissions[i].name,
value: permissions[i].id, value: permissions[i].id,
}); });
} }
});
}
for (let j = 0; j < actions.length; j++) { for (let j = 0; j < actions.length; j++) {
arr2.push({ arr2.map((item: any) => {
label: actions[j].group_name + "-" + actions[j].name, if (item.title === actions[j].group_name) {
item.children.push({
title: actions[j].name,
value: actions[j].id, value: actions[j].id,
}); });
} }
});
}
setPermissions(arr); setPermissions(arr);
setActions(arr2); setActions(arr2);
}); });
@ -120,21 +181,23 @@ export const SystemAdminrolesUpdate: React.FC<PropInterface> = ({
<Input style={{ width: 424 }} placeholder="请输入角色名" /> <Input style={{ width: 424 }} placeholder="请输入角色名" />
</Form.Item> </Form.Item>
<Form.Item label="操作权限" name="action_ids"> <Form.Item label="操作权限" name="action_ids">
<Select <TreeSelect
style={{ width: 424 }} style={{ width: 424 }}
mode="multiple" treeCheckable={true}
allowClear
placeholder="请选择权限" placeholder="请选择权限"
options={actions} multiple
allowClear
treeData={actions}
/> />
</Form.Item> </Form.Item>
<Form.Item label="数据权限" name="permission_ids"> <Form.Item label="数据权限" name="permission_ids">
<Select <TreeSelect
style={{ width: 424 }} style={{ width: 424 }}
mode="multiple" treeCheckable={true}
allowClear
placeholder="请选择权限" placeholder="请选择权限"
options={permissions} multiple
allowClear
treeData={permissions}
/> />
</Form.Item> </Form.Item>
</Form> </Form>