From e7ed56cce6c7a958564598b9c1fdaa7085acf5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Mon, 6 Mar 2023 17:18:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=A7=92=E8=89=B2=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=88=97=E8=A1=A8=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin-role.ts | 2 +- src/pages/index.ts | 1 + src/pages/system/administrator/index.tsx | 6 +- src/pages/system/adminroles/index.module.less | 0 src/pages/system/adminroles/index.tsx | 147 ++++++++++++++++++ src/router/routes.tsx | 5 + 6 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 src/pages/system/adminroles/index.module.less create mode 100644 src/pages/system/adminroles/index.tsx diff --git a/src/api/admin-role.ts b/src/api/admin-role.ts index d5c0e65..3ecaa1f 100644 --- a/src/api/admin-role.ts +++ b/src/api/admin-role.ts @@ -24,7 +24,7 @@ export function updateAdminRole( name: string, permissionIds: number[] ) { - return client.post(`/backend/v1/admin-role/${id}`, { + return client.put(`/backend/v1/admin-role/${id}`, { name: name, permission_ids: permissionIds, }); diff --git a/src/pages/index.ts b/src/pages/index.ts index ffdbb7a..9095f95 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -10,3 +10,4 @@ export * from "./member/update" export * from "./system/administrator/index" export * from "./system/administrator/create" export * from "./system/administrator/update" +export * from "./system/adminroles/index" diff --git a/src/pages/system/administrator/index.tsx b/src/pages/system/administrator/index.tsx index 0dbe42f..33336f9 100644 --- a/src/pages/system/administrator/index.tsx +++ b/src/pages/system/administrator/index.tsx @@ -79,13 +79,15 @@ export const SystemAdministratorPage: React.FC = () => { type="link" danger className="c-red" - onClick={() => navigate(`/system/administrator/update/${record.id}`)} + onClick={() => + navigate(`/system/administrator/update/${record.id}`) + } > 详情 delUser(record.id)} okText="确定" cancelText="取消" diff --git a/src/pages/system/adminroles/index.module.less b/src/pages/system/adminroles/index.module.less new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/system/adminroles/index.tsx b/src/pages/system/adminroles/index.tsx new file mode 100644 index 0000000..608dfab --- /dev/null +++ b/src/pages/system/adminroles/index.tsx @@ -0,0 +1,147 @@ +import React, { useState, useEffect } from "react"; +import { + Typography, + Input, + Select, + 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 { dateFormat } from "../../../utils/index"; +import { Link, useNavigate } from "react-router-dom"; + +interface DataType { + id: React.Key; + name: string; + slug: string; + created_at: string; +} + +export const SystemAdminrolesPage: React.FC = () => { + const navigate = useNavigate(); + const [loading, setLoading] = useState(true); + const [list, setList] = useState([]); + const [refresh, setRefresh] = useState(false); + + const columns: ColumnsType = [ + { + title: "ID", + key: "id", + dataIndex: "id", + }, + { + title: "角色名", + dataIndex: "name", + render: (text: string) => {text}, + }, + { + title: "Slug", + dataIndex: "slug", + }, + { + title: "时间", + dataIndex: "created_at", + render: (text: string) => {text && dateFormat(text)}, + }, + { + title: "操作", + key: "action", + fixed: "right", + width: 160, + render: (_, record) => ( + + + delUser(record.id)} + okText="确定" + cancelText="取消" + > + + + + ), + }, + ]; + + useEffect(() => { + getData(); + }, [refresh]); + + const getData = () => { + setLoading(true); + adminRole.adminRoleList().then((res: any) => { + setList(res.data); + setTimeout(() => { + setLoading(false); + }, 1000); + }); + }; + + const resetData = () => { + setList([]); + setRefresh(!refresh); + }; + + const delUser = (id: any) => { + adminRole.destroyAdminRole(id).then((res: any) => { + setTimeout(() => { + message.success("操作成功"); + setRefresh(!refresh); + }, 1000); + }); + }; + + return ( + <> +
+
+
+ + + +
+
+ +
+
+
+ record.id} + /> + + + + ); +}; diff --git a/src/router/routes.tsx b/src/router/routes.tsx index 370fe0a..f00ef8e 100644 --- a/src/router/routes.tsx +++ b/src/router/routes.tsx @@ -12,6 +12,7 @@ import { SystemAdministratorPage, AdministratorCreatePage, AdministratorUpdatePage, + SystemAdminrolesPage, } from "../pages"; const routes: RouteObject[] = [ @@ -51,6 +52,10 @@ const routes: RouteObject[] = [ path: "/system/administrator/update/:userId", element: , }, + { + path: "/system/adminroles", + element: , + }, ], }, {