import { GridProp } from '@/lib/types'; import { Store } from '@/lib/store'; import { Operator } from '@/lib/operator'; import { TREE_CHILDREN_KEY, TREE_EXPAND_KEY } from '@/lib/constants/default-props'; /** * 初始化 用户入参数,将其转化为索引优先的数据 * @param store * @param operator */ export const useInitialize = (store: Store, operator: Record) => { const layoutOperator = operator[Operator.layout]; const structureCalculator = operator[Operator.structureCalculator]; const initOuterSize = ( propHeight: number | string, propWidth: number | string, propRowHeight: number, ) => { layoutOperator.initLayoutSize(propHeight, propWidth, propRowHeight); }; const calculateDataAndInnerSize = (props: Readonly) => { structureCalculator.initTableStore(props); }; const addResizeMonitor = () => { layoutOperator.initResizeMonitor(); }; // TODO 抽象到 Operator const syncFeature = (props: Partial) => { if (props.idKey) { store.mutation.setIdKey(props.idKey); } // 同步树功能 if (!props.isTree) { store.mutation.setTreeFuture({ active: false, }); } else { store.mutation.setTreeFuture({ active: true, expandKey: props.expandKey || TREE_EXPAND_KEY, childrenKey: props.childrenKey || TREE_CHILDREN_KEY, defaultExpand: props.defaultExpand || true, }); } if (!props.rowSelection) { store.mutation.setRowSelectionFuture({ active: false, }); } else { store.mutation.setRowSelectionFuture({ active: true, render: props.rowSelection.render, display: props.rowSelection.display || (() => true), disabled: props.rowSelection.disabled || (() => false), }); } if (!props.showIndex) { store.mutation.setRowIndexFuture({ active: false, }); } else { store.mutation.setRowIndexFuture({ active: true, }); } if (!props.totalBar?.totalCount) { store.mutation.setTotalBarFuture({ active: false, }); } else { store.mutation.setTotalBarFuture({ active: true, totalCount: props.totalBar?.totalCount || false, }); } }; return { syncFeature, initOuterSize, calculateDataAndInnerSize, addResizeMonitor, }; };