vite-vue3-lowcode/preview/views/slot-item.vue

61 lines
1.5 KiB
Vue
Raw Normal View History

2021-05-04 21:54:05 +08:00
<template>
2021-06-12 22:19:59 +08:00
<div class="__slot-item">
2021-05-04 21:54:05 +08:00
<comp-render :element="element" :config="config">
<template v-for="(value, key) in element.props?.slots" :key="key" #[key]>
<template v-for="item in value?.children" :key="item._vid">
<slot-item :element="item" :config="config" />
</template>
</template>
</comp-render>
</div>
</template>
<script lang="ts">
/**
* @name: slot-item
* @author:卜启缘
2021-06-12 22:19:59 +08:00
* @date: 2021/5/3 13:18
2021-05-04 21:54:05 +08:00
* @descriptionslot-item
* @update: 2021/5/3 14:18
*/
2021-06-12 22:19:59 +08:00
import { defineComponent, onMounted, PropType } from 'vue'
2021-05-04 21:54:05 +08:00
import CompRender from './comp-render'
2021-06-12 22:19:59 +08:00
import { useAnimate } from '@/hooks/useAnimate'
import { VisualEditorBlockData } from '@/visual-editor/visual-editor.utils'
2021-05-04 21:54:05 +08:00
2021-06-12 22:19:59 +08:00
export default defineComponent({
2021-05-04 21:54:05 +08:00
name: 'SlotItem',
components: { CompRender },
props: {
element: {
2021-06-12 22:19:59 +08:00
type: [Object] as PropType<VisualEditorBlockData>,
2021-05-04 21:54:05 +08:00
default: () => ({})
},
config: {
type: Object,
default: () => ({})
}
2021-06-12 22:19:59 +08:00
},
setup(props) {
onMounted(() => {
const animations = props.element.animations
if (animations?.length) {
let animateEl =
(window.$$refs[props.element._vid]?.$el as HTMLElement) ??
(window.$$refs[props.element._vid] as HTMLElement)
animateEl = animateEl?.closest('.__slot-item')?.firstChild as HTMLElement
if (animateEl) {
useAnimate(animateEl, animations)
}
}
})
return {}
2021-05-04 21:54:05 +08:00
}
2021-06-12 22:19:59 +08:00
})
2021-05-04 21:54:05 +08:00
</script>
<style scoped></style>