-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from mice33/master
feat: 分离公共 Vue 工具 js
- Loading branch information
Showing
4 changed files
with
41 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 内部使用 . ,配置数据key不能出现. | ||
export const pathSeparator = '.'; | ||
|
||
// nodePath 转css类名 | ||
export function nodePath2ClassName(path) { | ||
const rootPathName = '__pathRoot'; | ||
return path ? `${rootPathName}.${path}`.replace(/\./g, '_') : rootPathName; | ||
} | ||
|
||
// 是否为根节点 | ||
export function isRootNodePath(path) { | ||
return path === ''; | ||
} | ||
|
||
// 计算当前节点path | ||
export function computedCurPath(prePath, curKey) { | ||
return prePath === '' ? curKey : [prePath, curKey].join(pathSeparator); | ||
} | ||
|
||
// 获取当前path值 | ||
export function getPathVal(obj, path, leftDeviation = 0) { | ||
const pathArr = path.split(pathSeparator); | ||
|
||
for (let i = 0; i < pathArr.length - leftDeviation; i += 1) { | ||
// 错误路径或者undefined中断查找 | ||
if (obj === undefined) return undefined; | ||
obj = pathArr[i] === '' ? obj : obj[pathArr[i]]; | ||
} | ||
return obj; | ||
} | ||
|
||
// path 等于props | ||
export function path2prop(path) { | ||
return path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters