+
@@ -14,27 +14,47 @@
/**
* @name: slot-item
* @author:卜启缘
- * @date: 2021/5/3 4:18
+ * @date: 2021/5/3 13:18
* @description:slot-item
* @update: 2021/5/3 14:18
*/
-
+import { defineComponent, onMounted, PropType } from 'vue'
import CompRender from './comp-render'
+import { useAnimate } from '@/hooks/useAnimate'
+import { VisualEditorBlockData } from '@/visual-editor/visual-editor.utils'
-export default {
+export default defineComponent({
name: 'SlotItem',
components: { CompRender },
props: {
element: {
- type: [Object, Array],
+ type: [Object] as PropType,
default: () => ({})
},
config: {
type: Object,
default: () => ({})
}
+ },
+ 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 {}
}
-}
+})
diff --git a/src/hooks/useAnimate.ts b/src/hooks/useAnimate.ts
new file mode 100644
index 0000000..1c9352d
--- /dev/null
+++ b/src/hooks/useAnimate.ts
@@ -0,0 +1,44 @@
+/*
+ * @Author: 卜启缘
+ * @Date: 2021-06-12 21:29:32
+ * @LastEditTime: 2021-06-12 22:03:43
+ * @LastEditors: 卜启缘
+ * @Description: 执行组件动画
+ * @FilePath: \vite-vue3-lowcode\src\hooks\useAnimate.ts
+ */
+
+import { Animation } from '@/visual-editor/visual-editor.utils'
+
+export const useAnimate = async (animateEl: HTMLElement, animations: Animation | Animation[]) => {
+ animations = Array.isArray(animations) ? animations : [animations]
+
+ const play = (animate: Animation) =>
+ new Promise((resolve) => {
+ if (animateEl) {
+ const animationName = `animate__${animate.value}`
+ animateEl.style.setProperty('--animate-duration', `${animate.duration}s`)
+ animateEl.style.setProperty('--animate-delay', `${animate.delay}s`)
+ animateEl.style.setProperty(
+ 'animation-iteration-count',
+ `${animate.infinite ? 'infinite' : animate.count}`
+ )
+
+ // 动画结束时,删除类名
+ const handleAnimationEnd = (event?: AnimationEvent) => {
+ event?.stopPropagation()
+ animateEl.classList.remove(`animate__animated`, animationName)
+ animateEl.removeEventListener('animationend', handleAnimationEnd)
+ resolve('animation end')
+ }
+
+ animateEl?.classList.add(`animate__animated`, animationName)
+ animateEl?.addEventListener('animationend', handleAnimationEnd, { once: true })
+ } else {
+ resolve('动画执行失败!执行动画元素不存在!')
+ }
+ })
+
+ for (const item of animations) {
+ await play(item)
+ }
+}
diff --git a/src/main.ts b/src/main.ts
index 2ea2c2b..e1a4f60 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -7,6 +7,7 @@ import { setupVant } from './plugins/vant'
import 'normalize.css'
import 'virtual:windi.css'
import 'virtual:windi-devtools'
+import 'animate.css'
import router from './router/'
import store from './store/'
diff --git a/src/packages/base-widgets/image/index.tsx b/src/packages/base-widgets/image/index.tsx
index c08fee1..69f3f60 100644
--- a/src/packages/base-widgets/image/index.tsx
+++ b/src/packages/base-widgets/image/index.tsx
@@ -1,3 +1,11 @@
+/*
+ * @Author: 卜启缘
+ * @Date: 2021-06-01 09:45:21
+ * @LastEditTime: 2021-06-12 09:55:10
+ * @LastEditors: 卜启缘
+ * @Description: 图片组件
+ * @FilePath: \vite-vue3-lowcode\src\packages\base-widgets\image\index.tsx
+ */
import { Image } from 'vant'
import {
createEditorInputProp,
@@ -5,6 +13,7 @@ import {
createEditorSwitchProp
} from '@/visual-editor/visual-editor.props'
import { VisualEditorComponent } from '@/visual-editor/visual-editor.utils'
+import { useGlobalProperties } from '@/hooks/useGlobalProperties'
export default {
key: 'image',
@@ -21,8 +30,10 @@ export default {
),
- render: ({ props }) => {
- return