|
@@ -1,4 +1,4 @@
|
|
|
-import { RootState } from "@/store";
|
|
|
|
|
|
|
+import store, { RootState } from "@/store";
|
|
|
import { MessageFu } from "@/utils/message";
|
|
import { MessageFu } from "@/utils/message";
|
|
|
import { Button, Input, Select } from "antd";
|
|
import { Button, Input, Select } from "antd";
|
|
|
import React, {
|
|
import React, {
|
|
@@ -57,6 +57,9 @@ function News() {
|
|
|
// 点击重置
|
|
// 点击重置
|
|
|
const [inputKey, setInputKey] = useState(1);
|
|
const [inputKey, setInputKey] = useState(1);
|
|
|
const resetSelectFu = useCallback(() => {
|
|
const resetSelectFu = useCallback(() => {
|
|
|
|
|
+ // 新增成功把表格滚动到顶部
|
|
|
|
|
+ store.dispatch({ type: "news/setSroolNum", payload: 0 });
|
|
|
|
|
+
|
|
|
// 把2个输入框和时间选择器清空
|
|
// 把2个输入框和时间选择器清空
|
|
|
setInputKey(Date.now());
|
|
setInputKey(Date.now());
|
|
|
setTableSelect({
|
|
setTableSelect({
|
|
@@ -76,16 +79,16 @@ function News() {
|
|
|
(state: RootState) => state.newsReducer.tableInfo
|
|
(state: RootState) => state.newsReducer.tableInfo
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const scrollRef = useRef(0);
|
|
|
|
|
-
|
|
|
|
|
// 点击新增或者编辑
|
|
// 点击新增或者编辑
|
|
|
const addInfoFu = useCallback(
|
|
const addInfoFu = useCallback(
|
|
|
- (id: number, num?: number) => {
|
|
|
|
|
|
|
+ (id: number) => {
|
|
|
if (id === -1 && results.length >= 50)
|
|
if (id === -1 && results.length >= 50)
|
|
|
return MessageFu.warning("最多可录入50条信息!");
|
|
return MessageFu.warning("最多可录入50条信息!");
|
|
|
- // 点击的是编辑,把滚动距离存起来
|
|
|
|
|
- if (id !== -1) scrollRef.current = num!;
|
|
|
|
|
- else scrollRef.current = 0;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const dom: any = document.querySelector("#NewsTable .ant-table-body");
|
|
|
|
|
+ // 设置当前表格滚动位置
|
|
|
|
|
+ store.dispatch({ type: "news/setSroolNum", payload: dom.scrollTop });
|
|
|
|
|
+
|
|
|
setEditId(id);
|
|
setEditId(id);
|
|
|
},
|
|
},
|
|
|
[results.length]
|
|
[results.length]
|
|
@@ -154,9 +157,8 @@ function News() {
|
|
|
/>
|
|
/>
|
|
|
) : (
|
|
) : (
|
|
|
<NewsTable
|
|
<NewsTable
|
|
|
- sroolNum={scrollRef.current}
|
|
|
|
|
tableType={tableSelect.type}
|
|
tableType={tableSelect.type}
|
|
|
- editInfoFu={(id, num) => addInfoFu(id, num)}
|
|
|
|
|
|
|
+ editInfoFu={(id) => addInfoFu(id)}
|
|
|
/>
|
|
/>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|