fix:完善根据id查询并修改对应组件的数据

This commit is contained in:
lhj
2024-11-09 23:18:21 +08:00
parent 8600606845
commit 91471748f3
5 changed files with 163 additions and 28 deletions

View File

@ -4,7 +4,9 @@
"id": "radiogroup",
"designer": {},
"text": "",
"props": {},
"props": {
"type": "button"
},
"style": "",
"class": "",
"visible": "",
@ -12,5 +14,42 @@
"disable": "",
"events": {},
"loop": {},
"children": []
"children": [
{
"type": "Radio",
"name": "radio",
"id": "radio",
"designer": {},
"text": "广州",
"props": {
"value": "guangzhou"
},
"style": "",
"class": "",
"visible": "",
"slots": {},
"disable": "",
"events": {},
"loop": {},
"children": []
},
{
"type": "Radio",
"name": "radio",
"id": "radio",
"designer": {},
"text": "深圳",
"props": {
"value": "shenzhen"
},
"style": "",
"class": "",
"visible": "",
"slots": {},
"disable": "",
"events": {},
"loop": {},
"children": []
}
]
}

View File

@ -1051,7 +1051,9 @@
"id": "radiogroup",
"designer": {},
"text": "",
"props": {},
"props": {
"type": "button"
},
"style": "",
"class": "",
"visible": "",
@ -1059,7 +1061,44 @@
"disable": "",
"events": {},
"loop": {},
"children": []
"children": [
{
"type": "Radio",
"name": "radio",
"id": "radio",
"designer": {},
"text": "广州",
"props": {
"value": "guangzhou"
},
"style": "",
"class": "",
"visible": "",
"slots": {},
"disable": "",
"events": {},
"loop": {},
"children": []
},
{
"type": "Radio",
"name": "radio",
"id": "radio",
"designer": {},
"text": "深圳",
"props": {
"value": "shenzhen"
},
"style": "",
"class": "",
"visible": "",
"slots": {},
"disable": "",
"events": {},
"loop": {},
"children": []
}
]
},
"Rate": {
"type": "Rate",

View File

@ -1051,7 +1051,9 @@ export const componentScheme = {
"id": "radiogroup",
"designer": {},
"text": "",
"props": {},
"props": {
"type": "button"
},
"style": "",
"class": "",
"visible": "",
@ -1059,7 +1061,44 @@ export const componentScheme = {
"disable": "",
"events": {},
"loop": {},
"children": []
"children": [
{
"type": "Radio",
"name": "radio",
"id": "radio",
"designer": {},
"text": "广州",
"props": {
"value": "guangzhou"
},
"style": "",
"class": "",
"visible": "",
"slots": {},
"disable": "",
"events": {},
"loop": {},
"children": []
},
{
"type": "Radio",
"name": "radio",
"id": "radio",
"designer": {},
"text": "深圳",
"props": {
"value": "shenzhen"
},
"style": "",
"class": "",
"visible": "",
"slots": {},
"disable": "",
"events": {},
"loop": {},
"children": []
}
]
},
"Rate": {
"type": "Rate",

View File

@ -1,5 +1,8 @@
import {defineStore} from 'pinia'
import {IPageComponent} from '@/type/IPageComponent';
import { defineStore } from 'pinia';
import { IPageComponent } from '@/type/IPageComponent';
// 缓存对象
const idToObjectCache = new Map<string, IPageComponent>();
function findObjectById(obj, targetId) {
if (Array.isArray(obj)) {
@ -27,21 +30,34 @@ export const useSchemeStore = defineStore('scheme', {
previewScheme: [],
nowComponentsData: {}
}),
actions:
{
initPreviewScheme(value) {
this.previewScheme = value
this.nowComponentsData = value[0]
},
initComponents(value) {
this.components = value
},
getSchemeObj(id) {
return findObjectById(this.previewScheme, id)
},
updateScheme() {
actions: {
initPreviewScheme(value) {
this.previewScheme = value;
this.nowComponentsData = value[0];
// 清空缓存
idToObjectCache.clear();
},
initComponents(value) {
this.components = value;
},
getSchemeObj(id) {
// 检查缓存
if (idToObjectCache.has(id)) {
return idToObjectCache.get(id);
}
// 查找并缓存
const obj = findObjectById(this.previewScheme, id);
if (obj) {
idToObjectCache.set(id, obj);
}
return obj;
},
updateScheme(id, updates) {
const obj = this.getSchemeObj(id);
if (obj) {
// 更新对象属性
Object.assign(obj, updates);
}
}
})
}
});