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

clear: 替换ID生成工具

This commit is contained in:
shangbin
2021-12-06 20:47:28 +08:00
parent e0a7222dae
commit 674064818d
7 changed files with 54 additions and 74 deletions

View File

@@ -1,5 +1,5 @@
import isEqual from "lodash-es/isEqual";
// import cryptoRandomString from "crypto-random-string";
import { customAlphabet, nanoid } from 'nanoid';
export function getRawComponentKey(__rawVueInfo__) {
return Object.keys(__rawVueInfo__)[0];
@@ -24,6 +24,14 @@ export function isObject(obj) {
return Object.prototype.toString.apply(obj) === "[object Object]";
}
/**
* @description 生成唯一ID
*/
export function createUniqueId() {
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 10);
return nanoid();
}
/**
* 遍历对象添加ID
* @param {*} jsonObj
@@ -50,7 +58,7 @@ export function ergodic(jsonObj) {
// 添加ID
if (!jsonObj["lc_id"]) {
// jsonObj["lc_id"] = cryptoRandomString({ length: 10, type: "base64" });
jsonObj["lc_id"] = createUniqueId();
}
}
}

View File

@@ -1,7 +1,6 @@
import { isObject, isArray, getRawComponentKey } from '@/utils/common';
import { isObject, isArray, getRawComponentKey, createUniqueId } from '@/utils/common';
import presetAttribute from "../libs/presetAttribute";
// const cryptoRandomString = require("crypto-random-string");
// 将预生成的ID替换否则当有两个组件挂在同一个树上时后一个会将前一个的属性覆盖
export function replaceRowID(codeObj, html) {
@@ -14,7 +13,7 @@ export function replaceRowID(codeObj, html) {
const element = obj[key];
if (key == "lc_id") {
const oldID = obj[key];
const newID = 3333;
const newID = createUniqueId();
newHtml = newHtml.replace(oldID, newID);
obj[key] = newID;
} else if (isObject(element)) {

View File

@@ -1,5 +1,4 @@
import { generateRawInfo, getSplitTag } from './forCode';
import { getRawComponentKey } from './common';
// 遍历DOM树初始化lc-mark标记的元素