Commit 10fc6e38262c8f9811b7f26ceb45133c28beba84
Committed by
小小鲁班
1 parent
3b894fd6
fix(preview): #196; !#zh: 预览模块支持长页面 !#en: support long page
Showing
1 changed file
with
36 additions
and
28 deletions
front-end/h5/src/engine-entry.js
| ... | ... | @@ -30,34 +30,54 @@ const Engine = { |
| 30 | 30 | components: { |
| 31 | 31 | NodeWrapper |
| 32 | 32 | }, |
| 33 | + data() { | |
| 34 | + return { | |
| 35 | + isLongPage: window.__work.mode === 'h5_long_page', | |
| 36 | + } | |
| 37 | + }, | |
| 33 | 38 | methods: { |
| 34 | - renderPreview (h, _elements) { | |
| 35 | - const isLongPage = window.__work.mode === 'h5_long_page' | |
| 36 | - const elements = _elements.map(element => new Element(element)) | |
| 39 | + renderLongPage () { | |
| 40 | + const work = window.__work | |
| 41 | + return this.renderPreview(work.pages[0].elements) | |
| 42 | + }, | |
| 43 | + renderSwiperPage () { | |
| 44 | + const work = window.__work | |
| 45 | + return ( | |
| 46 | + <div class="swiper-container"> | |
| 47 | + <div class="swiper-wrapper">{ | |
| 48 | + work.pages.map(page => { | |
| 49 | + return ( | |
| 50 | + <section class="swiper-slide flat"> | |
| 51 | + {/* this.walk(h, page.elements) */} | |
| 52 | + { this.renderPreview(page.elements) } | |
| 53 | + </section> | |
| 54 | + ) | |
| 55 | + }) | |
| 56 | + }</div> | |
| 57 | + <div class="swiper-pagination"></div> | |
| 58 | + </div> | |
| 59 | + ) | |
| 60 | + }, | |
| 61 | + renderPreview (pageElements) { | |
| 37 | 62 | let pageWrapperStyle = { |
| 38 | 63 | height: '100%', |
| 39 | 64 | position: 'relative' |
| 40 | 65 | } |
| 41 | 66 | |
| 42 | - if (isLongPage) { | |
| 67 | + if (this.isLongPage) { | |
| 43 | 68 | pageWrapperStyle = { |
| 44 | 69 | ...pageWrapperStyle, |
| 45 | 70 | 'overflow-y': 'scroll' |
| 46 | 71 | } |
| 47 | 72 | } |
| 48 | 73 | |
| 74 | + const elements = pageElements.map(element => new Element(element)) | |
| 49 | 75 | return ( |
| 50 | 76 | <div style={pageWrapperStyle}> |
| 51 | 77 | { |
| 52 | 78 | elements.map((element, index) => { |
| 53 | - // const style = element.getStyle({ position: 'absolute', isRem: true }) | |
| 54 | - // const data = { | |
| 55 | - // style, | |
| 56 | - // props: element.getProps({ mode: 'preview' }) | |
| 57 | - // } | |
| 58 | - // return h(element.name, data) | |
| 59 | 79 | return <node-wrapper element={element}> |
| 60 | - {h(element.name, element.getPreviewData({ position: 'static' }))} | |
| 80 | + {this.$createElement(element.name, element.getPreviewData({ position: 'static' }))} | |
| 61 | 81 | </node-wrapper> |
| 62 | 82 | }) |
| 63 | 83 | } |
| ... | ... | @@ -67,23 +87,11 @@ const Engine = { |
| 67 | 87 | }, |
| 68 | 88 | render (h) { |
| 69 | 89 | const work = window.__work |
| 70 | - return ( | |
| 71 | - <div id="work-container" data-work-id={work.id}> | |
| 72 | - <div class="swiper-container"> | |
| 73 | - <div class="swiper-wrapper">{ | |
| 74 | - work.pages.map(page => { | |
| 75 | - return ( | |
| 76 | - <section class="swiper-slide flat"> | |
| 77 | - {/* this.walk(h, page.elements) */} | |
| 78 | - { this.renderPreview(h, page.elements) } | |
| 79 | - </section> | |
| 80 | - ) | |
| 81 | - }) | |
| 82 | - }</div> | |
| 83 | - <div class="swiper-pagination"></div> | |
| 84 | - </div> | |
| 85 | - </div> | |
| 86 | - ) | |
| 90 | + return <div id="work-container" data-work-id={work.id}> | |
| 91 | + { | |
| 92 | + this.isLongPage ? this.renderLongPage() : this.renderSwiperPage() | |
| 93 | + } | |
| 94 | + </div> | |
| 87 | 95 | } |
| 88 | 96 | } |
| 89 | 97 | ... | ... |