|
@@ -0,0 +1,72 @@
|
|
|
|
+import { useLocalStorageState, useMount, useSetState } from "ahooks";
|
|
|
|
+import React, { useState } from "react"
|
|
|
|
+
|
|
|
|
+const log = (text?: any, key?: string) => {
|
|
|
|
+ console.log(`pro_${key || ''}----->`, text)
|
|
|
|
+}
|
|
|
|
+export const DispatchContext = React.createContext<{} | null>(null);
|
|
|
|
+export const version = '1.0.0'
|
|
|
|
+/**
|
|
|
|
+ * 升级版表格
|
|
|
|
+ * @returns
|
|
|
|
+ */
|
|
|
|
+const TablePro: React.FC<PROAPI.TableProProps> = ({
|
|
|
|
+ configName,
|
|
|
|
+ config,
|
|
|
|
+ fixed = { left: 0, right: 1 }
|
|
|
|
+}) => {
|
|
|
|
+
|
|
|
|
+ /*********************************************/
|
|
|
|
+ const [lsDataSource, setLsDataSource] = useLocalStorageState(`myAdMonitorConfig${version}_` + configName);
|
|
|
|
+ const [lsFixed, setLsFixed] = useLocalStorageState(`myAdMonitorConfigFixed${version}_` + configName);
|
|
|
|
+ const [state, setState] = useSetState<PROAPI.State>({
|
|
|
|
+ configObj: {},
|
|
|
|
+ columns: [],
|
|
|
|
+ defaultColumns: []
|
|
|
|
+ });
|
|
|
|
+ // const { configObj, columns, defaultColumns } = state
|
|
|
|
+ /*********************************************/
|
|
|
|
+
|
|
|
|
+ // 首次渲染
|
|
|
|
+ useMount(() => {
|
|
|
|
+ log('----mount-----')
|
|
|
|
+ handleConfig()
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理config成对象 减少后期轮询
|
|
|
|
+ * 拿到默认Columns
|
|
|
|
+ */
|
|
|
|
+ const handleConfig = () => {
|
|
|
|
+ // log(config)
|
|
|
|
+ let newColumns: any[] = []
|
|
|
|
+ let newConfigObj: { [key: string]: any; } = {}
|
|
|
|
+ config?.forEach((item: { data: { default: any; dataIndex: string }[] }) => {
|
|
|
|
+ item?.data?.forEach((d: { default: any, dataIndex: string }) => {
|
|
|
|
+ newConfigObj[d.dataIndex] = d
|
|
|
|
+ if (d.default) {
|
|
|
|
+ newColumns[d.default - 1] = d
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ setState({ defaultColumns: newColumns, configObj: newConfigObj })
|
|
|
|
+ handleColumns(newColumns, newConfigObj)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 处理columns
|
|
|
|
+ const handleColumns = (defaultColumns: any[], configObj: { [key: string]: string; }) => {
|
|
|
|
+ log(defaultColumns, 'defaultColumns')
|
|
|
|
+ log(configObj, 'configObj')
|
|
|
|
+ if (lsDataSource) { // 找到了设置的配置
|
|
|
|
+
|
|
|
|
+ } else { // 使用默认配置
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return <DispatchContext.Provider value={{}}></DispatchContext.Provider>
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export default React.memo(TablePro)
|