部门管理部门列表

This commit is contained in:
禺狨 2023-03-07 10:49:31 +08:00
parent 872ce3e5e9
commit 3f29132a80
3 changed files with 92 additions and 61 deletions

View File

@ -26,7 +26,7 @@ export function updateDepartment(
parentId: number,
sort: number
) {
return client.post(`/backend/v1/department/${id}`, {
return client.put(`/backend/v1/department/${id}`, {
name,
parent_id: parentId,
sort,

View File

@ -3,10 +3,17 @@ import { Button, Space, Table, Popconfirm, message } from "antd";
import type { ColumnsType } from "antd/es/table";
import styles from "./index.module.less";
import { PlusOutlined, ReloadOutlined } from "@ant-design/icons";
import { adminRole } from "../../api/index";
import { department } from "../../api/index";
import { dateFormat } from "../../utils/index";
import { Link, useNavigate } from "react-router-dom";
interface Option {
id: string | number;
name: string;
created_at: string;
children?: Option[];
}
interface DataType {
id: React.Key;
name: string;
@ -20,16 +27,16 @@ export const DepartmentPage: React.FC = () => {
const [refresh, setRefresh] = useState(false);
const columns: ColumnsType<DataType> = [
{
title: "部门名",
dataIndex: "name",
render: (text: string) => <span>{text}</span>,
},
{
title: "ID",
key: "id",
dataIndex: "id",
},
{
title: "角色名",
dataIndex: "name",
render: (text: string) => <span>{text}</span>,
},
{
title: "时间",
dataIndex: "created_at",
@ -72,21 +79,45 @@ export const DepartmentPage: React.FC = () => {
const getData = () => {
setLoading(true);
adminRole.adminRoleList().then((res: any) => {
setList(res.data);
department.departmentList().then((res: any) => {
const departments = res.data.departments;
const new_arr: Option[] = checkArr(departments, 0);
setList(new_arr);
setTimeout(() => {
setLoading(false);
}, 1000);
});
};
const checkArr = (departments: any[], id: number) => {
const arr = [];
for (let i = 0; i < departments[id].length; i++) {
if (!departments[departments[id][i].id]) {
arr.push({
name: departments[id][i].name,
id: departments[id][i].id,
created_at: departments[id][i].created_at,
});
} else {
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
arr.push({
name: departments[id][i].name,
id: departments[id][i].id,
created_at: departments[id][i].created_at,
children: new_arr,
});
}
}
return arr;
};
const resetData = () => {
setList([]);
setRefresh(!refresh);
};
const delUser = (id: any) => {
adminRole.destroyAdminRole(id).then((res: any) => {
department.destroyDepartment(id).then((res: any) => {
setTimeout(() => {
message.success("操作成功");
setRefresh(!refresh);

View File

@ -171,59 +171,59 @@ export const MemberPage: React.FC = () => {
return (
<>
<Row>
<div className="playedu-main-body mb-24">
<div className="float-left d-flex">
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={nickname}
onChange={(e) => {
setNickname(e.target.value);
}}
style={{ width: 160 }}
placeholder="请输入昵称"
/>
</div>
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={email}
onChange={(e) => {
setEmail(e.target.value);
}}
style={{ width: 160 }}
placeholder="请输入邮箱"
/>
</div>
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={id_card}
onChange={(e) => {
setIdCard(e.target.value);
}}
style={{ width: 160 }}
placeholder="请输入身份证号"
/>
</div>
<div className="d-flex mr-24">
<Button className="mr-16" onClick={resetData}>
</Button>
<Button
type="primary"
onClick={() => {
setPage(1);
setRefresh(!refresh);
}}
>
</Button>
</div>
</div>
</div>
<Col span={4}></Col>
<Col span={20}>
<div className="playedu-main-body mb-24">
<div className="float-left d-flex">
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={nickname}
onChange={(e) => {
setNickname(e.target.value);
}}
style={{ width: 160 }}
placeholder="请输入昵称"
/>
</div>
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={email}
onChange={(e) => {
setEmail(e.target.value);
}}
style={{ width: 160 }}
placeholder="请输入邮箱"
/>
</div>
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={id_card}
onChange={(e) => {
setIdCard(e.target.value);
}}
style={{ width: 160 }}
placeholder="请输入身份证号"
/>
</div>
<div className="d-flex mr-24">
<Button className="mr-16" onClick={resetData}>
</Button>
<Button
type="primary"
onClick={() => {
setPage(1);
setRefresh(!refresh);
}}
>
</Button>
</div>
</div>
</div>
<div className="playedu-main-body">
<div className="float-left j-b-flex mb-24">
<div className="d-flex">