From 5ae4897c0a76029105e4ae1f8b31351f354654c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Tue, 14 Mar 2023 18:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E6=96=B0=E5=BB=BA=E3=80=81=E7=BC=96=E8=BE=91=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E7=BB=84=E4=BB=B6=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index.ts | 2 - .../{ => compenents}/create.module.less | 0 .../administrator/compenents/create.tsx | 145 ++++++++++++++ .../{ => compenents}/update.module.less | 0 .../administrator/compenents/update.tsx | 162 ++++++++++++++++ src/pages/system/administrator/create.tsx | 141 -------------- src/pages/system/administrator/index.tsx | 183 +++++++++--------- src/pages/system/administrator/update.tsx | 158 --------------- .../system/adminroles/compenents/create.tsx | 12 +- .../system/adminroles/compenents/update.tsx | 14 +- src/pages/system/adminroles/index.tsx | 107 +++++----- src/router/routes.tsx | 10 - 12 files changed, 482 insertions(+), 452 deletions(-) rename src/pages/system/administrator/{ => compenents}/create.module.less (100%) create mode 100644 src/pages/system/administrator/compenents/create.tsx rename src/pages/system/administrator/{ => compenents}/update.module.less (100%) create mode 100644 src/pages/system/administrator/compenents/update.tsx delete mode 100644 src/pages/system/administrator/create.tsx delete mode 100644 src/pages/system/administrator/update.tsx diff --git a/src/pages/index.ts b/src/pages/index.ts index 6e4d412..98d884a 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -12,8 +12,6 @@ export * from "./member/update"; export * from "./member/import"; export * from "./system/index"; export * from "./system/administrator/index"; -export * from "./system/administrator/create"; -export * from "./system/administrator/update"; export * from "./system/adminroles/index"; export * from "./department"; export * from "./change-password"; diff --git a/src/pages/system/administrator/create.module.less b/src/pages/system/administrator/compenents/create.module.less similarity index 100% rename from src/pages/system/administrator/create.module.less rename to src/pages/system/administrator/compenents/create.module.less diff --git a/src/pages/system/administrator/compenents/create.tsx b/src/pages/system/administrator/compenents/create.tsx new file mode 100644 index 0000000..de17099 --- /dev/null +++ b/src/pages/system/administrator/compenents/create.tsx @@ -0,0 +1,145 @@ +import React, { useState, useEffect } from "react"; +import { Modal, Select, Switch, Form, Input, message } from "antd"; +import styles from "./create.module.less"; +import { adminUser } from "../../../../api/index"; + +interface PropInterface { + open: boolean; + onCancel: () => void; +} + +export const SystemAdministratorCreate: React.FC = ({ + open, + onCancel, +}) => { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(true); + const [roles, setRoles] = useState([]); + + useEffect(() => { + getParams(); + }, []); + + useEffect(() => { + form.setFieldsValue({ + email: "", + name: "", + password: "", + is_ban_login: 0, + roleIds: [], + }); + }, [form, open]); + + const getParams = () => { + adminUser.createAdminUser().then((res: any) => { + const arr = []; + let roles = res.data.roles; + for (let i = 0; i < roles.length; i++) { + arr.push({ + label: roles[i].name, + value: roles[i].id, + }); + } + setRoles(arr); + }); + }; + + const onFinish = (values: any) => { + adminUser + .storeAdminUser( + values.name, + values.email, + values.password, + values.is_ban_login, + values.roleIds + ) + .then((res: any) => { + message.success("保存成功!"); + onCancel(); + }); + }; + + const onFinishFailed = (errorInfo: any) => { + console.log("Failed:", errorInfo); + }; + + const handleChange = (value: any) => {}; + + const onChange = (checked: boolean) => { + if (checked) { + form.setFieldsValue({ is_ban_login: 1 }); + } else { + form.setFieldsValue({ is_ban_login: 0 }); + } + }; + + return ( + <> + form.submit()} + onCancel={() => onCancel()} + > +
+
+ + + + + + + + + + + + +
+
+
+ + ); +}; diff --git a/src/pages/system/administrator/update.module.less b/src/pages/system/administrator/compenents/update.module.less similarity index 100% rename from src/pages/system/administrator/update.module.less rename to src/pages/system/administrator/compenents/update.module.less diff --git a/src/pages/system/administrator/compenents/update.tsx b/src/pages/system/administrator/compenents/update.tsx new file mode 100644 index 0000000..fa1ddd5 --- /dev/null +++ b/src/pages/system/administrator/compenents/update.tsx @@ -0,0 +1,162 @@ +import React, { useState, useEffect } from "react"; +import { Modal, Form, Input, Select, Switch, message } from "antd"; +import styles from "./update.module.less"; +import { adminUser } from "../../../../api/index"; + +interface PropInterface { + id: number; + open: boolean; + onCancel: () => void; +} + +export const SystemAdministratorUpdate: React.FC = ({ + id, + open, + onCancel, +}) => { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(true); + const [roles, setRoles] = useState([]); + + useEffect(() => { + getParams(); + }, []); + + useEffect(() => { + form.setFieldsValue({ + is_ban_login: 0, + }); + }, [form, open]); + + useEffect(() => { + if (id === 0) { + return; + } + getDetail(); + }, [id]); + + const getParams = () => { + adminUser.createAdminUser().then((res: any) => { + const arr = []; + let roles = res.data.roles; + for (let i = 0; i < roles.length; i++) { + arr.push({ + label: roles[i].name, + value: roles[i].id, + }); + } + setRoles(arr); + }); + }; + + const getDetail = () => { + adminUser.AdminUser(id).then((res: any) => { + let user = res.data.user; + form.setFieldsValue({ + email: user.email, + name: user.name, + is_ban_login: user.is_ban_login, + roleIds: res.data.role_ids, + }); + }); + }; + + const onFinish = (values: any) => { + adminUser + .updateAdminUser( + id, + values.name, + values.email, + values.password, + values.is_ban_login, + values.roleIds + ) + .then((res: any) => { + message.success("保存成功!"); + onCancel(); + }); + }; + + const onFinishFailed = (errorInfo: any) => { + console.log("Failed:", errorInfo); + }; + + const handleChange = (value: any) => {}; + + const onChange = (checked: boolean) => { + if (checked) { + form.setFieldsValue({ is_ban_login: 1 }); + } else { + form.setFieldsValue({ is_ban_login: 0 }); + } + }; + + return ( + <> + form.submit()} + onCancel={() => onCancel()} + > +
+
+ + + + + + + + + + + + +
+
+
+ + ); +}; diff --git a/src/pages/system/administrator/create.tsx b/src/pages/system/administrator/create.tsx deleted file mode 100644 index fda9529..0000000 --- a/src/pages/system/administrator/create.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { Row, Col, Form, Input, Select, Switch, Button, message } from "antd"; -import styles from "./create.module.less"; -import { adminUser } from "../../../api/index"; -import { useNavigate } from "react-router-dom"; -import { BackBartment } from "../../../compenents"; - -export const AdministratorCreatePage: React.FC = () => { - const navigate = useNavigate(); - const [form] = Form.useForm(); - const [loading, setLoading] = useState(true); - const [roles, setRoles] = useState([]); - - useEffect(() => { - getParams(); - }, []); - - const getParams = () => { - adminUser.createAdminUser().then((res: any) => { - const arr = []; - let roles = res.data.roles; - for (let i = 0; i < roles.length; i++) { - arr.push({ - label: roles[i].name, - value: roles[i].id, - }); - } - setRoles(arr); - form.setFieldsValue({ is_ban_login: 0 }); - }); - }; - - const onFinish = (values: any) => { - adminUser - .storeAdminUser( - values.name, - values.email, - values.password, - values.is_ban_login, - values.roleIds - ) - .then((res: any) => { - message.success("保存成功!"); - navigate(-1); - }); - }; - - const onFinishFailed = (errorInfo: any) => { - console.log("Failed:", errorInfo); - }; - - const handleChange = (value: any) => {}; - - const onChange = (checked: boolean) => { - if (checked) { - form.setFieldsValue({ is_ban_login: 1 }); - } else { - form.setFieldsValue({ is_ban_login: 0 }); - } - }; - - return ( - <> - - -
- -
-
-
- - - - - - - - - - - - - - - - -
-
- -
- - ); -}; diff --git a/src/pages/system/administrator/index.tsx b/src/pages/system/administrator/index.tsx index 2772ea6..6d47e6d 100644 --- a/src/pages/system/administrator/index.tsx +++ b/src/pages/system/administrator/index.tsx @@ -1,19 +1,15 @@ import React, { useState, useEffect } from "react"; -import { - Typography, - Input, - Button, - Space, - Table, - Popconfirm, - message, -} from "antd"; +import { Typography, Input, Button, Space, Table, Modal, message } from "antd"; import type { ColumnsType } from "antd/es/table"; -import { PlusOutlined, ReloadOutlined } from "@ant-design/icons"; +import { PlusOutlined, ExclamationCircleFilled } from "@ant-design/icons"; import { adminUser } from "../../../api/index"; import { dateFormat } from "../../../utils/index"; -import { Link, useNavigate } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import { PerButton } from "../../../compenents"; +import { SystemAdministratorCreate } from "./compenents/create"; +import { SystemAdministratorUpdate } from "./compenents/update"; + +const { confirm } = Modal; interface DataType { id: React.Key; @@ -32,6 +28,9 @@ export const SystemAdministratorPage: React.FC = () => { const [list, setList] = useState([]); const [total, setTotal] = useState(0); const [refresh, setRefresh] = useState(false); + const [createVisible, setCreateVisible] = useState(false); + const [updateVisible, setUpdateVisible] = useState(false); + const [cid, setCid] = useState(0); const [name, setName] = useState(""); @@ -75,32 +74,26 @@ export const SystemAdministratorPage: React.FC = () => { - navigate(`/system/administrator/update/${record.id}`) - } + onClick={() => { + setCid(Number(record.id)); + setUpdateVisible(true); + }} + disabled={null} + /> +
+ delUser(record.id)} disabled={null} /> - delUser(record.id)} - okText="确定" - cancelText="取消" - > - null} - disabled={null} - /> -
), }, @@ -142,71 +135,70 @@ export const SystemAdministratorPage: React.FC = () => { }; const delUser = (id: any) => { - adminUser.destroyAdminUser(id).then((res: any) => { - message.success("操作成功"); - setRefresh(!refresh); + if (id === 0) { + return; + } + confirm({ + title: "操作确认", + icon: , + content: "确认删除此人员?", + centered: true, + okText: "确认", + okType: "danger", + cancelText: "取消", + onOk() { + adminUser.destroyAdminUser(id).then((res: any) => { + message.success("操作成功"); + setRefresh(!refresh); + }); + }, + onCancel() { + console.log("Cancel"); + }, }); }; return ( <> -
-
-
- 姓名: - { - setName(e.target.value); - }} - style={{ width: 160 }} - placeholder="请输入姓名" - /> -
-
- - -
-
-
- -
+
- - } - p="admin-user-cud" - onClick={() => null} - disabled={null} - /> - + } + p="admin-user-cud" + onClick={() => setCreateVisible(true)} + disabled={null} + />
- +
+ 姓名: + { + setName(e.target.value); + }} + style={{ width: 160 }} + placeholder="请输入姓名" + /> +
+
+ + +
@@ -217,6 +209,21 @@ export const SystemAdministratorPage: React.FC = () => { pagination={paginationProps} rowKey={(record) => record.id} /> + { + setCreateVisible(false); + setRefresh(!refresh); + }} + /> + { + setUpdateVisible(false); + setRefresh(!refresh); + }} + />
diff --git a/src/pages/system/administrator/update.tsx b/src/pages/system/administrator/update.tsx deleted file mode 100644 index cedfa4e..0000000 --- a/src/pages/system/administrator/update.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { Row, Col, Form, Input, Select, Switch, Button, message } from "antd"; -import styles from "./update.module.less"; -import { adminUser } from "../../../api/index"; -import { useParams, useNavigate } from "react-router-dom"; -import { BackBartment } from "../../../compenents"; - -export const AdministratorUpdatePage: React.FC = () => { - const params = useParams(); - const navigate = useNavigate(); - const [form] = Form.useForm(); - const [loading, setLoading] = useState(true); - const [roles, setRoles] = useState([]); - - useEffect(() => { - getParams(); - }, []); - useEffect(() => { - getDetail(); - }, [params.userId]); - - const getParams = () => { - adminUser.createAdminUser().then((res: any) => { - const arr = []; - let roles = res.data.roles; - for (let i = 0; i < roles.length; i++) { - arr.push({ - label: roles[i].name, - value: roles[i].id, - }); - } - setRoles(arr); - form.setFieldsValue({ is_ban_login: 0 }); - }); - }; - - const getDetail = () => { - adminUser.AdminUser(Number(params.userId)).then((res: any) => { - let user = res.data.user; - form.setFieldsValue({ - email: user.email, - name: user.name, - is_ban_login: user.is_ban_login, - roleIds: res.data.role_ids, - }); - }); - }; - - const onFinish = (values: any) => { - let id = Number(params.userId); - adminUser - .updateAdminUser( - id, - values.name, - values.email, - values.password, - values.is_ban_login, - values.roleIds - ) - .then((res: any) => { - message.success("保存成功!"); - navigate(-1); - }); - }; - - const onFinishFailed = (errorInfo: any) => { - console.log("Failed:", errorInfo); - }; - - const handleChange = (value: any) => {}; - - const onChange = (checked: boolean) => { - if (checked) { - form.setFieldsValue({ is_ban_login: 1 }); - } else { - form.setFieldsValue({ is_ban_login: 0 }); - } - }; - - return ( - <> - - -
- -
-
-
- - - - - - - - - - - - - - - - -
-
- -
- - ); -}; diff --git a/src/pages/system/adminroles/compenents/create.tsx b/src/pages/system/adminroles/compenents/create.tsx index 1924338..49284f0 100644 --- a/src/pages/system/adminroles/compenents/create.tsx +++ b/src/pages/system/adminroles/compenents/create.tsx @@ -24,6 +24,8 @@ export const SystemAdminrolesCreate: React.FC = ({ useEffect(() => { form.setFieldsValue({ name: "", + permission_ids: [], + action_ids: [], }); }, [form, open]); @@ -51,7 +53,15 @@ export const SystemAdminrolesCreate: React.FC = ({ }; const onFinish = (values: any) => { - const params = values.action_ids.concat(values.permission_ids); + let pids = []; + let aids = []; + if (values.permission_ids) { + pids = values.permission_ids; + } + if (values.action_ids) { + aids = values.action_ids; + } + const params = aids.concat(pids); adminRole.storeAdminRole(values.name, params).then((res: any) => { message.success("保存成功!"); onCancel(); diff --git a/src/pages/system/adminroles/compenents/update.tsx b/src/pages/system/adminroles/compenents/update.tsx index d5d25c3..2e9933a 100644 --- a/src/pages/system/adminroles/compenents/update.tsx +++ b/src/pages/system/adminroles/compenents/update.tsx @@ -65,8 +65,16 @@ export const SystemAdminrolesUpdate: React.FC = ({ }; const onFinish = (values: any) => { - const arr = values.action_ids.concat(values.permission_ids); - adminRole.updateAdminRole(id, values.name, arr).then((res: any) => { + let pids = []; + let aids = []; + if (values.permission_ids) { + pids = values.permission_ids; + } + if (values.action_ids) { + aids = values.action_ids; + } + const params = aids.concat(pids); + adminRole.updateAdminRole(id, values.name, params).then((res: any) => { message.success("保存成功!"); onCancel(); }); @@ -79,7 +87,7 @@ export const SystemAdminrolesUpdate: React.FC = ({ return ( <> { - const navigate = useNavigate(); const [loading, setLoading] = useState(true); const [list, setList] = useState([]); const [refresh, setRefresh] = useState(false); @@ -42,28 +43,28 @@ export const SystemAdminrolesPage: React.FC = () => { width: 160, render: (_, record) => ( - - delUser(record.id)} - okText="确定" - cancelText="取消" - > - - + disabled={null} + /> +
+ delUser(record.id)} + disabled={null} + />
), }, @@ -87,9 +88,26 @@ export const SystemAdminrolesPage: React.FC = () => { }; const delUser = (id: any) => { - adminRole.destroyAdminRole(id).then((res: any) => { - message.success("操作成功"); - resetData(); + if (id === 0) { + return; + } + confirm({ + title: "操作确认", + icon: , + content: "确认删除此角色?", + centered: true, + okText: "确认", + okType: "danger", + cancelText: "取消", + onOk() { + adminRole.destroyAdminRole(id).then((res: any) => { + message.success("操作成功"); + resetData(); + }); + }, + onCancel() { + console.log("Cancel"); + }, }); }; @@ -107,16 +125,7 @@ export const SystemAdminrolesPage: React.FC = () => { 新建角色
-
- -
+
{ loading={loading} rowKey={(record) => record.id} /> + { + setCreateVisible(false); + setRefresh(!refresh); + }} + /> + { + setUpdateVisible(false); + setRefresh(!refresh); + }} + /> - { - setCreateVisible(false); - setRefresh(!refresh); - }} - /> - { - setUpdateVisible(false); - setRefresh(!refresh); - }} - /> ); diff --git a/src/router/routes.tsx b/src/router/routes.tsx index 2fe9f26..3e460b7 100644 --- a/src/router/routes.tsx +++ b/src/router/routes.tsx @@ -13,8 +13,6 @@ import { MemberUpdatePage, MemberImportPage, SystemAdministratorPage, - AdministratorCreatePage, - AdministratorUpdatePage, SystemAdminrolesPage, DepartmentPage, ChangePasswordPage, @@ -86,14 +84,6 @@ const routes: RouteObject[] = [ path: "/system/administrator", element: , }, - { - path: "/system/administrator/create", - element: , - }, - { - path: "/system/administrator/update/:userId", - element: , - }, { path: "/system/adminroles", element: ,