Sfoglia il codice sorgente

feat: 将BasicTable应用于客户栏目

lanjianrong 5 anni fa
parent
commit
333431a3b9

+ 4 - 2
src/components/Table/src/BasicTable.tsx

@@ -47,6 +47,8 @@ const BasicTable: {
   }
   const tableElRef = useRef<HTMLElement>(null)
 
+  console.log('params', params)
+
   const [state, setState] = useState({
     selectKeysRef: null,
     sizeRef: 'middle',
@@ -114,7 +116,7 @@ const BasicTable: {
 
   const handleOnSizeChange = (size: DensitySize) => {
     if (onSizeChange) onSizeChange(size)
-    setState({ ...state, size })
+    setState({ ...state, sizeRef: size })
   }
 
   const rowSelectionOptions = useMemo(() => {
@@ -141,7 +143,7 @@ const BasicTable: {
       <ProTable
         {...resetProps}
         columns={columns}
-        params={state.params}
+        params={{ ...params, ...state.params }}
         columnsStateMap={state.columnsStateMap}
         onColumnsStateChange={handleOnColumnsChange}
         scroll={getScrollRef}

+ 1 - 0
src/components/Table/src/hooks/useTableScroll.ts

@@ -50,6 +50,7 @@ export function useTableScroll(
     let headerHeight = 0
     if (headEl) {
       headerHeight = headEl.offsetHeight
+      console.log('headerHeight', headerHeight)
     }
     const height = bottomIncludeBody - paddingHeight - paginationHeight - headerHeight
 

+ 10 - 3
src/pages/Customer/Client/index.jsx

@@ -449,23 +449,30 @@ const Client = props => {
 
   // 批量设置-确认触发
   const tagsSettingConfirm = async clientIds => {
+    let requestSuccess = true
     if (tagState.tagIds.length) {
-      await apiBatchLink({
+      const { code = -1 } = await apiBatchLink({
         tagIds: tagState.tagIds,
         dataIds: clientIds,
         dataType: TagDataTypeEnum.CLIENT,
         tagType: TagTypeEnum.PERSONTAG
       })
+      if (code !== consts.RET_CODE.SUCCESS) {
+        requestSuccess = false
+      }
     }
     if (tagState.tagCooperationIds.length) {
-      await apiBatchLink({
+      const { code = -1 } = await apiBatchLink({
         tagIds: tagState.tagCooperationIds,
         dataIds: clientIds,
         dataType: TagDataTypeEnum.CLIENT,
         tagType: TagTypeEnum.TEAMTAG
       })
+      if (code !== consts.RET_CODE.SUCCESS) {
+        requestSuccess = false
+      }
     }
-    refreshData()
+    requestSuccess && refreshData()
   }
 
   // 处理权限Select下拉组件OnChange事件

+ 17 - 37
src/pages/Customer/Company/index.jsx

@@ -1,6 +1,4 @@
 import React, { useState, useEffect, useRef, useMemo } from 'react'
-import ProTable from '@ant-design/pro-table'
-import { useTableScroll } from '@/hooks/useAutoTable'
 import { Input, Button, message, Tooltip } from 'antd'
 import { connect, useModel } from 'umi'
 import consts from '@/consts'
@@ -16,8 +14,8 @@ import { Add, Down, Check } from '@icon-park/react'
 import { apiBatchLink } from '@/services/customer'
 import styles from './index.less'
 import { refactorSortField } from '@/utils/utils'
-import PermSelect from './components/PermSelect'
 import { PermDataTypeEunm } from './components/PermSelect'
+import BasicTable from '@/components/Table'
 
 const Company = props => {
   const {
@@ -35,12 +33,12 @@ const Company = props => {
 
   const { toggleDrawer, setDrawerProps } = useModal()
   const tRef = useRef(null)
-  const [selectKeys, setSelectKeys] = useState([])
 
   const [tagState, setTagState] = useState({
     tagIds: [],
     tagCooperationIds: []
   })
+
   const tag = useMemo(() => {
     const personTagMap = {}
     const teamTagMap = {}
@@ -89,9 +87,7 @@ const Company = props => {
   }, [loading])
 
   const [state, setState] = useState({
-    id: '',
-    params: { dataPermission: 'oneself', staffIds: null },
-    visible: false,
+    params: {},
     orderIds: []
   })
 
@@ -323,7 +319,7 @@ const Company = props => {
       width: 80
     }
   ]
-  const [columnsStateMap, setColumnsStateMap] = useState({
+  const columnsStateMap = {
     address: {
       show: false
     },
@@ -351,46 +347,38 @@ const Company = props => {
     staffName: {
       show: false
     }
-  })
-
-  const hanleRowSelectChange = selectedRowKeys => {
-    setSelectKeys(selectedRowKeys)
   }
 
   const toolbarOptionsChange = (type, ids) => {
     setTagState({ ...tagState, [type]: ids })
   }
 
-  const { getScrollRef, redoHeight } = useTableScroll(columns, selectKeys)
-
   // 批量设置-确认触发
   const tagsSettingConfirm = async clientIds => {
+    let requestSuccess = true
     if (tagState.tagIds.length) {
-      await apiBatchLink({
+      const { code = -1 } = await apiBatchLink({
         tagIds: tagState.tagIds,
         dataIds: clientIds,
         dataType: TagDataTypeEnum.COMPANY,
         tagType: TagTypeEnum.PERSONTAG
       })
+      if (code !== consts.RET_CODE.SUCCESS) {
+        requestSuccess = false
+      }
     }
     if (tagState.tagCooperationIds.length) {
-      await apiBatchLink({
+      const { code = -1 } = await apiBatchLink({
         tagIds: tagState.tagCooperationIds,
         dataIds: clientIds,
         dataType: TagDataTypeEnum.COMPANY,
         tagType: TagTypeEnum.TEAMTAG
       })
+      if (code !== consts.RET_CODE.SUCCESS) {
+        requestSuccess = false
+      }
     }
-    refreshData()
-  }
-
-  // 处理权限Select下拉组件OnChange事件
-  const handlePermChange = ({ staffIds = [], dataPermission }) => {
-    if (staffIds?.length) {
-      setState({ ...state, params: { ...state.params, staffIds, dataPermission: null } })
-      return
-    }
-    setState({ ...state, params: { ...state.params, staffIds: null, dataPermission } })
+    requestSuccess && refreshData()
   }
 
   const renderTableAlert = ({ selectedRowKeys }) => {
@@ -456,9 +444,11 @@ const Company = props => {
 
   return (
     <div className={styles.companyContent}>
-      <ProTable
+      <BasicTable
         rowKey={record => record.id}
         actionRef={tRef}
+        mainMenuType="customer"
+        columnStateType="COMPANY"
         params={state.params}
         request={async (params, sort, filter) => {
           const srotOrder = refactorSortField(sort)
@@ -471,7 +461,6 @@ const Company = props => {
             total
           }
         }}
-        bordered
         search={{ filterType: 'light' }}
         toolbar={{
           search: (
@@ -504,21 +493,12 @@ const Company = props => {
             />
           ]
         }}
-        headerTitle={
-          <PermSelect onConfirm={handlePermChange} dataType={PermDataTypeEunm.CUSTOMER} />
-        }
         rowSelection={{
-          onChange: hanleRowSelectChange,
           type: 'checkbox',
           columnWidth: 25
         }}
-        onLoadingChange={loadingStatus => {
-          loadingStatus && redoHeight()
-        }}
         tableAlertRender={renderTableAlert}
-        scroll={getScrollRef}
         columnsStateMap={columnsStateMap}
-        onColumnsStateChange={map => setColumnsStateMap(map)}
         columns={columns}
       />
     </div>

+ 1 - 1
src/pages/workbench/Dashboard/components/RatioPanels.jsx

@@ -119,7 +119,7 @@ const ServiceRatioPanels = ({ staffIds, cyclical, dataPermission }) => {
       params={{ dataType: state.activeKey, cyclical, dataPermission, staffIds }}
       rowKey={record => record.id}
       scroll={{ y: 400 }}
-      border={true}
+      bordered={true}
       columns={columns}
       search={false}
       toolbar={{