From 3f29132a80d699736efa99ff321f8fd399c14f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Tue, 7 Mar 2023 10:49:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E7=AE=A1=E7=90=86=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/department.ts | 2 +- src/pages/department/index.tsx | 49 +++++++++++++--- src/pages/member/index.tsx | 102 ++++++++++++++++----------------- 3 files changed, 92 insertions(+), 61 deletions(-) diff --git a/src/api/department.ts b/src/api/department.ts index e78e5e8..2850091 100644 --- a/src/api/department.ts +++ b/src/api/department.ts @@ -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, diff --git a/src/pages/department/index.tsx b/src/pages/department/index.tsx index 9f7dd66..e2970d6 100644 --- a/src/pages/department/index.tsx +++ b/src/pages/department/index.tsx @@ -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 = [ + { + title: "部门名", + dataIndex: "name", + render: (text: string) => {text}, + }, { title: "ID", key: "id", dataIndex: "id", }, - { - title: "角色名", - dataIndex: "name", - render: (text: string) => {text}, - }, { 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); diff --git a/src/pages/member/index.tsx b/src/pages/member/index.tsx index 545fa83..4ffa0b7 100644 --- a/src/pages/member/index.tsx +++ b/src/pages/member/index.tsx @@ -171,59 +171,59 @@ export const MemberPage: React.FC = () => { return ( <> -
-
-
- 昵称: - { - setNickname(e.target.value); - }} - style={{ width: 160 }} - placeholder="请输入昵称" - /> -
-
- 邮箱: - { - setEmail(e.target.value); - }} - style={{ width: 160 }} - placeholder="请输入邮箱" - /> -
-
- 身份证号: - { - setIdCard(e.target.value); - }} - style={{ width: 160 }} - placeholder="请输入身份证号" - /> -
-
- - -
-
-
+
+
+
+ 昵称: + { + setNickname(e.target.value); + }} + style={{ width: 160 }} + placeholder="请输入昵称" + /> +
+
+ 邮箱: + { + setEmail(e.target.value); + }} + style={{ width: 160 }} + placeholder="请输入邮箱" + /> +
+
+ 身份证号: + { + setIdCard(e.target.value); + }} + style={{ width: 160 }} + placeholder="请输入身份证号" + /> +
+
+ + +
+
+