diff --git a/packages/lib/utils/formUtils.js b/packages/lib/utils/formUtils.js index 632f64a7..bb65986a 100644 --- a/packages/lib/utils/formUtils.js +++ b/packages/lib/utils/formUtils.js @@ -1,5 +1,5 @@ import retrieveSchema from './schema/retriev'; -import { getPathVal } from './vueUtils'; +import { getPathVal } from './vueCommonUtils'; import { getSchemaType, isObject } from './utils'; diff --git a/packages/lib/utils/vue3Utils.js b/packages/lib/utils/vue3Utils.js index 189ac246..61a305a8 100644 --- a/packages/lib/utils/vue3Utils.js +++ b/packages/lib/utils/vue3Utils.js @@ -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) { diff --git a/packages/lib/utils/vueCommonUtils.js b/packages/lib/utils/vueCommonUtils.js new file mode 100644 index 00000000..e8796e7a --- /dev/null +++ b/packages/lib/utils/vueCommonUtils.js @@ -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; +} diff --git a/packages/lib/utils/vueUtils.js b/packages/lib/utils/vueUtils.js index 70722b04..1f1473e6 100644 --- a/packages/lib/utils/vueUtils.js +++ b/packages/lib/utils/vueUtils.js @@ -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) { @@ -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; -}