fix:完善根据id查询并修改对应组件的数据
This commit is contained in:
@ -36,7 +36,7 @@
|
|||||||
@update="onPreviewUpdate"
|
@update="onPreviewUpdate"
|
||||||
@stop="onPreviewStop"
|
@stop="onPreviewStop"
|
||||||
>
|
>
|
||||||
{{store.previewScheme}}
|
<!-- {{store.previewScheme}}-->
|
||||||
<DynamicComponent v-for="component in store.previewScheme" :key="component.id" :componentData="component">
|
<DynamicComponent v-for="component in store.previewScheme" :key="component.id" :componentData="component">
|
||||||
{{ component.id }}
|
{{ component.id }}
|
||||||
</DynamicComponent>
|
</DynamicComponent>
|
||||||
@ -51,6 +51,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import {RadioGroup,Radio} from '@arco-design/web-vue'
|
||||||
import {onMounted, ref, watch} from 'vue';
|
import {onMounted, ref, watch} from 'vue';
|
||||||
import {uuid} from 'lsp-uuid';
|
import {uuid} from 'lsp-uuid';
|
||||||
import {componentScheme} from "@/schemes/scheme";
|
import {componentScheme} from "@/schemes/scheme";
|
||||||
@ -58,7 +59,7 @@ import {useSchemeStore} from '@/stores/useSchemeStore';
|
|||||||
import {IComponent} from "@/type/IComponent";
|
import {IComponent} from "@/type/IComponent";
|
||||||
import DynamicComponent from "@/components/DynamicComponent.vue";
|
import DynamicComponent from "@/components/DynamicComponent.vue";
|
||||||
import PropertyEditor from "@/components/PropertyEditor.vue";
|
import PropertyEditor from "@/components/PropertyEditor.vue";
|
||||||
import {VueDraggable} from "vue-draggable-plus";
|
import {DraggableEvent, VueDraggable} from "vue-draggable-plus";
|
||||||
|
|
||||||
let list0 = ref([])
|
let list0 = ref([])
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ onMounted(() => {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
});
|
});
|
||||||
|
|
||||||
function clone(element: Record<'name' | 'id' | 'type' | 'props' | 'class' | 'text' | 'style' | 'slots'|'visible'|'disable', IComponent>) {
|
function clone(element: Record<'name' | 'id' | 'type' | 'props' | 'class' | 'text' | 'style' | 'slots'|'visible'|'disable'|'children', IComponent>) {
|
||||||
console.log("clone", element)
|
console.log("clone", element)
|
||||||
return {
|
return {
|
||||||
id: `${element.type}-${uuid()}`,
|
id: `${element.type}-${uuid()}`,
|
||||||
@ -142,7 +143,7 @@ function clone(element: Record<'name' | 'id' | 'type' | 'props' | 'class' | 'tex
|
|||||||
class: element.class,
|
class: element.class,
|
||||||
designer: '',
|
designer: '',
|
||||||
text: element.text,
|
text: element.text,
|
||||||
children: [],
|
children: element.children||[],
|
||||||
style: element.style,
|
style: element.style,
|
||||||
visible: element.visible,
|
visible: element.visible,
|
||||||
slots: element.slots,
|
slots: element.slots,
|
||||||
@ -154,6 +155,7 @@ function clone(element: Record<'name' | 'id' | 'type' | 'props' | 'class' | 'tex
|
|||||||
|
|
||||||
const onEnd = (event: DraggableEvent) => {
|
const onEnd = (event: DraggableEvent) => {
|
||||||
console.log("onEnd", event)
|
console.log("onEnd", event)
|
||||||
|
store.nowComponentsData=event.clonedData
|
||||||
// const {oldDraggableIndex} = obj;
|
// const {oldDraggableIndex} = obj;
|
||||||
// store.previewData(store.component[oldDraggableIndex]);
|
// store.previewData(store.component[oldDraggableIndex]);
|
||||||
// store.nowComponentsData(store.component[oldDraggableIndex]);
|
// store.nowComponentsData(store.component[oldDraggableIndex]);
|
||||||
|
|||||||
@ -4,7 +4,26 @@
|
|||||||
"id": "radiogroup",
|
"id": "radiogroup",
|
||||||
"designer": {},
|
"designer": {},
|
||||||
"text": "",
|
"text": "",
|
||||||
"props": {},
|
"props": {
|
||||||
|
"type": "button"
|
||||||
|
},
|
||||||
|
"style": "",
|
||||||
|
"class": "",
|
||||||
|
"visible": "",
|
||||||
|
"slots": {},
|
||||||
|
"disable": "",
|
||||||
|
"events": {},
|
||||||
|
"loop": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "Radio",
|
||||||
|
"name": "radio",
|
||||||
|
"id": "radio",
|
||||||
|
"designer": {},
|
||||||
|
"text": "广州",
|
||||||
|
"props": {
|
||||||
|
"value": "guangzhou"
|
||||||
|
},
|
||||||
"style": "",
|
"style": "",
|
||||||
"class": "",
|
"class": "",
|
||||||
"visible": "",
|
"visible": "",
|
||||||
@ -13,4 +32,24 @@
|
|||||||
"events": {},
|
"events": {},
|
||||||
"loop": {},
|
"loop": {},
|
||||||
"children": []
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Radio",
|
||||||
|
"name": "radio",
|
||||||
|
"id": "radio",
|
||||||
|
"designer": {},
|
||||||
|
"text": "深圳",
|
||||||
|
"props": {
|
||||||
|
"value": "shenzhen"
|
||||||
|
},
|
||||||
|
"style": "",
|
||||||
|
"class": "",
|
||||||
|
"visible": "",
|
||||||
|
"slots": {},
|
||||||
|
"disable": "",
|
||||||
|
"events": {},
|
||||||
|
"loop": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@ -1051,7 +1051,26 @@
|
|||||||
"id": "radiogroup",
|
"id": "radiogroup",
|
||||||
"designer": {},
|
"designer": {},
|
||||||
"text": "",
|
"text": "",
|
||||||
"props": {},
|
"props": {
|
||||||
|
"type": "button"
|
||||||
|
},
|
||||||
|
"style": "",
|
||||||
|
"class": "",
|
||||||
|
"visible": "",
|
||||||
|
"slots": {},
|
||||||
|
"disable": "",
|
||||||
|
"events": {},
|
||||||
|
"loop": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "Radio",
|
||||||
|
"name": "radio",
|
||||||
|
"id": "radio",
|
||||||
|
"designer": {},
|
||||||
|
"text": "广州",
|
||||||
|
"props": {
|
||||||
|
"value": "guangzhou"
|
||||||
|
},
|
||||||
"style": "",
|
"style": "",
|
||||||
"class": "",
|
"class": "",
|
||||||
"visible": "",
|
"visible": "",
|
||||||
@ -1061,6 +1080,26 @@
|
|||||||
"loop": {},
|
"loop": {},
|
||||||
"children": []
|
"children": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "Radio",
|
||||||
|
"name": "radio",
|
||||||
|
"id": "radio",
|
||||||
|
"designer": {},
|
||||||
|
"text": "深圳",
|
||||||
|
"props": {
|
||||||
|
"value": "shenzhen"
|
||||||
|
},
|
||||||
|
"style": "",
|
||||||
|
"class": "",
|
||||||
|
"visible": "",
|
||||||
|
"slots": {},
|
||||||
|
"disable": "",
|
||||||
|
"events": {},
|
||||||
|
"loop": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"Rate": {
|
"Rate": {
|
||||||
"type": "Rate",
|
"type": "Rate",
|
||||||
"name": "rate",
|
"name": "rate",
|
||||||
|
|||||||
@ -1051,7 +1051,26 @@ export const componentScheme = {
|
|||||||
"id": "radiogroup",
|
"id": "radiogroup",
|
||||||
"designer": {},
|
"designer": {},
|
||||||
"text": "",
|
"text": "",
|
||||||
"props": {},
|
"props": {
|
||||||
|
"type": "button"
|
||||||
|
},
|
||||||
|
"style": "",
|
||||||
|
"class": "",
|
||||||
|
"visible": "",
|
||||||
|
"slots": {},
|
||||||
|
"disable": "",
|
||||||
|
"events": {},
|
||||||
|
"loop": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "Radio",
|
||||||
|
"name": "radio",
|
||||||
|
"id": "radio",
|
||||||
|
"designer": {},
|
||||||
|
"text": "广州",
|
||||||
|
"props": {
|
||||||
|
"value": "guangzhou"
|
||||||
|
},
|
||||||
"style": "",
|
"style": "",
|
||||||
"class": "",
|
"class": "",
|
||||||
"visible": "",
|
"visible": "",
|
||||||
@ -1061,6 +1080,26 @@ export const componentScheme = {
|
|||||||
"loop": {},
|
"loop": {},
|
||||||
"children": []
|
"children": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "Radio",
|
||||||
|
"name": "radio",
|
||||||
|
"id": "radio",
|
||||||
|
"designer": {},
|
||||||
|
"text": "深圳",
|
||||||
|
"props": {
|
||||||
|
"value": "shenzhen"
|
||||||
|
},
|
||||||
|
"style": "",
|
||||||
|
"class": "",
|
||||||
|
"visible": "",
|
||||||
|
"slots": {},
|
||||||
|
"disable": "",
|
||||||
|
"events": {},
|
||||||
|
"loop": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"Rate": {
|
"Rate": {
|
||||||
"type": "Rate",
|
"type": "Rate",
|
||||||
"name": "rate",
|
"name": "rate",
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import {defineStore} from 'pinia'
|
import { defineStore } from 'pinia';
|
||||||
import {IPageComponent} from '@/type/IPageComponent';
|
import { IPageComponent } from '@/type/IPageComponent';
|
||||||
|
|
||||||
|
// 缓存对象
|
||||||
|
const idToObjectCache = new Map<string, IPageComponent>();
|
||||||
|
|
||||||
function findObjectById(obj, targetId) {
|
function findObjectById(obj, targetId) {
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
@ -27,21 +30,34 @@ export const useSchemeStore = defineStore('scheme', {
|
|||||||
previewScheme: [],
|
previewScheme: [],
|
||||||
nowComponentsData: {}
|
nowComponentsData: {}
|
||||||
}),
|
}),
|
||||||
actions:
|
actions: {
|
||||||
{
|
|
||||||
initPreviewScheme(value) {
|
initPreviewScheme(value) {
|
||||||
this.previewScheme = value
|
this.previewScheme = value;
|
||||||
this.nowComponentsData = value[0]
|
this.nowComponentsData = value[0];
|
||||||
|
// 清空缓存
|
||||||
|
idToObjectCache.clear();
|
||||||
},
|
},
|
||||||
initComponents(value) {
|
initComponents(value) {
|
||||||
this.components = value
|
this.components = value;
|
||||||
},
|
},
|
||||||
getSchemeObj(id) {
|
getSchemeObj(id) {
|
||||||
return findObjectById(this.previewScheme, id)
|
// 检查缓存
|
||||||
|
if (idToObjectCache.has(id)) {
|
||||||
|
return idToObjectCache.get(id);
|
||||||
|
}
|
||||||
|
// 查找并缓存
|
||||||
|
const obj = findObjectById(this.previewScheme, id);
|
||||||
|
if (obj) {
|
||||||
|
idToObjectCache.set(id, obj);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
},
|
},
|
||||||
updateScheme() {
|
updateScheme(id, updates) {
|
||||||
|
const obj = this.getSchemeObj(id);
|
||||||
|
if (obj) {
|
||||||
|
// 更新对象属性
|
||||||
|
Object.assign(obj, updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user