Skip to content

Commit

Permalink
Merge pull request #318 from mice33/master
Browse files Browse the repository at this point in the history
feat: 分离公共 Vue 工具 js
  • Loading branch information
lljj-x authored Sep 9, 2023
2 parents 637b4b1 + a42ffb8 commit bb508de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/lib/utils/formUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import retrieveSchema from './schema/retriev';
import { getPathVal } from './vueUtils';
import { getPathVal } from './vueCommonUtils';

import { getSchemaType, isObject } from './utils';

Expand Down
7 changes: 2 additions & 5 deletions packages/lib/utils/vue3Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import { defineComponent, h, resolveComponent as _resolveComponent } from 'vue';

export {
nodePath2ClassName, isRootNodePath, computedCurPath, getPathVal, path2prop
} from './vueUtils';

// 内部使用 . ,配置数据key不能出现.
const pathSeparator = '.';
nodePath2ClassName, isRootNodePath, computedCurPath, getPathVal, path2prop, pathSeparator
} from './vueCommonUtils';

// 删除当前path值
export function deletePathVal(vueData, name) {
Expand Down
35 changes: 35 additions & 0 deletions packages/lib/utils/vueCommonUtils.js
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;
}
38 changes: 3 additions & 35 deletions packages/lib/utils/vueUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,9 @@

import Vue from 'vue';

// 内部使用 . ,配置数据key不能出现.
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);
}
export {
nodePath2ClassName, isRootNodePath, computedCurPath, getPathVal, path2prop, pathSeparator
} from './vueCommonUtils';

// 删除当前path值
export function deletePathVal(vueData, name) {
Expand All @@ -42,20 +27,3 @@ export function setPathVal(obj, path, value) {
obj = obj[pathArr[i]];
}
}

// 获取当前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;
}

0 comments on commit bb508de

Please sign in to comment.