|
|
@@ -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
|