lanjianrong 5 лет назад
Родитель
Сommit
9f6e020725

+ 4 - 2
src/components/Modal/src/index.js

@@ -1,14 +1,16 @@
+import type { ModalProps } from 'antd'
+import type { DraggerProps } from 'antd/lib/upload'
 import { useDispatch } from 'dva'
 
 export function useModal() {
   const dispath = useDispatch()
-  function setDrawerProps(options) {
+  function setDrawerProps(options: DraggerProps) {
     dispath({
       type: 'single/setProps',
       payload: { type: 'drawer', config: options }
     })
   }
-  function setModalProps(options) {
+  function setModalProps(options: ModalProps) {
     dispath({
       type: 'single/setProps',
       payload: { type: 'modal', config: options }

+ 59 - 9
src/components/ZHtable/src/BasicTable.tsx

@@ -1,17 +1,67 @@
-import type { MAIN_MENU_KEY } from '@/utils/cache/cacheEnum'
-import type { ProTableProps } from '@ant-design/pro-table'
+/* eslint-disable no-param-reassign */
+import type { MainMenuKeyEnum } from '@/utils/cache/cacheEnum'
+import type { ActionType, ColumnsState, ProTableProps } from '@ant-design/pro-table'
+import PermSelect from '@/pages/Customer/Company/components/PermSelect'
+import { TABLE_COLUMNS_MAP, ColumnStateEnum } from '@/utils/cache/cacheEnum'
+import { isNullOrUnDef } from '@/utils/is'
 import ProTable from '@ant-design/pro-table'
+import { useModel } from 'umi'
+import { getAuthCache, setAuthCache } from '@/utils/auth'
 
-interface BasicTableProps<T> extends ProTableProps {
-  dataType: T
+interface BasicTableProps<T, C>
+  extends Omit<
+    ProTableProps,
+    'actionRef' | 'headerTitle' | 'columnsStateMap' | 'onColumnsStateChange'
+  > {
+  /** @type 枚举表中的菜单常量 */
+  mainMenuType?: T
+  /** @type 枚举表中的表格列常量 */
+  columnStateType?: C
+  /** @name 左上角的 title */
+  headerTitle?: React.ReactNode
+  columnsStateMap?: Record<string, ColumnsState>
+  onColumnsStateChange?: (map: Record<string, ColumnsState>) => void
+  actionRef?: React.MutableRefObject<ActionType | undefined> | ((actionRef: ActionType) => void)
 }
 
-const BasicTable: React.FC<BasicTableProps<MAIN_MENU_KEY>> = ({ dataType, ...resetProps }) => {
-  // const proTableProps = { ...resetProps }
-  // if ('headerTitle' in resetProps) {
+const BasicTable: React.FC<BasicTableProps<MainMenuKeyEnum, ColumnStateEnum>> = ({
+  mainMenuType,
+  columnStateType,
+  columnsStateMap,
+  onColumnsStateChange,
+  ...resetProps
+}) => {
+  const {
+    initialState: { permData }
+  } = useModel('@@initialState')
+  if (isNullOrUnDef(permData)) return null
 
-  // }
-  return <ProTable {...resetProps} />
+  /** 增加头部 */
+  if (headerTitle && mainMenuType) {
+    resetProps.headerTitle = (
+      <>
+        <PermSelect />
+        {headerTitle}
+      </>
+    )
+  } else {
+    resetProps.headerTitle = headerTitle
+  }
+
+  // 处理列的本地化存储
+  const authColumnsStateMap = getAuthCache(TABLE_COLUMNS_MAP)
+  if (authColumnsStateMap && authColumnsStateMap[ColumnStateEnum[columnStateType]]) {
+    resetProps.columnsStateMap = authColumnsStateMap[ColumnStateEnum[columnStateType]]
+  } else {
+    resetProps.columnsStateMap = columnsStateMap
+  }
+
+  const handleOnColumnsChange = (map: Record<string, ColumnsState>) => {
+    onColumnsStateChange(map)
+    setAuthCache(TABLE_COLUMNS_MAP, { [ColumnStateEnum[columnStateType]]: map })
+  }
+
+  return <ProTable {...resetProps} onColumnsStateChange={handleOnColumnsChange} />
 }
 
 export default BasicTable

+ 26 - 2
src/utils/cache/cacheEnum.ts

@@ -14,9 +14,33 @@ export const CASCADER_HISTORY_KEY = 'CASCADER_HISTORY_KEY__'
 // permission select component key
 export const PERMISSION_SELECT_KEY = 'PERMISSION_SELECT_KEY'
 
-// permission select component defualtValue key
-export type MAIN_MENU_KEY = 'customer' | 'product' | 'workbench' | 'hr'
+// table columns map
+export const TABLE_COLUMNS_MAP = 'TABLE_COLUMNS_MAP'
 
+// permission select component defualtValue key
+export enum MainMenuKeyEnum {
+  /** @name 客户 */
+  CUSTOMER = 'customer',
+  /** @name 产品 */
+  PRODUCT = 'product',
+  /** @name 工作台 */
+  WORKBENCH = 'workbench',
+  /** @name 人资 */
+  HR = 'hr'
+}
+// single table columnsState enum
+export enum ColumnStateEnum {
+  /** @name 联系人 */
+  CLIENT = 'client',
+  /** @name 客户 */
+  COMPANY = 'company',
+  /** @name 商机 */
+  BUSINESS = 'business',
+  /** @name 公共锁库 */
+  LOCKSTORE = 'lockstore',
+  /** @name 部门与员工 */
+  EMPLOYEE = 'employee'
+}
 export enum CacheTypeEnum {
   SESSION,
   LOCAL

+ 4 - 2
src/utils/cache/persistent.ts

@@ -9,15 +9,17 @@ import {
   APP_SESSION_CACHE_KEY,
   CASCADER_HISTORY_KEY,
   PERMISSION_SELECT_KEY,
-  MAIN_MENU_KEY
+  MAIN_MENU_KEY,
+  TABLE_COLUMNS_MAP
 } from './cacheEnum'
 import { DEFAULT_CACHE_TIME } from '@/settings/encryptionSetting'
 import { pick, omit } from 'lodash-es'
 
 interface BasicStore {
   [TOKEN_KEY]: string | null | undefined
-  [CASCADER_HISTORY_KEY]: { key: string; value: string[]; label: string }[]
+  [CASCADER_HISTORY_KEY]: { key: string; value: string[]; label: string }[] | null | underfined
   [PERMISSION_SELECT_KEY]: { [key in MAIN_MENU_KEY]: string } | null | underfined
+  [TABLE_COLUMNS_MAP]: { [key in MAIN_MENU_KEY]: Record<string, ColumnsState> } | null | underfined
 }
 
 type LocalStore = BasicStore