add:添加悬停和选定样式
This commit is contained in:
@ -1,7 +1,27 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="componentVisible||store.designerMode" :id="componentId" @click="handleClick">
|
<div
|
||||||
<component :is="componentType" v-bind="componentPropsWithDisabled"
|
v-if="componentVisible || store.designerMode"
|
||||||
:class="componentClass" :style="componentStyle">
|
:id="componentId"
|
||||||
|
:class="[
|
||||||
|
'dynamic-component',
|
||||||
|
{ 'hover-state': isHovered },
|
||||||
|
{ 'click-state': isClicked }
|
||||||
|
]"
|
||||||
|
@click.stop="handleClick"
|
||||||
|
@mouseover="isHovered = true"
|
||||||
|
@mouseleave="isHovered = false"
|
||||||
|
>
|
||||||
|
<div v-if="isClicked" class="component-header">
|
||||||
|
<span>{{ componentName }}</span>
|
||||||
|
<button @click="handleFunction('edit')">编辑</button>
|
||||||
|
<button @click="handleFunction('delete')">删除</button>
|
||||||
|
</div>
|
||||||
|
<component
|
||||||
|
:is="componentType"
|
||||||
|
v-bind="componentPropsWithDisabled"
|
||||||
|
:class="componentClass"
|
||||||
|
:style="componentStyle"
|
||||||
|
>
|
||||||
{{ componentText }}
|
{{ componentText }}
|
||||||
<template v-for="child in componentChildren" :key="child.id">
|
<template v-for="child in componentChildren" :key="child.id">
|
||||||
<DynamicComponent :component-data="child" />
|
<DynamicComponent :component-data="child" />
|
||||||
@ -28,6 +48,7 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const componentId = computed(() => props.componentData?.id || '');
|
const componentId = computed(() => props.componentData?.id || '');
|
||||||
|
const componentName = computed(() => props.componentData?.name || 'Unnamed Component');
|
||||||
const componentType = computed(() => markRaw(componentMapping[props.componentData?.type]) || 'div');
|
const componentType = computed(() => markRaw(componentMapping[props.componentData?.type]) || 'div');
|
||||||
const componentProps = computed(() => props.componentData?.props || {});
|
const componentProps = computed(() => props.componentData?.props || {});
|
||||||
const componentDisable = computed(() => props.componentData?.disable || false);
|
const componentDisable = computed(() => props.componentData?.disable || false);
|
||||||
@ -49,14 +70,66 @@ const getCurrentSchemeObj = () => {
|
|||||||
return store.getSchemeObj(componentId.value);
|
return store.getSchemeObj(componentId.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 监听 previewScheme 的变化
|
// 控制悬停和点击状态
|
||||||
// watch(() => props.componentData, (n) => {
|
const isHovered = ref(false);
|
||||||
// console.log("currentComponent", JSON.stringify(n));
|
const isClicked = ref(false);
|
||||||
// }, { deep: true });
|
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
|
isClicked.value = !isClicked.value;
|
||||||
const currentComponent = getCurrentSchemeObj();
|
const currentComponent = getCurrentSchemeObj();
|
||||||
console.log(`Component with id ${currentComponent.id} was clicked.`);
|
console.log(`Component with id ${currentComponent.id} was clicked.`);
|
||||||
// 你可以在这里执行更多的逻辑,例如发出一个事件或调用一个方法
|
// 你可以在这里执行更多的逻辑,例如发出一个事件或调用一个方法
|
||||||
};
|
};
|
||||||
</script>
|
|
||||||
|
const handleFunction = (action: string) => {
|
||||||
|
console.log(`Action: ${action}`);
|
||||||
|
// 处理编辑或删除操作
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dynamic-component {
|
||||||
|
position: relative;
|
||||||
|
border: 1px solid transparent; /* 默认透明边框 */
|
||||||
|
transition: border 0.3s, box-shadow 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynamic-component.hover-state {
|
||||||
|
border: 1px dashed #1057CC; /* 悬停时浅蓝色虚线框 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynamic-component.click-state {
|
||||||
|
border: 2px solid #1057CC; /* 点击时深蓝色实线框 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-header {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
|
color: white;
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 4px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-header span {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-header button {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-header button:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user