From 6f9a8906eb77264ca47beb8052bef667b66df021 Mon Sep 17 00:00:00 2001 From: Jim__TT <1820452084@qq.com> Date: Tue, 31 Oct 2023 19:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=94=90=E7=AE=80=EF=BC=9A=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=B2=97=E4=BD=8D=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/post.ts | 51 ++++ src/view/system/post/index.scss | 103 +++++++ src/view/system/post/index.tsx | 473 ++++++++++++++++++++++++++++++++ src/view/system/user/index.tsx | 12 +- 4 files changed, 636 insertions(+), 3 deletions(-) create mode 100644 src/api/system/post.ts create mode 100644 src/view/system/post/index.scss create mode 100644 src/view/system/post/index.tsx diff --git a/src/api/system/post.ts b/src/api/system/post.ts new file mode 100644 index 0000000..1683a0a --- /dev/null +++ b/src/api/system/post.ts @@ -0,0 +1,51 @@ +import request from "../../utils/request"; + +interface postListParams { + postCode?: string; + postName?: string; + state?: string; + pageNum?: string; + pageSize?: string; +} + +export const getPostListApi = (data: postListParams) => { + const { postCode, postName, state, pageNum, pageSize } = data; + const params = data + ? { + postCode, + postName, + state, + pageNum, + pageSize: 500, + } + : undefined; + + return request({ + url: "/admin/post", + method: "get", + params, + }); +}; + +export const addPostApi = (data: any) => { + return request({ + url: "/admin/post", + method: "post", + data, + }); +}; + +export const editPostApi = (data: any) => { + return request({ + url: "/admin/post", + method: "put", + data, + }); +}; + +export const deletePostApi = (postId: any) => { + return request({ + url: "/admin/post/" + postId, + method: "delete", + }); +}; diff --git a/src/view/system/post/index.scss b/src/view/system/post/index.scss new file mode 100644 index 0000000..19d6dac --- /dev/null +++ b/src/view/system/post/index.scss @@ -0,0 +1,103 @@ +#content { + display: flex; + border-top: 1px solid black; + .dept-content { + flex: 20%; + padding: 35px 12px 0 0; + height: calc(100vh - 85px); + } + + .left-dept { + flex: 20%; + padding: 35px 12px 0 0; + height: calc(100vh - 85px); + border: 1px solid red; + border-top: 1px solid black; + } + .right { + flex: 80%; + height: 190px; + display: flex; + flex-direction: column; + + .search-content { + display: flex; + flex-direction: column; + padding: 35px 12px 0 0; + .content-top { + display: flex; + .input-item { + display: flex; + align-items: center; + margin-right: 20px; + width: 270px; + div { + width: 120px; + font-weight: bold; + } + } + :nth-child(3) { + div { + margin-right: -30px; + } + } + } + .content-bottom { + display: flex; + margin-left: 12px; + margin-top: 20px; + div { + margin-right: 10px; + } + .time-selector { + display: flex; + align-items: center; + + div { + width: 120px; + font-weight: bold; + } + .time-picker { + width: 400px; + text-align: center; + margin-left: -30px; + margin-right: 25px; + } + } + button:focus, + button:focus-visible { + outline: none; + } + } + } + .table-content { + margin: 12px 0 0 12px; + + .ant-table-thead > tr > th { + color: #909399; + text-align: center; + } + .ant-table-tbody > tr > td { + text-align: center; + } + } + .add-content { + display: flex; + margin-left: 12px; + margin-top: 20px; + button:focus, + button:focus-visible { + outline: none; + } + } + .user-mid-button { + display: flex; + margin-left: 12px; + margin-top: 20px; + button:focus, + button:focus-visible { + outline: none; + } + } + } +} diff --git a/src/view/system/post/index.tsx b/src/view/system/post/index.tsx new file mode 100644 index 0000000..2adaa63 --- /dev/null +++ b/src/view/system/post/index.tsx @@ -0,0 +1,473 @@ +import "./index.scss"; +import { + Input, + Select, + Button, + Table, + Space, + Tag, + message, + Modal, + Form, + Row, + Col, + Radio, + InputNumber, +} from "antd"; + +import { + EditOutlined, + DeleteOutlined, + ExclamationCircleFilled, +} from "@ant-design/icons"; + +import { + getPostListApi, + addPostApi, + editPostApi, + deletePostApi, +} from "../../../api/system/post"; + +import React, { useEffect, useState } from "react"; +import { SearchOutlined, RedoOutlined, PlusOutlined } from "@ant-design/icons"; + +export default function Post() { + const [form] = Form.useForm(); + const postIdList: number[] = []; + const [echoData, setEchoData] = useState({}); + const [listData, setListData] = useState([]); + const [radioValue, setRadioValue] = useState(1); + const [messageApi, contextHolder] = message.useMessage(); + const [modalTitle, setModalTitle] = useState(""); + const [buttonType, setButtonType] = useState(""); + const [isShowModal, setIsShowModal] = useState(false); + const [queryParams, setQueryParams] = useState({ + postName: undefined, + postCode: undefined, + state: undefined, + postSort: undefined, + pageSize: undefined, + pageNum: undefined, + }); + const columns = [ + { + title: "序号", + dataIndex: "postId", + key: "Id", + render: (text: string) => <>{text ? text : "null"}, + }, + { + title: "岗位名称", + dataIndex: "postName", + key: "postName", + render: (text: string) => <>{text ? text : "null"}, + }, + { + title: "岗位编码", + dataIndex: "postCode", + key: "postCode", + render: (text: string) => <>{text ? text : "null"}, + }, + { + title: "排序", + key: "postSort", + dataIndex: "postSort", + render: (text: string) => <>{text ? text : "--"}, + }, + { + title: "状态", + key: "state", + dataIndex: "state", + render: (text: string) => ( + <> + {text === "0" ? ( + 停用 + ) : ( + 正常 + )} + + ), + }, + { + title: "创建时间", + key: "createTime", + dataIndex: "createTime", + render: (text: string) => <>{text ? text : "null"}, + }, + { + title: "操作", + key: "operate", + dataIndex: "operate", + render: (_: string, record: object) => ( + + ), + }, + ]; + + interface QueryParamsType { + postName?: string; + postCode?: string; + state?: string; + postSort?: string; + postId?: string; + pageSize?: number; + pageNum?: number; + } + + const getPostList = async (newQueryParams: object) => { + try { + const { code, data } = await getPostListApi(newQueryParams); + if (code === 1000) { + setListData(data.rows); + } + } catch (err) { + console.error(err); + } + }; + + const handleAdd = () => { + setModalTitle("新增用户"); + setButtonType("ADD"); + setIsShowModal(true); + }; + + const handleEdit = (data: any) => { + setModalTitle("修改用户"); + setButtonType("EDIT"); + setIsShowModal(true); + console.log(data); + setEchoData({ + postId: data.postId, + }); + handleEcho(data); + }; + + const handleConfirm = () => { + form.validateFields().then((values) => { + console.log(values); + console.log(buttonType); + + if (buttonType === "ADD") { + handleConfirmAdd(values); + } else if (buttonType === "EDIT") { + handleConfirmEdit(values); + } else { + messageApi.open({ + type: "error", + content: "系统异常,请刷新后重试", + }); + } + }); + }; + + const handleConfirmAdd = async (data: object) => { + console.log(data); + const { code } = await addPostApi(data); + try { + if (code === 1000) { + messageApi.open({ + type: "success", + content: "创建成功", + }); + setQueryParams({}); + handleClear(); + } else { + messageApi.open({ + type: "error", + content: "岗位名称已经存在", + }); + } + } catch (err) { + console.log(err); + } + }; + + const handleConfirmEdit = async (data: object) => { + const editData = { + ...data, + postId: echoData.postId, + }; + console.log(editData); + const { code } = await editPostApi(editData); + try { + if (code === 1000) { + messageApi.open({ + type: "success", + content: "修改成功", + }); + setQueryParams({}); + handleClear(); + } else { + messageApi.open({ + type: "error", + content: "修改失败", + }); + } + } catch (err) { + console.log(err); + } + }; + + const handleReset = async () => { + setQueryParams({}); + getPostList({}); + }; + + const handleSearch = () => { + getPostList(queryParams); + }; + + const handleDel = async (record: any) => { + Modal.confirm({ + title: `确定删除Id为-${record.postId}-, 岗位名称为-${record.postName}-的岗位吗?`, + icon: , + async onOk() { + const { code } = await deletePostApi(record.postId); + try { + if (code === 1000) { + messageApi.open({ + type: "success", + content: "删除成功", + }); + setQueryParams({}); + } else { + messageApi.open({ + type: "error", + content: "删除失败", + }); + } + } catch (err) { + console.log(err); + } + }, + onCancel() { + messageApi.open({ + type: "warning", + content: "取消成功", + }); + }, + }); + }; + + const handleSearchValues = (e: any) => { + const { name, value } = e.target; + setQueryParams({ ...queryParams, [name]: value }); + }; + + const handlePageChange = (page: number) => { + setQueryParams({ + ...queryParams, + pageNum: page, + }); + }; + + const handleEcho = (data: any) => { + const { postName, postCode, state, postSort } = data; + form.setFieldsValue({ + postName, + postCode, + state, + postSort, + }); + }; + + const handleCancel = () => { + handleClear(); + }; + + const handleClear = () => { + form.resetFields(); + setIsShowModal(false); + }; + + const onRadio = (e: any) => { + setRadioValue(e.target.value); + }; + + useEffect(() => { + getPostList(queryParams); + }, []); + + return ( +
+ <> +
+
+ <> +
+
+
岗位名称
+ +
+
+
岗位编码
+ +
+
+
状态
+ + + + + + + + + + + + + + + + + 正常 + 停用 + + + + + + + +
+ +
+ ); +} diff --git a/src/view/system/user/index.tsx b/src/view/system/user/index.tsx index a0dabc5..cbc4211 100644 --- a/src/view/system/user/index.tsx +++ b/src/view/system/user/index.tsx @@ -34,6 +34,7 @@ import { } from "../../../api/system/users"; import FormatData from "../../../utils/formatData"; +import locale from "antd/es/date-picker/locale/zh_CN"; import React, { useEffect, useState, useMemo, useRef } from "react"; import { SearchOutlined, RedoOutlined, PlusOutlined } from "@ant-design/icons"; @@ -557,6 +558,7 @@ export default function User() {
创建时间
{ @@ -596,6 +598,10 @@ export default function User() { className="article-table" pagination={{ onChange: handlePageChange, + locale: { + jump_to: "跳至", + page: "页", + }, showQuickJumper: true, showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`, @@ -608,6 +614,8 @@ export default function User() {