|
@@ -1,9 +1,134 @@
|
|
|
-import React from "react";
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
+import { Button, Input } from "antd";
|
|
|
+import { UserTableAPIType, UserTableListType } from "@/types";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import { getMessageListAPI, removeMessageAPI } from "@/store/action/A3message";
|
|
|
+import MyTable from "@/components/MyTable";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+import { A3tableC } from "@/utils/tableData";
|
|
|
+import MyPopconfirm from "@/components/MyPopconfirm";
|
|
|
function A3message() {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+
|
|
|
+ // 顶部筛选
|
|
|
+ const [fromData, setFromData] = useState<UserTableAPIType>({
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ searchKey: "",
|
|
|
+ });
|
|
|
+
|
|
|
+ // 封装发送请求的函数
|
|
|
+
|
|
|
+ const getList = useCallback(async () => {
|
|
|
+ dispatch(getMessageListAPI(fromData));
|
|
|
+ }, [dispatch, fromData]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getList();
|
|
|
+ }, [getList]);
|
|
|
+
|
|
|
+ const timeRef = useRef(-1);
|
|
|
+ // 用户名
|
|
|
+ const txtChangeFu = useCallback(
|
|
|
+ (e: React.ChangeEvent<HTMLInputElement>, key: "searchKey") => {
|
|
|
+ clearTimeout(timeRef.current);
|
|
|
+ timeRef.current = window.setTimeout(() => {
|
|
|
+ setFromData({
|
|
|
+ ...fromData,
|
|
|
+ [key]: e.target.value,
|
|
|
+ pageNum: 1,
|
|
|
+ });
|
|
|
+ }, 500);
|
|
|
+ },
|
|
|
+ [fromData]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const [inputKey, setInputKey] = useState(1);
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
+ // 把2个输入框和时间选择器清空
|
|
|
+ setInputKey(Date.now());
|
|
|
+ setFromData({
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ searchKey: "",
|
|
|
+ });
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 从仓库中获取表格数据
|
|
|
+ const tableInfo = useSelector((state: RootState) => state.A3message.tableInfo);
|
|
|
+
|
|
|
+ // 点击删除
|
|
|
+ const delTableFu = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ const res: any = await removeMessageAPI(id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
+ getList();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [getList]
|
|
|
+ );
|
|
|
+
|
|
|
+ const tableLastBtn = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: UserTableListType) => {
|
|
|
+ return item.isAdmin === 1 ? (
|
|
|
+ "-"
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
|
|
|
+ </>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }, [delTableFu]);
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.A3message}>
|
|
|
<div className="pageTitle">留言反馈</div>
|
|
|
+
|
|
|
+ <div className="userTop">
|
|
|
+ <div className="selectBox">
|
|
|
+ <div className="selectBoxRow">
|
|
|
+ <span>搜索项:</span>
|
|
|
+ <Input
|
|
|
+ key={inputKey}
|
|
|
+ maxLength={10}
|
|
|
+ showCount
|
|
|
+ style={{ width: 300 }}
|
|
|
+ placeholder="请输入用户名"
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => txtChangeFu(e, "searchKey")}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="selectBoxRow">
|
|
|
+   <Button onClick={resetSelectFu}>重置</Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <div className="tableBox">
|
|
|
+ <MyTable
|
|
|
+ yHeight={617}
|
|
|
+ list={tableInfo.list}
|
|
|
+ columnsTemp={A3tableC}
|
|
|
+ lastBtn={tableLastBtn}
|
|
|
+ pageNum={fromData.pageNum}
|
|
|
+ pageSize={fromData.pageSize}
|
|
|
+ total={tableInfo.total}
|
|
|
+ onChange={(pageNum, pageSize) =>
|
|
|
+ setFromData({ ...fromData, pageNum, pageSize })
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
);
|
|
|
}
|