|
@@ -1,12 +1,233 @@
|
|
|
-import React from "react";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import {
|
|
|
+ getUserListAPI,
|
|
|
+ userPassResetAPI,
|
|
|
+ userRemoveAPI,
|
|
|
+} from "@/store/action/A7user";
|
|
|
+import { UserTableAPIType, UserTableListType } from "@/types";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+import { Input, Button, Table, Popconfirm } from "antd";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
import styles from "./index.module.scss";
|
|
|
- function A7user() {
|
|
|
-
|
|
|
+import UserAdd from "./UserAdd";
|
|
|
+
|
|
|
+function A7user() {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+
|
|
|
+ // 顶部筛选
|
|
|
+ const [tableSelect, setTableSelect] = useState<UserTableAPIType>({
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ searchKey: "",
|
|
|
+ });
|
|
|
+
|
|
|
+ // 封装发送请求的函数
|
|
|
+
|
|
|
+ const getList = useCallback(async () => {
|
|
|
+ dispatch(getUserListAPI(tableSelect));
|
|
|
+ }, [dispatch, tableSelect]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getList();
|
|
|
+ }, [getList]);
|
|
|
+
|
|
|
+ const timeRef = useRef(-1);
|
|
|
+ // 用户名
|
|
|
+ const txtChangeFu = useCallback(
|
|
|
+ (e: React.ChangeEvent<HTMLInputElement>, key: "searchKey") => {
|
|
|
+ clearTimeout(timeRef.current);
|
|
|
+ timeRef.current = window.setTimeout(() => {
|
|
|
+ setTableSelect({
|
|
|
+ ...tableSelect,
|
|
|
+ [key]: e.target.value,
|
|
|
+ pageNum: 1,
|
|
|
+ });
|
|
|
+ }, 500);
|
|
|
+ },
|
|
|
+ [tableSelect]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const [inputKey, setInputKey] = useState(1);
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
+ // 把2个输入框和时间选择器清空
|
|
|
+ setInputKey(Date.now());
|
|
|
+ setTableSelect({
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ searchKey: "",
|
|
|
+ });
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 从仓库中获取表格数据
|
|
|
+ const tableInfo = useSelector((state: RootState) => state.A7user.tableInfo);
|
|
|
+
|
|
|
+ // 页码变化
|
|
|
+ const paginationChange = useCallback(
|
|
|
+ () => (pageNum: number, pageSize: number) => {
|
|
|
+ setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
+ },
|
|
|
+ [tableSelect]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击删除
|
|
|
+ const delTableFu = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ const res: any = await userRemoveAPI(id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
+ getList();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [getList]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击重置密码
|
|
|
+ const resetPassFu = useCallback(async (id: number) => {
|
|
|
+ const res: any = await userPassResetAPI(id);
|
|
|
+ if (res.code === 0) MessageFu.success("重置成功!");
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 0------------点击新增或者编辑出来的页面
|
|
|
+ const [editPageShow, setEditPageShow] = useState(false);
|
|
|
+ const editId = useRef(0);
|
|
|
+
|
|
|
+ const openEditPageFu = useCallback(
|
|
|
+ (id: number) => {
|
|
|
+ if (id === 0 && tableInfo.list.length >= 50)
|
|
|
+ return MessageFu.warning("最多支持50个用户!");
|
|
|
+
|
|
|
+ editId.current = id;
|
|
|
+ setEditPageShow(true);
|
|
|
+ },
|
|
|
+ [tableInfo.list.length]
|
|
|
+ );
|
|
|
+
|
|
|
+ const columns = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: "用户名",
|
|
|
+ dataIndex: "userName",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "角色",
|
|
|
+ render: (item: UserTableListType) =>
|
|
|
+ item.isAdmin === 1 ? "管理员" : "普通成员",
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ title: "真实姓名",
|
|
|
+ dataIndex: "realName",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "创建日期",
|
|
|
+ dataIndex: "createTime",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: UserTableListType) => {
|
|
|
+ return item.isAdmin === 1 ? (
|
|
|
+ "-"
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Popconfirm
|
|
|
+ title="密码重制后为123456,是否重置?"
|
|
|
+ okText="重置"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => resetPassFu(item.id!)}
|
|
|
+ >
|
|
|
+ <Button size="small" type="text">
|
|
|
+ 重置密码
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+
|
|
|
+ <Button
|
|
|
+ size="small"
|
|
|
+ type="text"
|
|
|
+ onClick={() => openEditPageFu(item.id!)}
|
|
|
+ >
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+ <Popconfirm
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
+ okText="删除"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => delTableFu(item.id!)}
|
|
|
+ >
|
|
|
+ <Button size="small" type="text" danger>
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }, [delTableFu, openEditPageFu, resetPassFu]);
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.A7user}>
|
|
|
- <h1>A7user</h1>
|
|
|
+ <div className="pageTitle">用户管理</div>
|
|
|
+ <div className="userTop">
|
|
|
+ <div className="selectBox">
|
|
|
+ <div className="selectBoxRow">
|
|
|
+ <span>搜索项:</span>
|
|
|
+ <Input
|
|
|
+ key={inputKey}
|
|
|
+ maxLength={8}
|
|
|
+ style={{ width: 300 }}
|
|
|
+ placeholder="请输入用户名"
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => txtChangeFu(e, "searchKey")}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="selectBoxRow">
|
|
|
+   <Button onClick={resetSelectFu}>重置</Button>
|
|
|
+   
|
|
|
+ <Button type="primary" onClick={() => openEditPageFu(0)}>
|
|
|
+ 新增
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <div className="tableBox">
|
|
|
+ <Table
|
|
|
+ scroll={{ y: 617 }}
|
|
|
+ dataSource={tableInfo.list}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={{
|
|
|
+ showQuickJumper: true,
|
|
|
+ position: ["bottomCenter"],
|
|
|
+ showSizeChanger: true,
|
|
|
+ current: tableSelect.pageNum,
|
|
|
+ pageSize: tableSelect.pageSize,
|
|
|
+ total: tableInfo.total,
|
|
|
+ onChange: paginationChange(),
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 点击新增或者编辑 */}
|
|
|
+ {editPageShow ? (
|
|
|
+ <UserAdd
|
|
|
+ id={editId.current}
|
|
|
+ closePage={() => setEditPageShow(false)}
|
|
|
+ upTableList={getList}
|
|
|
+ addTableList={resetSelectFu}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
- )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
const MemoA7user = React.memo(A7user);
|