|
@@ -8,21 +8,25 @@ import React, {
|
|
|
import styles from "./index.module.scss";
|
|
|
import { Button, Input, Popconfirm, Table, Tooltip } from "antd";
|
|
|
import { useDispatch } from "react-redux";
|
|
|
-import { A2_APIgetList, A2_APIsort } from "@/store/action/A2Country";
|
|
|
+import { A2_APIdel, A2_APIgetList, A2_APIsort } from "@/store/action/A2Country";
|
|
|
import { A2TableType } from "@/types";
|
|
|
import { ExclamationCircleFilled } from "@ant-design/icons";
|
|
|
+import { forwardRef, useImperativeHandle } from "react";
|
|
|
|
|
|
// 表格拖动排序-----------------
|
|
|
import { DndProvider, useDrag, useDrop } from "react-dnd";
|
|
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+import ImageLazy from "../ImageLazy";
|
|
|
|
|
|
type Props = {
|
|
|
setEditId: (id: number, flag: boolean) => void; //点击新增/编辑/查看
|
|
|
- myType: "national" | "history" | "custom" | "project"; //区分各个不同板块
|
|
|
- tableInfo: any; //表格数据
|
|
|
+ myType: "national" | "history" | "custom" | "project" | "craft" | "master"; //区分各个不同板块
|
|
|
+ tableInfo: { list: A2TableType[]; total: number }; //表格数据
|
|
|
+ ref: any;
|
|
|
};
|
|
|
|
|
|
-function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
+function ZA_Table({ myType, setEditId, tableInfo }: Props, ref: any) {
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
// 发送请求的数据
|
|
@@ -30,21 +34,18 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
pageNum: 1,
|
|
|
pageSize: 10,
|
|
|
searchKey: "",
|
|
|
- myType,
|
|
|
+ type: myType,
|
|
|
});
|
|
|
|
|
|
// 每次数据变化的时候发送请求
|
|
|
|
|
|
- const getListFu = useCallback(
|
|
|
- (data: any) => {
|
|
|
- if (myType === "custom") dispatch(A2_APIgetList(data));
|
|
|
- },
|
|
|
- [dispatch, myType]
|
|
|
- );
|
|
|
+ const getListFu = useCallback(() => {
|
|
|
+ if (myType === "national") dispatch(A2_APIgetList(getData));
|
|
|
+ }, [dispatch, getData, myType]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- getListFu(getData);
|
|
|
- }, [getData, getListFu]);
|
|
|
+ getListFu();
|
|
|
+ }, [getListFu]);
|
|
|
|
|
|
const [inputKey, setInputKey] = useState(1);
|
|
|
|
|
@@ -67,12 +68,26 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
pageNum: 1,
|
|
|
pageSize: 10,
|
|
|
searchKey: "",
|
|
|
- myType,
|
|
|
+ type: myType,
|
|
|
});
|
|
|
}, [myType]);
|
|
|
|
|
|
// 点击删除
|
|
|
- const delTableFu = useCallback((id: number) => {}, []);
|
|
|
+ const delTableFu = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ let resUrl = "block";
|
|
|
+
|
|
|
+ if (myType === "master") resUrl = "master";
|
|
|
+ else if (myType === "craft") resUrl = "craft";
|
|
|
+
|
|
|
+ const res = await A2_APIdel(id, resUrl);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
+ getListFu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [getListFu, myType]
|
|
|
+ );
|
|
|
|
|
|
// 页码变化
|
|
|
const paginationChange = useCallback(
|
|
@@ -82,7 +97,7 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
[getData]
|
|
|
);
|
|
|
const columns = useMemo(() => {
|
|
|
- return [
|
|
|
+ const arr: any = [
|
|
|
{
|
|
|
width: 100,
|
|
|
title: (
|
|
@@ -99,54 +114,74 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
index + 1 + (getData.pageNum - 1) * getData.pageSize,
|
|
|
},
|
|
|
{
|
|
|
- title: "账号名",
|
|
|
- dataIndex: "userName",
|
|
|
- },
|
|
|
- {
|
|
|
- title: "用户昵称",
|
|
|
- dataIndex: "nickName",
|
|
|
- },
|
|
|
-
|
|
|
- {
|
|
|
- title: "真实姓名",
|
|
|
- dataIndex: "realName",
|
|
|
- },
|
|
|
- {
|
|
|
- title: "注册时间",
|
|
|
- dataIndex: "createTime",
|
|
|
+ title: "标题",
|
|
|
+ dataIndex: "name",
|
|
|
},
|
|
|
+ ];
|
|
|
|
|
|
- {
|
|
|
- title: "操作",
|
|
|
+ if (myType !== "craft") {
|
|
|
+ arr.push({
|
|
|
+ title: "封面图",
|
|
|
render: (item: A2TableType) => (
|
|
|
+ <div className="tableImgAuto">
|
|
|
+ <ImageLazy width={60} height={60} src={item.thumb} />
|
|
|
+ </div>
|
|
|
+ ),
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ arr.push({
|
|
|
+ title: "正文",
|
|
|
+ render: (item: A2TableType) =>
|
|
|
+ item.content.length >= 50 ? (
|
|
|
+ <span style={{ cursor: "pointer" }} title={item.content}>
|
|
|
+ {item.content.substring(0, 50) + "..."}
|
|
|
+ </span>
|
|
|
+ ) : (
|
|
|
+ item.content
|
|
|
+ ),
|
|
|
+ });
|
|
|
+
|
|
|
+ arr.push({
|
|
|
+ title: "操作",
|
|
|
+ render: (item: A2TableType) => (
|
|
|
+ <>
|
|
|
<>
|
|
|
- <>
|
|
|
- <Button
|
|
|
- size="small"
|
|
|
- type="text"
|
|
|
- onClick={() => setEditId(item.id, false)}
|
|
|
- >
|
|
|
- 编辑
|
|
|
+ <Button
|
|
|
+ size="small"
|
|
|
+ type="text"
|
|
|
+ onClick={() => setEditId(item.id, true)}
|
|
|
+ >
|
|
|
+ 查看
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ size="small"
|
|
|
+ type="text"
|
|
|
+ onClick={() => setEditId(item.id, false)}
|
|
|
+ >
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+ <Popconfirm
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
+ okText="删除"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => delTableFu(item.id!)}
|
|
|
+ >
|
|
|
+ <Button size="small" type="text" danger>
|
|
|
+ 删除
|
|
|
</Button>
|
|
|
- <Popconfirm
|
|
|
- title="删除后无法恢复,是否删除?"
|
|
|
- okText="删除"
|
|
|
- cancelText="取消"
|
|
|
- onConfirm={() => delTableFu(item.id!)}
|
|
|
- >
|
|
|
- <Button size="small" type="text" danger>
|
|
|
- 删除
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- </>
|
|
|
+ </Popconfirm>
|
|
|
</>
|
|
|
- ),
|
|
|
- },
|
|
|
- ];
|
|
|
+ </>
|
|
|
+ ),
|
|
|
+ });
|
|
|
+
|
|
|
+ return arr;
|
|
|
}, [
|
|
|
delTableFu,
|
|
|
getData.pageNum,
|
|
|
getData.pageSize,
|
|
|
+ myType,
|
|
|
setEditId,
|
|
|
tableInfo.list.length,
|
|
|
]);
|
|
@@ -185,7 +220,6 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
};
|
|
|
},
|
|
|
drop: (item: { index: number }) => {
|
|
|
- console.log("pppppppppp", moveRow);
|
|
|
if (moveRow) moveRow(item.index, index);
|
|
|
},
|
|
|
});
|
|
@@ -223,17 +257,26 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
// 交互位置-之前的id
|
|
|
const beforeId = tableInfo.list[dragIndex].id;
|
|
|
const afterId = tableInfo.list[hoverIndex].id;
|
|
|
- console.log("交换位置", beforeId, afterId);
|
|
|
+ // console.log("交换位置", beforeId, afterId);
|
|
|
|
|
|
- const res = await A2_APIsort(beforeId, afterId);
|
|
|
+ let resUrl = "block";
|
|
|
|
|
|
- if (res.code === 0) {
|
|
|
- if (myType === "custom") dispatch(A2_APIgetList(getData));
|
|
|
- }
|
|
|
+ if (myType === "master") resUrl = "master";
|
|
|
+ else if (myType === "craft") resUrl = "craft";
|
|
|
+
|
|
|
+ const res = await A2_APIsort(beforeId, afterId, resUrl);
|
|
|
+
|
|
|
+ if (res.code === 0) getListFu();
|
|
|
},
|
|
|
- [dispatch, getData, myType, tableInfo.list]
|
|
|
+ [getListFu, myType, tableInfo.list]
|
|
|
);
|
|
|
|
|
|
+ // 可以让父组件调用子组件的方法
|
|
|
+ useImperativeHandle(ref, () => ({
|
|
|
+ getListFu,
|
|
|
+ resetSelectFu,
|
|
|
+ }));
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.ZA_Table}>
|
|
|
{/* 顶部搜索 */}
|
|
@@ -286,6 +329,6 @@ function ZA_Table({ myType, setEditId, tableInfo }: Props) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-const MemoZA_Table = React.memo(ZA_Table);
|
|
|
+// const MemoZA_Table = React.memo(ZA_Table);
|
|
|
|
|
|
-export default MemoZA_Table;
|
|
|
+export default forwardRef(ZA_Table);
|