|
|
|
|
@ -1,14 +1,16 @@
|
|
|
|
|
<template>
|
|
|
|
|
<component v-if="componentVisible" @click.stop="handleClick" :id="componentId" :is="componentType" v-bind="componentProps"
|
|
|
|
|
:class="componentClass" :style="componentStyle">
|
|
|
|
|
{{ componentText }}
|
|
|
|
|
<template v-for="child in componentChildren" :key="child.id">
|
|
|
|
|
<DynamicComponent :component-data="child" />
|
|
|
|
|
</template>
|
|
|
|
|
<template v-for="(slot, key, index) in componentSlots" :key="index" v-slot:[key]>
|
|
|
|
|
<DynamicComponent :component-data="slot" />
|
|
|
|
|
</template>
|
|
|
|
|
</component>
|
|
|
|
|
<div v-if="componentVisible||store.designerMode" :id="componentId" @click="handleClick">
|
|
|
|
|
<component :is="componentType" v-bind="componentPropsWithDisabled"
|
|
|
|
|
:class="componentClass" :style="componentStyle">
|
|
|
|
|
{{ componentText }}
|
|
|
|
|
<template v-for="child in componentChildren" :key="child.id">
|
|
|
|
|
<DynamicComponent :component-data="child" />
|
|
|
|
|
</template>
|
|
|
|
|
<template v-for="(slot, key, index) in componentSlots" :key="index" v-slot:[key]>
|
|
|
|
|
<DynamicComponent :component-data="slot" />
|
|
|
|
|
</template>
|
|
|
|
|
</component>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
@ -25,21 +27,22 @@ onMounted(() => {
|
|
|
|
|
console.log(props.componentData);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const componentId = ref(props.componentData?.id || '');
|
|
|
|
|
const componentType = ref(markRaw(componentMapping[props.componentData?.type]) || 'div'); // 使用 markRaw
|
|
|
|
|
const componentProps = ref(props.componentData?.props || {});
|
|
|
|
|
const componentDisable = ref(props.componentData?.disable || false);
|
|
|
|
|
const componentVisible = ref(props.componentData?.visible || true);
|
|
|
|
|
const componentChildren = ref(props.componentData?.children || []);
|
|
|
|
|
const componentText = ref(props.componentData?.text || '');
|
|
|
|
|
const componentClass = ref(props.componentData?.class || []);
|
|
|
|
|
const componentStyle = ref(props.componentData?.style || []);
|
|
|
|
|
const componentSlots = ref(props.componentData?.slots || {});
|
|
|
|
|
const componentId = computed(() => props.componentData?.id || '');
|
|
|
|
|
const componentType = computed(() => markRaw(componentMapping[props.componentData?.type]) || 'div');
|
|
|
|
|
const componentProps = computed(() => props.componentData?.props || {});
|
|
|
|
|
const componentDisable = computed(() => props.componentData?.disable || false);
|
|
|
|
|
const componentVisible = computed(() => props.componentData?.visible);
|
|
|
|
|
const componentChildren = computed(() => props.componentData?.children || []);
|
|
|
|
|
const componentText = computed(() => props.componentData?.text || '');
|
|
|
|
|
const componentClass = computed(() => props.componentData?.class || []);
|
|
|
|
|
const componentStyle = computed(() => props.componentData?.style || []);
|
|
|
|
|
const componentSlots = computed(() => props.componentData?.slots || {});
|
|
|
|
|
|
|
|
|
|
// 确保 componentProps 包含 disabled 属性
|
|
|
|
|
watch(componentDisable, (newDisable) => {
|
|
|
|
|
componentProps.value['disabled'] = newDisable;
|
|
|
|
|
});
|
|
|
|
|
const componentPropsWithDisabled = computed(() => ({
|
|
|
|
|
...componentProps.value,
|
|
|
|
|
disabled: componentDisable.value
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// 获取当前组件的最新数据
|
|
|
|
|
const getCurrentSchemeObj = () => {
|
|
|
|
|
@ -47,26 +50,13 @@ const getCurrentSchemeObj = () => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 监听 previewScheme 的变化
|
|
|
|
|
watch(() => store.previewScheme, (newPreviewScheme) => {
|
|
|
|
|
// 重新获取当前组件的最新数据
|
|
|
|
|
const currentComponent = getCurrentSchemeObj();
|
|
|
|
|
console.log("currentComponent", JSON.stringify(currentComponent));
|
|
|
|
|
if (currentComponent) {
|
|
|
|
|
// 更新组件数据
|
|
|
|
|
componentProps.value = currentComponent.props ;
|
|
|
|
|
componentDisable.value = currentComponent.disable ;
|
|
|
|
|
componentVisible.value = currentComponent?.visible;
|
|
|
|
|
componentChildren.value = currentComponent.children ;
|
|
|
|
|
componentText.value = currentComponent.text;
|
|
|
|
|
componentClass.value = currentComponent.class ;
|
|
|
|
|
componentStyle.value = currentComponent.style ;
|
|
|
|
|
componentSlots.value = currentComponent.slots ;
|
|
|
|
|
}
|
|
|
|
|
console.log("store.previewScheme has changed",componentVisible.value)
|
|
|
|
|
}, { deep: true });
|
|
|
|
|
// watch(() => props.componentData, (n) => {
|
|
|
|
|
// console.log("currentComponent", JSON.stringify(n));
|
|
|
|
|
// }, { deep: true });
|
|
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
|
console.log(`Component with id ${JSON.stringify(getCurrentSchemeObj())} was clicked.`);
|
|
|
|
|
const currentComponent = getCurrentSchemeObj();
|
|
|
|
|
console.log(`Component with id ${currentComponent.id} was clicked.`);
|
|
|
|
|
// 你可以在这里执行更多的逻辑,例如发出一个事件或调用一个方法
|
|
|
|
|
};
|
|
|
|
|
</script>
|