Skip to content

Commit 98ffdd6

Browse files
committed
feat: add preview mode and register plugin globally for adding script later
1 parent 7afbd71 commit 98ffdd6

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

front-end/h5/src/views/Editor.vue

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script>
2+
import Vue from 'vue'
3+
24
// LuBanPlugin -> Lbp
35
const LbpButton = {
46
render () {
@@ -344,11 +346,15 @@ const Editor = {
344346
data: () => ({
345347
pages: [],
346348
elements: [],
347-
editingElement: null
349+
editingElement: null,
350+
isPreviewMode: false,
348351
}),
349352
methods: {
350353
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
352358
},
353359
/**
354360
* !#zh 点击插件,copy 其基础数据到组件树(中间画布)
@@ -396,6 +402,22 @@ const Editor = {
396402
</div>
397403
)
398404
},
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+
},
399421
renderPluginListPanel () {
400422
return (
401423
<el-tabs tab-position="left" class="lb-tabs">
@@ -465,8 +487,14 @@ const Editor = {
465487
{ this.renderPluginListPanel() }
466488
</div>
467489
<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>
468496
<div class='canvas-wrapper'>
469-
{ this.renderCanvas(h, this.elements) }
497+
{ this.isPreviewMode ? this.renderPreview(h, this.elements) : this.renderCanvas(h, this.elements) }
470498
</div>
471499
</div>
472500
<div class='el-col-6' style="border-left: 1px solid #eee;">
@@ -488,7 +516,8 @@ export default {
488516
methods: {
489517
mixinPlugins2Editor () {
490518
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)
492521
})
493522
}
494523
},

0 commit comments

Comments
 (0)