UUID升级异常修复

This commit is contained in:
付民康
2025-03-25 17:26:43 +08:00
parent 42693b2115
commit f008442a91

View File

@@ -46,6 +46,15 @@ const setSelectRow = (row) => {
showDetail.value = true;
};
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
const renameComponentsToChildren = (obj) => {
// 如果传入的不是对象,直接返回
if (typeof obj !== 'object' || obj === null) {
@@ -55,7 +64,7 @@ const renameComponentsToChildren = (obj) => {
// 如果对象有 `components` 属性,将其改为 `children`
if (obj.hasOwnProperty('component')) {
// 生成随机 UUID 并赋值给 id
obj.id = crypto.randomUUID(); // 使用浏览器/Node.js 原生 API
obj.id = generateUUID(); // 使用浏览器/Node.js 原生 API
// obj.id = obj.component.id; // 将 components 改为 children
obj.libraryName = obj.component.libraryName; // 将 components 改为 children
obj.latestVersion = obj.component.latestVersion; // 将 components 改为 children