Selaa lähdekoodia

fix: 增加单位角色模式、修复:清单模板移动操作

lanjianrong 3 vuotta sitten
vanhempi
commit
bffce705f0

+ 47 - 18
src/app.tsx

@@ -49,31 +49,60 @@ const authHeaderInterceptor = options => {
   return options
 }
 
-const errorHandler = response => {
-  if (consts.TOKEN_INVALID_CODE.includes(response.code) && window.location.pathname !== consts.loginPath) {
+const errorHandler = (error: any, opts: any) => {
+  if (opts?.skipErrorHandler) return
+
+  const errorInfo = error.info
+  if (errorInfo) {
+    const { errorMessage = '请求失败', errorCode } = errorInfo
+    if (errorCode.includes(response.code) && window.location.pathname !== consts.loginPath) {
+      notification.error({
+        message: '用户信息过期',
+        description: '请重新登录'
+      })
+      history.replace({
+        pathname: consts.loginPath,
+        search: createSearchParams({
+          redirect: window.location.pathname
+        }).toString()
+      })
+      return
+    }
+    notification.error({
+      message: title,
+      description: errorMessage
+    })
+  } else if (error.response) {
+    // Axios 的错误
+    // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
     notification.error({
-      message: '用户信息过期',
-      description: '请重新登录'
+      description: `状态码为${error.status}, 请联系管理员进行处理`,
+      message: '请求异常'
     })
-    history.replace({
-      pathname: consts.loginPath,
-      search: createSearchParams({
-        redirect: window.location.pathname
-      }).toString()
+  } else if (error.request) {
+    // 请求已经成功发起,但没有收到响应
+    // 或请求根本没有发送出去
+    notification.error({
+      description: '您的网络请求已经发起,但没有收到响应',
+      message: '响应超时'
+    })
+  } else {
+    notification.error({
+      description: '您的网络发生异常,无法连接服务器',
+      message: '网络异常'
     })
-    return
   }
-  notification.error({
-    message: '请求失败',
-    description: response.msg
-  })
-  return
 }
 
 const responseInterceptor = response => {
-  const { code = -1 } = response?.data || {}
-  if (code !== consts.RET_CODE.SUCCESS) {
-    return Promise.reject(response?.data)
+  const { data, code: errorCode, msg: errorMessage } = response.data
+  if (!errorCode || errorCode !== consts.RET_CODE.SUCCESS) {
+    if (errorCode !== consts.RET_CODE.SUCCESS) {
+      const error: any = new Error(errorMessage)
+      error.name = 'BizError'
+      error.info = { errorCode, errorMessage, data }
+      throw error
+    }
   }
   return Promise.resolve(response)
 }

+ 10 - 4
src/pages/Business/Inventory/index.tsx

@@ -140,7 +140,7 @@ const Inventory = () => {
                     size="small"
                     type="primary"
                     ghost
-                    disabled={!record?.moveable || record.position !== 'bottom'}
+                    disabled={!record?.moveable || record?.position === 'top'}
                     onClick={() => moveWithOperation('up')}>
                     上移
                   </Button>
@@ -149,7 +149,7 @@ const Inventory = () => {
                     size="small"
                     type="primary"
                     ghost
-                    disabled={!record?.moveable || record.position !== 'top'}
+                    disabled={!record?.moveable || record?.position === 'bottom'}
                     onClick={() => moveWithOperation('down')}>
                     下移
                   </Button>
@@ -158,7 +158,7 @@ const Inventory = () => {
                     size="small"
                     type="primary"
                     ghost
-                    disabled={!record?.folder && !record?.moveable}
+                    disabled={!record}
                     onClick={move}>
                     移动至
                   </Button>
@@ -172,7 +172,13 @@ const Inventory = () => {
             size="small"
             bordered
             expandable={{ defaultExpandAllRows: true }}
-            onRow={record => ({ onClick: () => rowClick(record) })}
+            onRow={record => ({
+              onClick: () => {
+                console.log(record)
+
+                rowClick(record)
+              }
+            })}
             rowClassName={row => (row.ID === record?.ID ? 'ant-table-row-selected' : '')}
           />
         )}

+ 32 - 19
src/pages/Project/Verification/Detail/Flow/components/Drawer/ParticipantCard.tsx

@@ -1,4 +1,4 @@
-import React, { useContext, useEffect, useMemo, useState } from 'react'
+import React, { useContext, useEffect, useState } from 'react'
 import { ApprovalWay, approvalWayConfigurationsEnum, ParticipantMode } from '../../enum'
 import { ConfigureType } from '../../enum'
 import { queryAccountList } from '@/services/api/institution'
@@ -47,6 +47,10 @@ const configureItemTitle = {
   }
 }
 
+interface iState {
+  configureArr: string[]
+  staffList: { label: string; value: string }[]
+}
 const ParticipantCard: React.FC<ParticipantCardProps> = ({
   approvalWay,
   updateAction,
@@ -58,7 +62,7 @@ const ParticipantCard: React.FC<ParticipantCardProps> = ({
   const curNode = elements.filter(item => isNode(item)).find(item => item.id === nodeID)
   const lastEdge = elements.filter(item => isEdge(item)).find(item => item.target === eId)
 
-  const [state, setState] = useState({
+  const [state, setState] = useState<iState>({
     configureArr: approvalWayConfigurationsEnum[approvalWay],
     staffList: []
   })
@@ -89,7 +93,12 @@ const ParticipantCard: React.FC<ParticipantCardProps> = ({
     ) {
       // 当前的node元素
       // 最后一个edge及诶单
-      if (lastEdge && curNode && lastEdge.source === curNode.id) {
+      if (
+        lastEdge &&
+        curNode &&
+        lastEdge.source === curNode.id &&
+        !state.configureArr.includes(ConfigureType.NEXTSECTOR)
+      ) {
         setState({ ...state, configureArr: [...state.configureArr, ConfigureType.NEXTSECTOR] })
       }
     }
@@ -103,8 +112,8 @@ const ParticipantCard: React.FC<ParticipantCardProps> = ({
             className="w-full"
             defaultValue={defaultData.participantMode}
             options={[
-              { label: '仅用户模式', value: ParticipantMode.ACCOUNT }
-              // { label: '角色模式', value: ParticipantMode.ROLE }
+              { label: '仅用户模式', value: ParticipantMode.ACCOUNT },
+              { label: '单位角色模式', value: ParticipantMode.ROLE }
             ]}
             onChange={value => {
               updateAction({ ...defaultData, participantMode: value })
@@ -114,24 +123,28 @@ const ParticipantCard: React.FC<ParticipantCardProps> = ({
         <div>
           <Select
             className="w-full"
-            defaultValue={defaultData.institutionID}
+            value={defaultData.institutionID}
             options={institutionList}
-            onChange={value => {
-              if (value) tryUpdateStaffList(value)
-              updateAction({ ...defaultData, institutionID: value })
-            }}
-          />
-        </div>
-        <div>
-          <Select
-            className="w-full"
-            defaultValue={defaultData.ID}
-            options={state.staffList}
-            onChange={(_, options) => {
-              updateAction({ ...defaultData, ID: options?.value, name: options?.label })
+            onChange={async value => {
+              if (value && defaultData.participantMode === ParticipantMode.ACCOUNT) {
+                await tryUpdateStaffList(value)
+              }
+              updateAction({ ...defaultData, institutionID: value, ID: null, name: null })
             }}
           />
         </div>
+        {defaultData.participantMode === ParticipantMode.ACCOUNT ? (
+          <div>
+            <Select
+              className="w-full"
+              value={defaultData.ID}
+              options={state.staffList}
+              onChange={(_, options) => {
+                updateAction({ ...defaultData, ID: options?.value, name: options?.label })
+              }}
+            />
+          </div>
+        ) : null}
       </div>
       <Collapse
         defaultActiveKey={['1']}

+ 2 - 9
src/pages/Project/Verification/Detail/Flow/components/Drawer/index.tsx

@@ -1,14 +1,8 @@
 import { useState, useEffect, useContext, useMemo } from 'react'
-import { Button, Drawer, message, Radio, Select, Tabs, Tooltip } from 'antd'
+import { Button, Drawer, message, Radio, Tabs, Tooltip } from 'antd'
 import { Actions, FlowContext } from '../../context'
 import type { RadioChangeEvent } from 'antd'
-import {
-  ApprovalWay,
-  approvalWayConfigurationsEnum,
-  ConfigureType,
-  ParticipantMode,
-  VoteOption
-} from '../../enum'
+import { ApprovalWay, approvalWayConfigurationsEnum, ParticipantMode } from '../../enum'
 import { QuestionCircleFilled } from '@ant-design/icons'
 import { queryInstitutionList } from '@/services/api/institution'
 import { buildUUID } from '@/utils/uuid'
@@ -26,7 +20,6 @@ const FlowDrawer = () => {
     loading: false,
     institutionList: [],
     approvalWay: ApprovalWay.ACCOUNT,
-    // voteWay: null, // 投票方式,仅会签模式下
     accounts: [],
     validityIDs: []
   })

+ 1 - 1
src/pages/Project/Verification/Detail/Flow/enum/index.ts

@@ -27,7 +27,7 @@ export enum ApprovalWay {
 export enum ParticipantMode {
   /** @name 用户模式 */
   ACCOUNT = 'account',
-  /** @name 角色模式 */
+  /** @name 单位角色模式 */
   ROLE = 'role'
 }