|
@@ -0,0 +1,205 @@
|
|
|
+import BreadTit from "@/components/BreadTit";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import { getRoleListAPI } from "@/store/action/system";
|
|
|
+import { Button, Input, Modal, Popconfirm, Table } from "antd";
|
|
|
+import TextArea from "antd/es/input/TextArea";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import "../System1/index.css";
|
|
|
+function System2() {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+
|
|
|
+ // 筛选和分页
|
|
|
+ const [tableSelect, setTableSelect] = useState({
|
|
|
+ searchKey: "",
|
|
|
+ pageSize: 10,
|
|
|
+ pageNum: 1,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 账号的输入
|
|
|
+ const nameTime = useRef(-1);
|
|
|
+ const nameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
+ clearTimeout(nameTime.current);
|
|
|
+ nameTime.current = window.setTimeout(() => {
|
|
|
+ setTableSelect({ ...tableSelect, searchKey: e.target.value, pageNum: 1 });
|
|
|
+ }, 500);
|
|
|
+ };
|
|
|
+ useEffect(() => {
|
|
|
+ dispatch(getRoleListAPI(tableSelect));
|
|
|
+ }, [dispatch, tableSelect]);
|
|
|
+
|
|
|
+ // 点击新增或者编辑按钮
|
|
|
+ const addRole = useCallback((id?: any) => {
|
|
|
+ if (id) {
|
|
|
+ editRef.current = "edit";
|
|
|
+ console.log("点了编辑");
|
|
|
+ } else {
|
|
|
+ editRef.current = "add";
|
|
|
+ console.log("点了新增");
|
|
|
+ }
|
|
|
+ setOpen(true);
|
|
|
+ }, []);
|
|
|
+ // 点击删除
|
|
|
+ const delOne = useCallback((id: number) => {
|
|
|
+ console.log(id);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // ---------关于表格
|
|
|
+
|
|
|
+ // 页码变化
|
|
|
+ const paginationChange = (pageNum: number, pageSize: number) => {
|
|
|
+ setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
+ };
|
|
|
+ const results = useSelector(
|
|
|
+ (state: RootState) => state.systemStore.tableList
|
|
|
+ );
|
|
|
+ const columns = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: "角色名称",
|
|
|
+ dataIndex: "roleName",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "描述",
|
|
|
+ dataIndex: "roleDesc",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "成语数量",
|
|
|
+ dataIndex: "sort",
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ title: "状态",
|
|
|
+ render: (item: any) => (item.day && item.status === 3 ? item.day : "-"),
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: any) => (
|
|
|
+ <>
|
|
|
+ <Button type="text" danger onClick={() => addRole(item.id)}>
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Popconfirm
|
|
|
+ title="确定删除吗?"
|
|
|
+ okText="确定"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => delOne(item.id)}
|
|
|
+ >
|
|
|
+ <Button type="text" danger>
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }, [addRole, delOne]);
|
|
|
+
|
|
|
+ // --------关于弹窗
|
|
|
+ const [open, setOpen] = useState(true);
|
|
|
+ const editRef = useRef("add");
|
|
|
+
|
|
|
+ // 角色名称
|
|
|
+ const [roleName, setRoleName] = useState("");
|
|
|
+ // 描述
|
|
|
+ const [roleDesc, setRoleDesc] = useState("");
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.System2}>
|
|
|
+ <div className="breadTit">
|
|
|
+ <BreadTit>
|
|
|
+ <div className="breadTitRow active">角色管理</div>
|
|
|
+ </BreadTit>
|
|
|
+ </div>
|
|
|
+ <div className="objectSonMain">
|
|
|
+ <div className="tableSelectBox">
|
|
|
+ <div className="row">
|
|
|
+ <span>账号:</span>
|
|
|
+ <Input
|
|
|
+ maxLength={10}
|
|
|
+ style={{ width: 150 }}
|
|
|
+ placeholder="请输入"
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => nameChange(e)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className="row">
|
|
|
+ <Button type="primary" onClick={() => addRole()}>
|
|
|
+ 新增角色
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <div className="tableMain">
|
|
|
+ <Table
|
|
|
+ scroll={{ y: 480 }}
|
|
|
+ dataSource={results.list}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={{
|
|
|
+ showQuickJumper: true,
|
|
|
+ position: ["bottomCenter"],
|
|
|
+ showSizeChanger: true,
|
|
|
+ current: tableSelect.pageNum,
|
|
|
+ pageSize: tableSelect.pageSize,
|
|
|
+ total: results.total,
|
|
|
+ onChange: paginationChange,
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {/* 点击新增或者编辑出来的弹窗 */}
|
|
|
+ <Modal
|
|
|
+ wrapClassName="systemUser systemRole"
|
|
|
+ destroyOnClose
|
|
|
+ open={open}
|
|
|
+ title={editRef.current === "add" ? "新增角色" : "编辑角色"}
|
|
|
+ onCancel={() => setOpen(false)}
|
|
|
+ footer={
|
|
|
+ [] // 设置footer为空,去掉 取消 确定默认按钮
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className="systemTit">
|
|
|
+ <div className="systemTitRow">
|
|
|
+ <div className="bs">*</div>
|
|
|
+ <span>角色名称:</span>
|
|
|
+ <Input
|
|
|
+ maxLength={15}
|
|
|
+ showCount
|
|
|
+ style={{ width: 500 }}
|
|
|
+ placeholder="请输入"
|
|
|
+ value={roleName}
|
|
|
+ onChange={(e) => setRoleName(e.target.value.trim())}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className="systemTitRow">
|
|
|
+ <div className="bs bs2">*</div>
|
|
|
+ <span>描述:</span>
|
|
|
+ <TextArea
|
|
|
+ style={{ width: 500 }}
|
|
|
+ value={roleDesc}
|
|
|
+ onChange={(e) => setRoleDesc(e.target.value)}
|
|
|
+ rows={3}
|
|
|
+ placeholder="请输入"
|
|
|
+ showCount
|
|
|
+ maxLength={255}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoSystem2 = React.memo(System2);
|
|
|
+
|
|
|
+export default MemoSystem2;
|