diff --git a/src/App.vue b/src/App.vue index 9aeb031..7aa5b87 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,14 +1,17 @@ + + \ No newline at end of file diff --git a/src/utils/common.js b/src/utils/common.js index 0795489..8671d40 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -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" }); + } + } } \ No newline at end of file