Commit 65311e9d225998238a147b035bc444fc4d042343

Authored by ly525
1 parent e7b6ed06

feat(animation): run animations in preview mode

front-end/h5/src/components/core/editor/canvas/preview.js
  1 +import animationMixin from '@/mixins/animation.js'
1 2 /**
2 3 * TODO extract page preview card used for page list
3 4 */
4 5 export default {
5 6 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 + },
6 21 methods: {
7 22 renderPreview (h, elements) {
8 23 return (
9 24 <div style={{ height: '100%', position: 'relative' }}>
10 25 {
11 26 elements.map((element, index) => {
  27 + console.log(element.getStyle())
12 28 /**
13 29 * TODO 是否可以将 renderElement 进行抽象成 renderBaseElement?
14 30 * renderBaseElement
15 31 * -> renderBaseElementWithEvent()
16 32 * -> renderBaseElementWithCustomStyle()
17 33 */
18   -
19   - return h(element.name, element.getPreviewData())
  34 + return <node-wrapper element={element}>{h(element.name, element.getPreviewData({ position: 'static' }))}</node-wrapper>
20 35 })
21 36 }
22 37 </div>
... ...
front-end/h5/src/components/core/models/element.js
... ... @@ -91,8 +91,8 @@ class Element {
91 91 }
92 92 }
93 93  
94   - getPreviewData () {
95   - const style = this.getStyle({ position: 'absolute' })
  94 + getPreviewData ({ position = 'static', isRem = false } = {}) {
  95 + const style = this.getStyle({ position })
96 96 const data = {
97 97 style,
98 98 props: this.getProps({ mode: 'preview' }),
... ...
front-end/h5/src/mixins/animation.js
... ... @@ -46,9 +46,10 @@ export default {
46 46 created () {
47 47 const that = this
48 48 window.getEditorApp.$on('RUN_ANIMATIONS', () => {
49   - if (that.active) {
50   - that.runAnimations()
51   - }
  49 + that.runAnimations()
  50 + // if (that.active) {
  51 + // that.runAnimations()
  52 + // }
52 53 })
53 54 }
54 55  
... ...