Commit 98ffdd6a356bb715a22d978b76421b33bfda1031
1 parent
7afbd71d
feat: add preview mode and register plugin globally for adding script later
Showing
1 changed file
with
33 additions
and
4 deletions
front-end/h5/src/views/Editor.vue
| 1 | <script> | 1 | <script> |
| 2 | +import Vue from 'vue' | ||
| 3 | + | ||
| 2 | // LuBanPlugin -> Lbp | 4 | // LuBanPlugin -> Lbp |
| 3 | const LbpButton = { | 5 | const LbpButton = { |
| 4 | render () { | 6 | render () { |
| @@ -344,11 +346,15 @@ const Editor = { | @@ -344,11 +346,15 @@ const Editor = { | ||
| 344 | data: () => ({ | 346 | data: () => ({ |
| 345 | pages: [], | 347 | pages: [], |
| 346 | elements: [], | 348 | elements: [], |
| 347 | - editingElement: null | 349 | + editingElement: null, |
| 350 | + isPreviewMode: false, | ||
| 348 | }), | 351 | }), |
| 349 | methods: { | 352 | methods: { |
| 350 | getEditorConfig (pluginName) { | 353 | getEditorConfig (pluginName) { |
| 351 | - return this.$options.components[pluginName].editorConfig | 354 | + // const pluginCtor = Vue.options[pluginName] |
| 355 | + // const pluginCtor = this.$options.components[pluginName] | ||
| 356 | + const pluginCtor = Vue.component(pluginName) | ||
| 357 | + return new pluginCtor().$options.editorConfig | ||
| 352 | }, | 358 | }, |
| 353 | /** | 359 | /** |
| 354 | * !#zh 点击插件,copy 其基础数据到组件树(中间画布) | 360 | * !#zh 点击插件,copy 其基础数据到组件树(中间画布) |
| @@ -396,6 +402,22 @@ const Editor = { | @@ -396,6 +402,22 @@ const Editor = { | ||
| 396 | </div> | 402 | </div> |
| 397 | ) | 403 | ) |
| 398 | }, | 404 | }, |
| 405 | + renderPreview (h, elements) { | ||
| 406 | + return ( | ||
| 407 | + <div style={{ height: '100%' }}> | ||
| 408 | + {elements.map((element, index) => { | ||
| 409 | + return (() => { | ||
| 410 | + const data = { | ||
| 411 | + style: element.getStyle(), | ||
| 412 | + props: element.pluginProps, // #6 #3 | ||
| 413 | + nativeOn: {} | ||
| 414 | + } | ||
| 415 | + return h(element.name, data) | ||
| 416 | + })() | ||
| 417 | + })} | ||
| 418 | + </div> | ||
| 419 | + ) | ||
| 420 | + }, | ||
| 399 | renderPluginListPanel () { | 421 | renderPluginListPanel () { |
| 400 | return ( | 422 | return ( |
| 401 | <el-tabs tab-position="left" class="lb-tabs"> | 423 | <el-tabs tab-position="left" class="lb-tabs"> |
| @@ -465,8 +487,14 @@ const Editor = { | @@ -465,8 +487,14 @@ const Editor = { | ||
| 465 | { this.renderPluginListPanel() } | 487 | { this.renderPluginListPanel() } |
| 466 | </div> | 488 | </div> |
| 467 | <div class='el-col-13'> | 489 | <div class='el-col-13'> |
| 490 | + <div style="text-align: center;"> | ||
| 491 | + <el-radio-group value={this.isPreviewMode} onInput={(value) => this.isPreviewMode = value} size="mini"> | ||
| 492 | + <el-radio-button label={false}>Edit</el-radio-button> | ||
| 493 | + <el-radio-button label={true}>Preview</el-radio-button> | ||
| 494 | + </el-radio-group> | ||
| 495 | + </div> | ||
| 468 | <div class='canvas-wrapper'> | 496 | <div class='canvas-wrapper'> |
| 469 | - { this.renderCanvas(h, this.elements) } | 497 | + { this.isPreviewMode ? this.renderPreview(h, this.elements) : this.renderCanvas(h, this.elements) } |
| 470 | </div> | 498 | </div> |
| 471 | </div> | 499 | </div> |
| 472 | <div class='el-col-6' style="border-left: 1px solid #eee;"> | 500 | <div class='el-col-6' style="border-left: 1px solid #eee;"> |
| @@ -488,7 +516,8 @@ export default { | @@ -488,7 +516,8 @@ export default { | ||
| 488 | methods: { | 516 | methods: { |
| 489 | mixinPlugins2Editor () { | 517 | mixinPlugins2Editor () { |
| 490 | PluginList.forEach(plugin => { | 518 | PluginList.forEach(plugin => { |
| 491 | - this.$options.components[plugin.name] = plugin.component | 519 | + // 全局注册组件,便于以后扩展自定义脚本,注释原来的局部注册:this.$options.components[plugin.name] = plugin.component |
| 520 | + Vue.component(plugin.name, plugin.component) | ||
| 492 | }) | 521 | }) |
| 493 | } | 522 | } |
| 494 | }, | 523 | }, |