shaogen1995 пре 7 часа
родитељ
комит
4a30abc4b9
3 измењених фајлова са 61 додато и 19 уклоњено
  1. 24 18
      src/pages/Abench/A2bench/A2table/index.tsx
  2. 31 0
      src/store/reducer/ZformData.ts
  3. 6 1
      src/store/reducer/index.ts

+ 24 - 18
src/pages/Abench/A2bench/A2table/index.tsx

@@ -10,6 +10,8 @@ import { authorityFu, tableListAuditBtnFu } from '@/utils/authority'
 import history from '@/utils/history'
 import { selectObj } from '@/utils/dataChange'
 import { GI5tableC } from '@/utils/tableData'
+import { useSelector } from 'react-redux'
+import store, { RootState } from '@/store'
 
 const { RangePicker } = DatePicker
 
@@ -30,21 +32,21 @@ function A2table() {
     return arr
   }, [])
 
-  const [formData, setFormData] = useState({
-    pageNum: 1,
-    pageSize: 10,
-    auditType: '1',
-    type: '',
-    num: '',
-    startTime: '',
-    endTime: '',
-    status: ''
-  })
+  const [formData, setFormData] = useState({} as any)
+
+  // 回调页面的时候 回显参数
+  const A2formData = useSelector((state: RootState) => state.ZformData.A2formData)
+
+  useEffect(() => {
+    setFormData({ ...A2formData })
+  }, [A2formData])
 
   const getListFu = useCallback(async () => {
-    const res = await A2_APIgetList(formData)
-    if (res.code === 0) {
-      setTableObj({ list: res.data.records || [], total: res.data.total })
+    if (formData.pageNum) {
+      const res = await A2_APIgetList(formData)
+      if (res.code === 0) {
+        setTableObj({ list: res.data.records || [], total: res.data.total })
+      }
     }
   }, [formData])
 
@@ -95,11 +97,15 @@ function A2table() {
     total: 0
   })
 
-  const btnFu = useCallback((pageKey: '3' | '4', obj: any, id: number) => {
-    if (obj) {
-      authorityFu(obj.id, obj.name, () => history.push(`${obj.path}_edit/${pageKey}/${id}`))
-    } else MessageFu.warning('业务类型错误')
-  }, [])
+  const btnFu = useCallback(
+    (pageKey: '3' | '4', obj: any, id: number) => {
+      if (obj) {
+        store.dispatch({ type: 'ZF/A2formData', payload: formData })
+        authorityFu(obj.id, obj.name, () => history.push(`${obj.path}_edit/${pageKey}/${id}`))
+      } else MessageFu.warning('业务类型错误')
+    },
+    [formData]
+  )
 
   const tableLastBtn = useMemo(() => {
     return [

+ 31 - 0
src/store/reducer/ZformData.ts

@@ -0,0 +1,31 @@
+// 初始化状态
+const initState = {
+  // 列表筛选回显
+  A2formData: {
+    pageNum: 1,
+    pageSize: 10,
+    auditType: '1',
+    type: '',
+    num: '',
+    startTime: '',
+    endTime: '',
+    status: ''
+  } as any
+}
+
+// 定义 action 类型
+type Props = {
+  type: 'ZF/A2formData'
+  payload: any
+}
+
+// reducer
+export default function Reducer(state = initState, action: Props) {
+  switch (action.type) {
+    case 'ZF/A2formData':
+      return { ...state, A2formData: action.payload }
+
+    default:
+      return state
+  }
+}

+ 6 - 1
src/store/reducer/index.ts

@@ -28,6 +28,9 @@ import I6role from './Isystem/I6role'
 import I7user from './Isystem/I7user'
 import I8log from './Isystem/I8log'
 
+// 所有列表回调需要保存当前筛选数据
+import ZformData from './ZformData'
+
 // 合并 reducer
 const rootReducer = combineReducers({
   A0Layout,
@@ -56,7 +59,9 @@ const rootReducer = combineReducers({
   I5organization,
   I6role,
   I7user,
-  I8log
+  I8log,
+
+  ZformData
 })
 
 // 默认导出