|
@@ -2,7 +2,10 @@ import BreadTit from "@/components/BreadTit";
|
|
|
import classNames from "classnames";
|
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
-import { Select, Input, DatePicker } from "antd";
|
|
|
+import { Select, Input, DatePicker, Table } from "antd";
|
|
|
+import AuthButton from "@/components/AuthButton";
|
|
|
+import history from "@/utils/history";
|
|
|
+import { useLocation } from "react-router-dom";
|
|
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
@@ -19,9 +22,23 @@ export default function Object1() {
|
|
|
|
|
|
// 封装发送请求的函数
|
|
|
const getList = () => {
|
|
|
- console.log("------", tableSelect);
|
|
|
+ const data = { ...tableSelect, pageNum: pageNumRef.current };
|
|
|
+ console.log("------", data);
|
|
|
};
|
|
|
|
|
|
+ // 获取地址栏参数
|
|
|
+ const location = useLocation();
|
|
|
+
|
|
|
+ const pageNumRef = useRef(1);
|
|
|
+
|
|
|
+ // 如果有参数 根据参数页码在次发送请求
|
|
|
+ useEffect(() => {
|
|
|
+ const urlParam = location.state || {};
|
|
|
+ if (urlParam.k && urlParam.k !== "1")
|
|
|
+ setTableSelect({ ...tableSelect, pageNum: Number(urlParam.k) });
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
+ }, [location]);
|
|
|
+
|
|
|
// 顶部筛选
|
|
|
const [tableSelect, setTableSelect] = useState({
|
|
|
state: 1,
|
|
@@ -30,9 +47,14 @@ export default function Object1() {
|
|
|
staTime: "",
|
|
|
endTime: "",
|
|
|
pageSize: 10,
|
|
|
- paseNum: 1,
|
|
|
+ pageNum: 1,
|
|
|
});
|
|
|
|
|
|
+ // 当前页码统一
|
|
|
+ useEffect(() => {
|
|
|
+ pageNumRef.current = tableSelect.pageNum;
|
|
|
+ }, [tableSelect.pageNum]);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
getList();
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -40,7 +62,7 @@ export default function Object1() {
|
|
|
|
|
|
// 藏品来源下拉框筛选
|
|
|
const handleChange = (value: string) => {
|
|
|
- setTableSelect({ ...tableSelect, laiyuan: value, paseNum: 1 });
|
|
|
+ setTableSelect({ ...tableSelect, laiyuan: value, pageNum: 1 });
|
|
|
};
|
|
|
|
|
|
// 单位或个人输入
|
|
@@ -48,7 +70,7 @@ export default function Object1() {
|
|
|
const nameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
clearTimeout(nameTime.current);
|
|
|
nameTime.current = window.setTimeout(() => {
|
|
|
- setTableSelect({ ...tableSelect, name: e.target.value, paseNum: 1 });
|
|
|
+ setTableSelect({ ...tableSelect, name: e.target.value, pageNum: 1 });
|
|
|
}, 500);
|
|
|
};
|
|
|
|
|
@@ -60,9 +82,75 @@ export default function Object1() {
|
|
|
staTime = dateString[0] + " 00:00:00";
|
|
|
endTime = dateString[1] + " 23:59:59";
|
|
|
}
|
|
|
- setTableSelect({ ...tableSelect, staTime, endTime, paseNum: 1 });
|
|
|
+ setTableSelect({ ...tableSelect, staTime, endTime, pageNum: 1 });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 点击新增或者编辑按钮
|
|
|
+ const addObject = (id?: any) => {
|
|
|
+ if (id) history.push(`/object/1/add?k=${pageNumRef.current}&id=${id}`);
|
|
|
+ else history.push(`/object/1/add?k=${pageNumRef.current}`);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 关于表格的数据
|
|
|
+ const paginationChange = (pageNum: number, pageSize: number) => {
|
|
|
+ setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
+ };
|
|
|
+
|
|
|
+ const results = {
|
|
|
+ list: [
|
|
|
+ { name: "666-1", id: 1 },
|
|
|
+ { name: "666-2", id: 2 },
|
|
|
+ { name: "666-3", id: 3 },
|
|
|
+ { name: "666-4", id: 4 },
|
|
|
+ { name: "666-5", id: 5 },
|
|
|
+ { name: "666-6", id: 6 },
|
|
|
+ { name: "666-7", id: 7 },
|
|
|
+ { name: "666-8", id: 8 },
|
|
|
+ { name: "666-9", id: 9 },
|
|
|
+ { name: "666-10", id: 10 },
|
|
|
+ { name: "666-11", id: 11 },
|
|
|
+ { name: "666-12", id: 12 },
|
|
|
+ { name: "666-13", id: 13 },
|
|
|
+ { name: "666-14", id: 14 },
|
|
|
+ { name: "666-15", id: 15 },
|
|
|
+ { name: "666-16", id: 16 },
|
|
|
+ { name: "666-17", id: 17 },
|
|
|
+ { name: "666-18", id: 18 },
|
|
|
+ { name: "666-19", id: 19 },
|
|
|
+ { name: "666-20", id: 20 },
|
|
|
+ { name: "666-21", id: 21 },
|
|
|
+ { name: "666-22", id: 22 },
|
|
|
+ { name: "666-23", id: 23 },
|
|
|
+ ],
|
|
|
+ total: 23,
|
|
|
};
|
|
|
|
|
|
+ const columns = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: "标题",
|
|
|
+ dataIndex: "name",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: any) => (
|
|
|
+ <>
|
|
|
+ <AuthButton type="text" danger>
|
|
|
+ 查看
|
|
|
+ </AuthButton>
|
|
|
+ <AuthButton type="text" danger onClick={() => addObject(item.id)}>
|
|
|
+ 编辑
|
|
|
+ </AuthButton>
|
|
|
+ <AuthButton type="text" danger>
|
|
|
+ 删除
|
|
|
+ </AuthButton>
|
|
|
+ </>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
+ }, []);
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.Object1}>
|
|
|
<div className="breadTit">
|
|
@@ -77,7 +165,7 @@ export default function Object1() {
|
|
|
<div
|
|
|
key={v.id}
|
|
|
onClick={() =>
|
|
|
- setTableSelect({ ...tableSelect, state: v.id, paseNum: 1 })
|
|
|
+ setTableSelect({ ...tableSelect, state: v.id, pageNum: 1 })
|
|
|
}
|
|
|
className={classNames(v.id === tableSelect.state ? "active" : "")}
|
|
|
>
|
|
@@ -117,9 +205,29 @@ export default function Object1() {
|
|
|
<RangePicker onChange={timeChange} />
|
|
|
</div>
|
|
|
<div className="row">
|
|
|
-
|
|
|
+ <AuthButton type="primary" onClick={() => addObject()}>
|
|
|
+ 新增
|
|
|
+ </AuthButton>
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <div className="tableMain">
|
|
|
+ <Table
|
|
|
+ scroll={{ y: 428 }}
|
|
|
+ dataSource={results.list}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={{
|
|
|
+ position: ["bottomCenter"],
|
|
|
+ showSizeChanger: true,
|
|
|
+ current: tableSelect.pageNum,
|
|
|
+ pageSize: tableSelect.pageSize,
|
|
|
+ total: results.total,
|
|
|
+ onChange: paginationChange,
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|