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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { generateRawInfo, getSplitTag } from './forCode';
|
||||
import { getRawComponentKey } from './common';
|
||||
|
||||
|
||||
// 遍历DOM树,初始化lc-mark标记的元素
|
||||
|
||||
Reference in New Issue
Block a user