1/** 2 * Created by Liu.Jun on 2020/4/25 14:45. 3 */ 4 5 6// 内部使用 . ,配置数据key不能出现. 7const pathSeparator = '.'; 8 9// nodePath 转css类名 10export function nodePath2ClassName(path) { 11 const rootPathName = '__pathRoot'; 12 return path ? `${rootPathName}.${path}`.replace(/\./g, '_') : rootPathName; 13} 14 15// 是否为根节点 16export function isRootNodePath(path) { 17 return path === ''; 18} 19 20// 计算当前节点path 21export function computedCurPath(prePath, curKey) { 22 return prePath === '' ? curKey : [prePath, curKey].join(pathSeparator); 23} 24 25// 获取当前path值 26export function getPathVal(obj, path, leftDeviation = 0) { 27 const pathArr = path.split(pathSeparator); 28 29 for (let i = 0; i < pathArr.length - leftDeviation; i += 1) { 30 // 错误路径或者undefined中断查找 31 if (obj === undefined) return undefined; 32 obj = pathArr[i] === '' ? obj : obj[pathArr[i]]; 33 } 34 return obj; 35} 36 37// path 等于props 38export function path2prop(path) { 39 return path; 40} 41