1
0
mirror of https://github.com/sahadev/vue-component-creater-ui.git synced 2025-12-18 16:34:17 +08:00

feat: 支持单文件二次编辑

This commit is contained in:
shangbin
2021-11-16 19:58:28 +08:00
parent 4cde9098bc
commit 2f4b143550
8 changed files with 139 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import isEqual from "lodash/isEqual";
import cryptoRandomString from "crypto-random-string";
export function getRawComponentKey(__rawVueInfo__) {
return Object.keys(__rawVueInfo__)[0];
@@ -21,4 +22,35 @@ export function isArray(arr) {
export function isObject(obj) {
return Object.prototype.toString.apply(obj) === "[object Object]";
}
/**
* 遍历对象添加ID
* @param {*} jsonObj
*/
export function ergodic(jsonObj) {
if (jsonObj) {
for (const key in jsonObj) {
if (jsonObj.hasOwnProperty(key)) {
const element = jsonObj[key];
if (isArray(element)) {
element.forEach((item) => {
if (isObject(item)) {
ergodic(item);
delete item.lc_id;
}
});
} else if (isObject(element)) {
ergodic(element);
} else {
}
}
}
// 添加ID
if (!jsonObj["lc_id"]) {
jsonObj["lc_id"] = cryptoRandomString({ length: 10, type: "base64" });
}
}
}