|
@@ -1,20 +1,22 @@
|
|
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
|
/* eslint-disable no-param-reassign */
|
|
/* eslint-disable no-param-reassign */
|
|
|
-import React, { useRef, useState, useMemo } from 'react'
|
|
|
|
|
|
|
+import ProTable from '@ant-design/pro-table'
|
|
|
import PermSelect from '@/pages/Customer/Company/components/PermSelect'
|
|
import PermSelect from '@/pages/Customer/Company/components/PermSelect'
|
|
|
|
|
+import { useRef, useState, useMemo } from 'react'
|
|
|
import { TABLE_COLUMNS_MAP, ColumnStateEnum } from '@/utils/cache/cacheEnum'
|
|
import { TABLE_COLUMNS_MAP, ColumnStateEnum } from '@/utils/cache/cacheEnum'
|
|
|
import { isBoolean, isMobile, isNullOrUnDef, isObject, isUnDef } from '@/utils/is'
|
|
import { isBoolean, isMobile, isNullOrUnDef, isObject, isUnDef } from '@/utils/is'
|
|
|
-import ProTable from '@ant-design/pro-table'
|
|
|
|
|
import { useModel } from '@umijs/max'
|
|
import { useModel } from '@umijs/max'
|
|
|
import { getAuthCache, getPermAuthCache, setAuthCache } from '@/utils/auth'
|
|
import { getAuthCache, getPermAuthCache, setAuthCache } from '@/utils/auth'
|
|
|
import { useTableScroll } from './hooks/useTableScroll'
|
|
import { useTableScroll } from './hooks/useTableScroll'
|
|
|
|
|
+import { useMemoizedFn, useUpdateLayoutEffect } from 'ahooks'
|
|
|
|
|
+import transformRequestParams from './share'
|
|
|
|
|
+
|
|
|
import type { ColumnsState } from '@ant-design/pro-table'
|
|
import type { ColumnsState } from '@ant-design/pro-table'
|
|
|
import type { BasicTableProps, PermStateEnum } from '@/types/typing'
|
|
import type { BasicTableProps, PermStateEnum } from '@/types/typing'
|
|
|
import type { ParamsType } from '@ant-design/pro-provider'
|
|
import type { ParamsType } from '@ant-design/pro-provider'
|
|
|
import type { DensitySize } from '@ant-design/pro-table/lib/components/ToolBar/DensityIcon'
|
|
import type { DensitySize } from '@ant-design/pro-table/lib/components/ToolBar/DensityIcon'
|
|
|
|
|
|
|
|
import styles from './index.less'
|
|
import styles from './index.less'
|
|
|
-import { useMemoizedFn, useUpdateLayoutEffect } from 'ahooks'
|
|
|
|
|
|
|
|
|
|
const BasicTable: {
|
|
const BasicTable: {
|
|
|
<T extends Record<string, any>, U extends ParamsType = ParamsType, ValueType = 'text'>(
|
|
<T extends Record<string, any>, U extends ParamsType = ParamsType, ValueType = 'text'>(
|
|
@@ -36,6 +38,7 @@ const BasicTable: {
|
|
|
bordered,
|
|
bordered,
|
|
|
rowSelection,
|
|
rowSelection,
|
|
|
onLoad,
|
|
onLoad,
|
|
|
|
|
+ onRequestError,
|
|
|
revalidateOnFocus = false,
|
|
revalidateOnFocus = false,
|
|
|
...resetProps
|
|
...resetProps
|
|
|
}) => {
|
|
}) => {
|
|
@@ -79,7 +82,7 @@ const BasicTable: {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
useUpdateLayoutEffect(() => {
|
|
useUpdateLayoutEffect(() => {
|
|
|
- state.dataSource && redoHeight(state.dataSource)
|
|
|
|
|
|
|
+ state.dataSource && redoHeight(state.dataSource)
|
|
|
}, [state.dataSource])
|
|
}, [state.dataSource])
|
|
|
|
|
|
|
|
/** 增加头部 */
|
|
/** 增加头部 */
|
|
@@ -143,18 +146,21 @@ const BasicTable: {
|
|
|
|
|
|
|
|
const computedParams = mainMenuType ? { ...params, ...state.params } : params
|
|
const computedParams = mainMenuType ? { ...params, ...state.params } : params
|
|
|
|
|
|
|
|
- const _request = useMemoizedFn(
|
|
|
|
|
- async (_params, _sort, _filter) => {
|
|
|
|
|
- if (isUnDef(request)) return undefined
|
|
|
|
|
- const result = await request(_params, _sort, _filter)
|
|
|
|
|
- if (!isBoolean(result?.success)) {
|
|
|
|
|
- result.success = true
|
|
|
|
|
- } else if (!result?.success) result.success = true
|
|
|
|
|
- if (!Array.isArray(result?.data)) result.data = []
|
|
|
|
|
- return result
|
|
|
|
|
- },
|
|
|
|
|
- [request]
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ const _request = useMemoizedFn(async (_params, _sort, _filter) => {
|
|
|
|
|
+ if (isUnDef(request)) return undefined
|
|
|
|
|
+ const result = await request(transformRequestParams(_params, _sort, _filter))
|
|
|
|
|
+ if (!isBoolean(result?.success)) {
|
|
|
|
|
+ result.success = true
|
|
|
|
|
+ } else if (!result?.success) result.success = true
|
|
|
|
|
+ if (!Array.isArray(result?.data)) result.data = []
|
|
|
|
|
+ return result
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: 让redoHeight逻辑执行需要一次set
|
|
|
|
|
+ const _onRequestError = useMemoizedFn((e: Error) => {
|
|
|
|
|
+ onRequestError?.(e)
|
|
|
|
|
+ setState({ ...state, dataSource: [] })
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
const _onLoad = useMemoizedFn(_dataSource => {
|
|
const _onLoad = useMemoizedFn(_dataSource => {
|
|
|
onLoad?.(_dataSource)
|
|
onLoad?.(_dataSource)
|
|
@@ -166,30 +172,29 @@ const BasicTable: {
|
|
|
if (Reflect.has(resetProps, 'dataSource')) {
|
|
if (Reflect.has(resetProps, 'dataSource')) {
|
|
|
setState({ ...state, dataSource: resetProps.dataSource })
|
|
setState({ ...state, dataSource: resetProps.dataSource })
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }, [])
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <React.StrictMode>
|
|
|
|
|
- <div ref={tableElRef} className={styles.BasicTable}>
|
|
|
|
|
- <ProTable
|
|
|
|
|
- {...resetProps}
|
|
|
|
|
- rowKey={rowKey || 'id'}
|
|
|
|
|
- columns={originalColumns}
|
|
|
|
|
- params={computedParams}
|
|
|
|
|
- scroll={getScrollRef}
|
|
|
|
|
- request={_request}
|
|
|
|
|
- columnsState={{
|
|
|
|
|
- defaultValue: state.columnsStateMap,
|
|
|
|
|
- onChange: handleOnColumnsChange
|
|
|
|
|
- }}
|
|
|
|
|
- bordered={isNullOrUnDef(bordered) ? bordered : true}
|
|
|
|
|
- onLoad={_onLoad}
|
|
|
|
|
- onSizeChange={handleOnSizeChange}
|
|
|
|
|
- rowSelection={rowSelectionOptions}
|
|
|
|
|
- revalidateOnFocus={revalidateOnFocus}
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
- </React.StrictMode>
|
|
|
|
|
|
|
+ <div ref={tableElRef} className={styles.BasicTable}>
|
|
|
|
|
+ <ProTable
|
|
|
|
|
+ {...resetProps}
|
|
|
|
|
+ rowKey={rowKey || 'id'}
|
|
|
|
|
+ columns={originalColumns}
|
|
|
|
|
+ params={computedParams}
|
|
|
|
|
+ scroll={getScrollRef}
|
|
|
|
|
+ request={_request}
|
|
|
|
|
+ columnsState={{
|
|
|
|
|
+ defaultValue: state.columnsStateMap,
|
|
|
|
|
+ onChange: handleOnColumnsChange
|
|
|
|
|
+ }}
|
|
|
|
|
+ bordered={isNullOrUnDef(bordered) ? bordered : true}
|
|
|
|
|
+ onLoad={_onLoad}
|
|
|
|
|
+ onSizeChange={handleOnSizeChange}
|
|
|
|
|
+ onRequestError={_onRequestError}
|
|
|
|
|
+ rowSelection={rowSelectionOptions}
|
|
|
|
|
+ revalidateOnFocus={revalidateOnFocus}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|