浏览代码

fix: 优化业务审批部分逻辑

lanjianrong 2 年之前
父节点
当前提交
6acbec93e4
共有 3 个文件被更改,包括 170 次插入114 次删除
  1. 5 3
      config/config.ts
  2. 77 55
      src/pages/Business/Inventory/index.tsx
  3. 88 56
      src/pages/Business/Process/index.tsx

+ 5 - 3
config/config.ts

@@ -1,12 +1,13 @@
 // https://umijs.org/config/
 
-const prodGzipList = ['js', 'css', 'html']
-
 import { defineConfig } from '@umijs/max'
 import defaultSettings from './defaultSettings'
 import proxy from './proxy'
 import routes from './routes'
+
 const { REACT_APP_ENV } = process.env
+const prodGzipList = ['js', 'css', 'html']
+
 export default defineConfig({
   plugins: [require.resolve('@umijs/plugins/dist/unocss')],
   npmClient: 'pnpm',
@@ -19,7 +20,7 @@ export default defineConfig({
   access: {},
   dva: {},
   srcTranspiler: 'esbuild',
-  mfsu: {},
+  mfsu: { esbuild: true },
   fastRefresh: true,
   unocss: {
     watch: ['src/pages/**/*.{jsx,tsx,less}', 'src/components/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
@@ -27,6 +28,7 @@ export default defineConfig({
   // Fast Refresh 热更新
   theme: {},
   layout: {},
+  // clickToComponent: {},
   locale: {
     default: 'zh-CN',
     antd: false,

+ 77 - 55
src/pages/Business/Inventory/index.tsx

@@ -6,10 +6,11 @@ import {
   EditOutlined,
   FileAddOutlined,
   FolderAddOutlined,
-  SelectOutlined
+  SelectOutlined,
+  DownOutlined
 } from '@ant-design/icons'
 import { PageContainer } from '@ant-design/pro-layout'
-import { Button, Table } from 'antd'
+import { Button, Dropdown, Table, Menu, Space } from 'antd'
 import { ColumnsType } from 'antd/lib/table'
 import { useRowScript } from './hooks/useRowScript'
 
@@ -17,6 +18,12 @@ export enum TemplateMode {
   PAPER = 'paper',
   UPLOAD = 'upload'
 }
+const items = [
+  {
+    key: '1',
+    label: '预算业务表单'
+  }
+]
 
 const Inventory = () => {
   const contentHeight = document.body.clientHeight - 122
@@ -33,6 +40,7 @@ const Inventory = () => {
     deleteFolderOrFile,
     moveWithOperation
   } = useRowScript(modal)
+
   const columns: ColumnsType<API.ProfileTemplateItem> = [
     {
       title: '目录文件名称',
@@ -87,62 +95,76 @@ const Inventory = () => {
   return (
     <PageContainer title={false}>
       <div style={{ height: `${contentHeight}px` }} className="bg-white">
-        <div className="children:mx-1 px-1 py-2">
-          <Button icon={<FolderAddOutlined />} size="small" type="primary" ghost onClick={addFolder}>
-            新建目录
-          </Button>
-          <Button icon={<FileAddOutlined />} size="small" type="primary" ghost onClick={addFile}>
-            新建文件
-          </Button>
-          <Button
-            icon={<EditOutlined />}
-            size="small"
-            type="primary"
-            ghost
-            onClick={editFolder}
-            disabled={!record}>
-            编辑
-          </Button>
-          <Button
-            icon={<DeleteOutlined />}
-            size="small"
-            type="primary"
-            ghost
-            onClick={deleteFolderOrFile}
-            disabled={!record}>
-            删除
-          </Button>
-          <Button
-            icon={<ArrowUpOutlined />}
-            size="small"
-            type="primary"
-            ghost
-            disabled={!record?.moveable || record.position !== 'bottom'}
-            onClick={() => moveWithOperation('up')}>
-            上移
-          </Button>
-          <Button
-            icon={<ArrowDownOutlined />}
-            size="small"
-            type="primary"
-            ghost
-            disabled={!record?.moveable || record.position !== 'top'}
-            onClick={() => moveWithOperation('down')}>
-            下移
-          </Button>
-          <Button
-            icon={<SelectOutlined />}
-            size="small"
-            type="primary"
-            ghost
-            disabled={!record?.folder && !record?.moveable}
-            onClick={move}>
-            移动至
-          </Button>
-        </div>
         {list?.length && (
           <Table
             rowKey="ID"
+            title={() => (
+              <div className="ml-2 flex flex-nowrap justify-start items-center">
+                <Dropdown
+                  overlay={<Menu selectable defaultSelectedKeys={['1']} items={items} />}
+                  trigger={['click']}>
+                  <div className="font-bold cursor-pointer">
+                    <Space>
+                      {items[0].label}
+                      <DownOutlined />
+                    </Space>
+                  </div>
+                </Dropdown>
+                <div className="children:mx-1 px-1 py-2 ml-5">
+                  <Button icon={<FolderAddOutlined />} size="small" type="primary" ghost onClick={addFolder}>
+                    新建目录
+                  </Button>
+                  <Button icon={<FileAddOutlined />} size="small" type="primary" ghost onClick={addFile}>
+                    新建文件
+                  </Button>
+                  <Button
+                    icon={<EditOutlined />}
+                    size="small"
+                    type="primary"
+                    ghost
+                    onClick={editFolder}
+                    disabled={!record}>
+                    编辑
+                  </Button>
+                  <Button
+                    icon={<DeleteOutlined />}
+                    size="small"
+                    type="primary"
+                    ghost
+                    onClick={deleteFolderOrFile}
+                    disabled={!record}>
+                    删除
+                  </Button>
+                  <Button
+                    icon={<ArrowUpOutlined />}
+                    size="small"
+                    type="primary"
+                    ghost
+                    disabled={!record?.moveable || record.position !== 'bottom'}
+                    onClick={() => moveWithOperation('up')}>
+                    上移
+                  </Button>
+                  <Button
+                    icon={<ArrowDownOutlined />}
+                    size="small"
+                    type="primary"
+                    ghost
+                    disabled={!record?.moveable || record.position !== 'top'}
+                    onClick={() => moveWithOperation('down')}>
+                    下移
+                  </Button>
+                  <Button
+                    icon={<SelectOutlined />}
+                    size="small"
+                    type="primary"
+                    ghost
+                    disabled={!record?.folder && !record?.moveable}
+                    onClick={move}>
+                    移动至
+                  </Button>
+                </div>
+              </div>
+            )}
             loading={loading}
             columns={columns}
             dataSource={list}

+ 88 - 56
src/pages/Business/Process/index.tsx

@@ -40,6 +40,8 @@ type iProcessProps = {
   approvalAccountDetail: API.ApprovalAccountDetail[]
 }
 
+let cacheKeys: string[] = []
+
 const Process: React.FC = props => {
   const { institutionList } = props
   const dispatch = useDispatch()
@@ -48,8 +50,7 @@ const Process: React.FC = props => {
     approvalAccountDetail: null
   })
 
-  const {} = useRequest(queryApprovalAccountDetail, {
-    // manual: true,
+  useRequest(queryApprovalAccountDetail, {
     onSuccess: (result: API.ApprovalAccountDetail) => {
       setState({
         ...state,
@@ -66,16 +67,6 @@ const Process: React.FC = props => {
     }
   })
 
-  const { run: trysaveApprovalAccount } = useRequest(
-    (params: Partial<API.UpdateRoleParams>) => saveApprovalAccount(params),
-    {
-      manual: true,
-      onSuccess: () => {
-        message.success('编辑成功')
-      }
-    }
-  )
-
   const renderTreeNodes = data =>
     data.map(item => {
       const newItem = { ...item }
@@ -90,7 +81,8 @@ const Process: React.FC = props => {
   useEffect(() => {
     if (!institutionList.length) {
       dispatch({
-        type: 'business/queryInstitution'
+        type: 'business/queryInstitution',
+        payload: { pageSize: 214000 }
       })
     }
     // tryApprovalAccountDetail()
@@ -109,15 +101,23 @@ const Process: React.FC = props => {
           return
         }
         // 收件人企事业id
-        const institutionID = field.value
-        if (institutionID) {
-          const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
-          if (code === consts.RET_CODE.SUCCESS) {
-            form.setFieldState('receiver.receiverAccountIDs', field => {
+        const institutionID: undefined | string = field.value
+        institutionID &&
+          form.setFieldState('receiver.receiverAccountIDs', async field => {
+            const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
+            if (code === consts.RET_CODE.SUCCESS) {
+              if (cacheKeys.some((key: string) => key.startsWith('receiver_'))) {
+                // 说明当前企事业id已变,需要将当前field的value置空
+                field.value = []
+                cacheKeys = cacheKeys
+                  .filter(item => item.startsWith('receiver_'))
+                  .concat(`receiver_${institutionID}`)
+              } else {
+                cacheKeys = cacheKeys.concat(`receiver_${institutionID}`)
+              }
               field.dataSource = renderTreeNodes(data)
-            })
-          }
-        }
+            }
+          })
       })
       onFieldReact('fgLeader.fgLeaderInstitutionID', async field => {
         if (!field.dataSource?.length) {
@@ -127,60 +127,90 @@ const Process: React.FC = props => {
           }))
           return
         }
-        const institutionID = field.value
-        if (institutionID) {
-          const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
-          if (code === consts.RET_CODE.SUCCESS) {
-            form.setFieldState('fgLeader.fgLeaderAccountIDs', field => {
+        const institutionID: undefined | string = field.value
+        institutionID &&
+          form.setFieldState('fgLeader.fgLeaderAccountIDs', async field => {
+            const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
+            if (code === consts.RET_CODE.SUCCESS) {
+              if (cacheKeys.some((key: string) => key.startsWith('fgLeader_'))) {
+                // 说明当前企事业id已变,需要将当前field的value置空
+                field.value = []
+                cacheKeys = cacheKeys
+                  .filter(item => item.startsWith('fgLeader_'))
+                  .concat(`fgLeader_${institutionID}`)
+              } else {
+                cacheKeys = cacheKeys.concat(`fgLeader_${institutionID}`)
+              }
+
               field.dataSource = renderTreeNodes(data)
-            })
-          }
-        }
+            }
+          })
       })
       onFieldReact('zxLeader.zxLeaderInstitutionID', async field => {
         if (!field.dataSource?.length) {
           field.dataSource = institutionList?.items?.map(item => ({ value: item.ID, label: item.name }))
           return
         }
-        const institutionID = field.value
-        if (institutionID) {
-          const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
-          if (code === consts.RET_CODE.SUCCESS) {
-            form.setFieldState('zxLeader.zxLeaderAccountIDs', field => {
+        const institutionID: undefined | string = field.value
+        institutionID &&
+          form.setFieldState('zxLeader.zxLeaderAccountIDs', async field => {
+            const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
+            if (code === consts.RET_CODE.SUCCESS) {
               field.dataSource = renderTreeNodes(data)
-            })
-          }
-        }
+              if (cacheKeys.some((key: string) => key.startsWith('zxLeader_'))) {
+                // 说明当前企事业id已变,需要将当前field的value置空
+                field.value = []
+                cacheKeys = cacheKeys
+                  .filter(item => item.startsWith('zxLeader_'))
+                  .concat(`zxLeader_${institutionID}`)
+              } else {
+                cacheKeys = cacheKeys.concat(`zxLeader_${institutionID}`)
+              }
+            }
+          })
       })
       onFieldReact('post.postInstitutionID', async field => {
         if (!field.dataSource?.length) {
           field.dataSource = institutionList?.items?.map(item => ({ value: item.ID, label: item.name }))
           return
         }
-        const institutionID = field.value
-        if (institutionID) {
-          const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
-          if (code === consts.RET_CODE.SUCCESS) {
-            form.setFieldState('post.postAccountIDs', field => {
+        const institutionID: undefined | string = field.value
+        institutionID &&
+          form.setFieldState('post.postAccountIDs', async field => {
+            const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
+            if (code === consts.RET_CODE.SUCCESS) {
+              if (cacheKeys.some((key: string) => key.startsWith('post_'))) {
+                // 说明当前企事业id已变,需要将当前field的value置空
+                field.value = []
+                cacheKeys = cacheKeys.filter(item => item.startsWith('post_')).concat(`post_${institutionID}`)
+              }
+              cacheKeys = cacheKeys.concat(`post_${institutionID}`)
               field.dataSource = renderTreeNodes(data)
-            })
-          }
-        }
+            }
+          })
       })
       onFieldReact('archive.archiveInstitutionID', async field => {
         if (!field.dataSource?.length) {
           field.dataSource = institutionList?.items?.map(item => ({ value: item.ID, label: item.name }))
           return
         }
-        const institutionID = field.value
-        if (institutionID) {
-          const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
-          if (code === consts.RET_CODE.SUCCESS) {
-            form.setFieldState('archive.archiveAccountIDs', field => {
+        const institutionID: undefined | string = field.value
+        institutionID &&
+          form.setFieldState('archive.archiveAccountIDs', async field => {
+            const { code = -1, data } = await queryOrganizationalMembersList({ institutionID })
+            if (code === consts.RET_CODE.SUCCESS) {
+              if (cacheKeys.some((key: string) => key.startsWith('archive_'))) {
+                // 说明当前企事业id已变,需要将当前field的value置空
+                field.value = []
+                cacheKeys = cacheKeys
+                  .filter(item => item.startsWith('archive_'))
+                  .concat(`archive_${institutionID}`)
+              } else {
+                cacheKeys = cacheKeys.concat(`archive_${institutionID}`)
+              }
               field.dataSource = renderTreeNodes(data)
-            })
-          }
-        }
+            }
+          })
       })
     }
   })
@@ -203,14 +233,16 @@ const Process: React.FC = props => {
     }
   })
 
-  const onFinish = (values: Record<string, any>) => {
+  const onFinish = async (values: Record<string, any>) => {
     const keys = Object.keys(values)
     const params = keys.reduce((prev, curr) => {
       const obj = { ...prev, ...values[curr] }
       return obj
     }, {})
-
-    trysaveApprovalAccount(params)
+    const { code = -1 } = await saveApprovalAccount(params)
+    if (code === consts.RET_CODE.SUCCESS) {
+      message.success('编辑成功')
+    }
   }
   return (
     <PageContainer title={false}>