소스 검색

refactor: 审核资料清单模板优化

outaozhen 2 년 전
부모
커밋
60f6277032

+ 19 - 10
src/pages/Business/Inventory/hooks/useRowScript.tsx

@@ -66,23 +66,29 @@ function formatTreeNode(nodes: API.ProfileTemplateItem[], ID?: string, PID?: str
   })
 }
 
-export function useRowScript(modal: ModalAction) {
+export function useRowScript(modal: ModalAction, dataID: string) {
   const [state, setState] = useState<IState>({})
   const {
     run: query,
     refresh,
     loading
-  } = useRequest(queryProfileTemplateList, {
-    manual: true,
-    onSuccess: (result?: API.ProfileTemplateItem[]) => {
-      setState({ ...state, list: formatTreeTable(result) || [], record: null })
+  } = useRequest(
+    () => {
+      const [gatherID, businessType] = dataID.split('_')
+      return queryProfileTemplateList({ gatherID, businessType, pageSize: 214000 })
+    },
+    {
+      manual: true,
+      onSuccess: (result?: API.ProfileTemplateItem[]) => {
+        setState({ ...state, list: formatTreeTable(result) || [], record: null })
+      }
     }
-  })
+  )
 
   const handleRowClick = (record: API.ProfileTemplateItem) => setState({ ...state, record })
 
   /** 新建目录 */
-  const addFolder = subjectParams => {
+  const addFolder = () => {
     modal.open({
       title: '新建目录',
       okText: '确认',
@@ -101,7 +107,8 @@ export function useRowScript(modal: ModalAction) {
         </ProForm>
       ),
       onOk: async (values: { name: string; parentID: string }) => {
-        const { code = -1 } = await createTemplateFolder({ ...values, ...subjectParams })
+        const [gatherID, businessType] = dataID.split('_')
+        const { code = -1 } = await createTemplateFolder({ ...values, gatherID, businessType })
         if (code === consts.RET_CODE.SUCCESS) {
           message.success('新建目录成功')
           modal.close()
@@ -136,7 +143,7 @@ export function useRowScript(modal: ModalAction) {
   }
 
   /** 新建文件 */
-  const addFile = (mode?: 'add' | 'update', subjectParams) => {
+  const addFile = (mode?: 'add' | 'update') => {
     modal.open({
       title: mode === 'add' ? '新增文件' : '编辑文件',
       okText: '确认',
@@ -191,9 +198,11 @@ export function useRowScript(modal: ModalAction) {
         </ProForm>
       ),
       onOk: async (values: any) => {
+        const [gatherID, businessType] = dataID.split('_')
         const { code = -1 } = await saveTemplateFile({
           ...values,
-          ...subjectParams,
+          gatherID,
+          businessType,
           required: !!values.required,
           enable: !!values.enable
         })

+ 13 - 22
src/pages/Business/Inventory/index.tsx

@@ -16,29 +16,16 @@ import {
 } from '@ant-design/icons'
 import LeftMenu from '../RuleCode/components/LeftMenu'
 import ProTable from '@ant-design/pro-table'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
 import styles from './index.less'
 
 export enum TemplateMode {
   PAPER = 'paper',
   UPLOAD = 'upload'
 }
-
-interface IState {
-  subjectParams: {
-    gatherID?: Nullable<string>
-    businessType?: Nullable<string>
-  }
-}
-
 const Inventory = () => {
   const [modal, ModalDOM] = useModal()
-  const [state, setState] = useState<IState>({
-    subjectParams: {
-      gatherID: '',
-      businessType: ''
-    }
-  })
+  const [activeKey, setActivekey] = useState<Nullable<string>>(null)
   const {
     query,
     loading,
@@ -51,7 +38,13 @@ const Inventory = () => {
     editFolder,
     deleteFolderOrFile,
     moveWithOperation
-  } = useRowScript(modal)
+  } = useRowScript(modal, activeKey)
+
+  useEffect(() => {
+    if (activeKey) {
+      query()
+    }
+  }, [activeKey])
 
   const columns: ColumnsType<API.ProfileTemplateItem> = [
     {
@@ -111,9 +104,7 @@ const Inventory = () => {
   ]
 
   const handleMenuOnChange = (key: string) => {
-    const [gatherID, businessType] = key.split('_')
-    query({ gatherID, businessType })
-    setState({ ...state, subjectParams: { ...state.subjectParams, gatherID, businessType } })
+    setActivekey(key)
   }
   return (
     <PageContainer title={false}>
@@ -132,7 +123,7 @@ const Inventory = () => {
                     size="small"
                     type="primary"
                     ghost
-                    onClick={() => addFolder(state.subjectParams)}>
+                    onClick={() => addFolder()}>
                     新建目录
                   </Button>
                   <Button
@@ -140,7 +131,7 @@ const Inventory = () => {
                     size="small"
                     type="primary"
                     ghost
-                    onClick={() => addFile('add', state.subjectParams)}>
+                    onClick={() => addFile('add')}>
                     新建文件
                   </Button>
                   <Button
@@ -150,7 +141,7 @@ const Inventory = () => {
                     ghost
                     onClick={() => {
                       record?.folder && editFolder()
-                      !record?.folder && addFile('update', state.subjectParams)
+                      !record?.folder && addFile('update')
                     }}
                     disabled={!record}>
                     编辑

+ 2 - 2
src/pages/Business/Matter/hooks/useRowScript.tsx

@@ -50,13 +50,13 @@ export function useRowScript(modal: ModalAction, dataID: string) {
   const handleRowClick = (record: API.MatterTreeItem) => setState({ ...state, record })
 
   /** 新建 */
-  const add = (mode: MatterType.CATEGORY | MatterType.MATTER, record) => {
+  const add = (mode: MatterType.CATEGORY | MatterType.MATTER) => {
     const text = mode === MatterType.CATEGORY ? '新建分类' : '新建事项'
     modal.open({
       title: text,
       okText: '确定',
       cancelText: '取消',
-      initialValues: { parentID: record?.parentID || record?.ID },
+      initialValues: { parentID: state.record?.parentID || state.record?.ID },
       type: 'form',
       children: (
         <ProForm submitter={false} layout="horizontal" labelCol={{ span: 5 }} isKeyPressSubmit>

+ 1 - 1
src/pages/Business/Matter/index.tsx

@@ -110,7 +110,7 @@ const Matter: React.FC = () => {
                   <Button size="small" type="primary" ghost onClick={() => add(MatterType.CATEGORY)}>
                     新建分类
                   </Button>
-                  <Button size="small" type="primary" ghost onClick={() => add(MatterType.MATTER, record)}>
+                  <Button size="small" type="primary" ghost onClick={() => add(MatterType.MATTER)}>
                     新建事项
                   </Button>
                 </div>