From 2f4b143550c9800db3d13552d75992e2fbe2135b Mon Sep 17 00:00:00 2001 From: shangbin Date: Tue, 16 Nov 2021 19:58:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=8D=95=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BA=8C=E6=AC=A1=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 7 +++- src/components-v2/VCC.vue | 7 +++- src/components/Code.vue | 15 +++++--- src/libs/main-panel.js | 13 ++++--- src/script/compile.js | 8 ++-- src/script/compileComponent.js | 7 +++- src/test/compileVueOnline.vue | 69 ++++++++++++++++++++++++++++++++++ src/utils/common.js | 32 ++++++++++++++++ 8 files changed, 139 insertions(+), 19 deletions(-) create mode 100644 src/test/compileVueOnline.vue 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