|
@@ -41,7 +41,7 @@ const TablePro: React.FC<PROAPI.TableProProps> = ({
|
|
|
}) => {
|
|
|
|
|
|
/*********************************************/
|
|
|
- const [lsDataSource, setLsDataSource] = useLocalStorageState(`myAdMonitorConfig${version}_` + configName);
|
|
|
+ const [lsDataSource, setLsDataSource] = useLocalStorageState<PROAPI.ColumnsTypePro<any>>(`myAdMonitorConfig${version}_` + configName);
|
|
|
const [lsFixed] = useLocalStorageState<{ left: number, right: number }>(`myAdMonitorConfigFixed${version}_` + configName);
|
|
|
const [state, setState] = useSetState<PROAPI.State>({
|
|
|
// 所有配置用key转Object
|
|
@@ -69,29 +69,29 @@ const TablePro: React.FC<PROAPI.TableProProps> = ({
|
|
|
*/
|
|
|
const handleConfig = () => {
|
|
|
// log(config)
|
|
|
- let newColumns: any[] = []
|
|
|
- let newConfigObj: { [key: string]: any; } = {}
|
|
|
+ let newColumns: PROAPI.ColumnsTypePro<any> = []
|
|
|
+ let newConfigObj: { [key: string]: PROAPI.ColumnTypePro<any>; } = {}
|
|
|
config?.forEach((item: { data: { default: any; dataIndex: string }[] }) => {
|
|
|
item?.data?.forEach((d: { default: any, dataIndex: string }) => {
|
|
|
- newConfigObj[d.dataIndex] = d
|
|
|
+ newConfigObj[d.dataIndex] = { ...d }
|
|
|
if (d.default) {
|
|
|
newColumns[d.default - 1] = d
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
- setState({ defaultColumns: newColumns, configObj: JSON.parse(JSON.stringify(newConfigObj)) })
|
|
|
+ setState({ defaultColumns: newColumns, configObj: newConfigObj })
|
|
|
handleColumns(newColumns, newConfigObj, lsDataSource, lsFixed)
|
|
|
}
|
|
|
|
|
|
// 处理columns
|
|
|
- const handleColumns = (defaultColumns: any[], configObj: { [key: string]: string; }, lsDataSource?: any, lsFixed?: { left: number, right: number }) => {
|
|
|
- log(defaultColumns, 'defaultColumns')
|
|
|
- log(configObj, 'configObj')
|
|
|
- log(lsDataSource, 'lsDataSource')
|
|
|
+ const handleColumns = (defaultColumns: PROAPI.ColumnsTypePro<any>, configObj: { [key: string]: PROAPI.ColumnTypePro<any>; }, lsDataSource?: PROAPI.ColumnsTypePro<any>, lsFixed?: { left: number, right: number }) => {
|
|
|
+ // log(defaultColumns, 'defaultColumns')
|
|
|
+ // log(configObj, 'configObj')
|
|
|
+ // log(lsDataSource, 'lsDataSource')
|
|
|
|
|
|
// 使用默认配置
|
|
|
- let newColumns = defaultColumns
|
|
|
- let newFixed = fixed
|
|
|
+ let newColumns: PROAPI.ColumnsTypePro<any> = defaultColumns
|
|
|
+ let newFixed: { left: number, right: number } = fixed
|
|
|
if (lsFixed) {
|
|
|
newFixed = lsFixed
|
|
|
}
|
|
@@ -99,12 +99,12 @@ const TablePro: React.FC<PROAPI.TableProProps> = ({
|
|
|
newColumns = lsDataSource
|
|
|
.filter((item: { dataIndex: string | number; }) => !!item && configObj[item.dataIndex])
|
|
|
.map((item: { dataIndex: string | number; width: number }) => {
|
|
|
- let column = configObj[item.dataIndex]
|
|
|
+ let column = { ...configObj[item.dataIndex] }
|
|
|
column['width'] = item.width
|
|
|
return column
|
|
|
})
|
|
|
}
|
|
|
- log(newFixed, 'newFixed')
|
|
|
+ // log(newFixed, 'newFixed')
|
|
|
newColumns = newColumns.map(item => {
|
|
|
if (item?.tips && typeof item.title === 'string') {
|
|
|
let column: any = configObj[item.dataIndex]
|
|
@@ -126,7 +126,7 @@ const TablePro: React.FC<PROAPI.TableProProps> = ({
|
|
|
newColumns[i] = { ...newColumns[i], fixed: 'right' };
|
|
|
}
|
|
|
}
|
|
|
- log(newColumns, 'newColumns')
|
|
|
+ // log(newColumns, 'newColumns')
|
|
|
setState({ columns: newColumns })
|
|
|
}
|
|
|
|
|
@@ -158,16 +158,19 @@ const TablePro: React.FC<PROAPI.TableProProps> = ({
|
|
|
|
|
|
const { run: runResize } = useDebounceFn((columns) => {
|
|
|
if (configName) {
|
|
|
- let newSelectData = state.columns?.map((item, index) => {
|
|
|
- item['width'] = columns[index]['width']
|
|
|
- return item
|
|
|
+ let newSelectData: PROAPI.ColumnsTypePro<any> = []
|
|
|
+ state.columns?.forEach((item, index) => {
|
|
|
+ newSelectData.push({ ...JSON.parse(JSON.stringify(state.configObj[item.dataIndex])), width: columns[index]['width'] })
|
|
|
})
|
|
|
setLsDataSource(newSelectData)
|
|
|
+ if (isZj) { // 有总计需要刷新内容表格
|
|
|
+ handleColumns(state.defaultColumns, state.configObj, newSelectData, lsFixed)
|
|
|
+ }
|
|
|
}
|
|
|
}, { wait: 200 });
|
|
|
|
|
|
//拖动宽度设置设置保存
|
|
|
- const handelResize = useCallback((columns: any) => {
|
|
|
+ const handelResize = useCallback((columns: PROAPI.ColumnTypePro<any>) => {
|
|
|
runResize(columns)
|
|
|
}, [configName, state.columns])
|
|
|
|