Skip to content

Commit 65311e9

Browse files
committed
feat(animation): run animations in preview mode
1 parent e7b6ed0 commit 65311e9

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

front-end/h5/src/components/core/editor/canvas/preview.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1+
import animationMixin from '@/mixins/animation.js'
12
/**
23
* TODO extract page preview card used for page list
34
*/
45
export default {
56
props: ['elements'],
7+
components: {
8+
nodeWrapper: {
9+
mixins: [animationMixin],
10+
props: ['element'],
11+
mounted () {
12+
this.runAnimations()
13+
},
14+
render (h) {
15+
return (
16+
<div style={this.element.getStyle({ position: 'absolute' })}>{this.$slots.default}</div>
17+
)
18+
}
19+
}
20+
},
621
methods: {
722
renderPreview (h, elements) {
823
return (
924
<div style={{ height: '100%', position: 'relative' }}>
1025
{
1126
elements.map((element, index) => {
27+
console.log(element.getStyle())
1228
/**
1329
* TODO 是否可以将 renderElement 进行抽象成 renderBaseElement?
1430
* renderBaseElement
1531
* -> renderBaseElementWithEvent()
1632
* -> renderBaseElementWithCustomStyle()
1733
*/
18-
19-
return h(element.name, element.getPreviewData())
34+
return <node-wrapper element={element}>{h(element.name, element.getPreviewData({ position: 'static' }))}</node-wrapper>
2035
})
2136
}
2237
</div>

front-end/h5/src/components/core/models/element.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class Element {
9191
}
9292
}
9393

94-
getPreviewData () {
95-
const style = this.getStyle({ position: 'absolute' })
94+
getPreviewData ({ position = 'static', isRem = false } = {}) {
95+
const style = this.getStyle({ position })
9696
const data = {
9797
style,
9898
props: this.getProps({ mode: 'preview' }),

front-end/h5/src/mixins/animation.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ export default {
4646
created () {
4747
const that = this
4848
window.getEditorApp.$on('RUN_ANIMATIONS', () => {
49-
if (that.active) {
50-
that.runAnimations()
51-
}
49+
that.runAnimations()
50+
// if (that.active) {
51+
// that.runAnimations()
52+
// }
5253
})
5354
}
5455

0 commit comments

Comments
 (0)