import { getFieldValue, isArray } from '@cip/utils/util' import { sizeCellConfig } from './config' export const analyseData = (list = [], treeProps, count = 0, parentPath = []) => { return list.reduce((acc, item, index) => { const path = parentPath.concat(index) acc[count] = path count++ const children = getFieldValue(item, treeProps.children) if (isArray(children)) { const indexed = analyseData(children, treeProps, count, path) acc = Object.assign(acc, indexed) count += Object.keys(indexed).length } return acc }, {}) } export const getPropertyKeyByPath = (path, treeProps) => { const { children } = treeProps return path.join(`.${children}.`) } // 根据标准和当前大小计算转换系数 export const calculateCurrentWidth = (size = 'default', standardSize = 'default', width) => { // 宽度 = 字体宽度 + padding if (size === standardSize) return width const standardConfig = sizeCellConfig[standardSize] const x = (width - standardConfig.padding * 2) / standardConfig.fontSize const currentConfig = sizeCellConfig[size] return x * currentConfig.fontSize + currentConfig.padding * 2 }