Commit dcf9c0692fa2b3477703d8ebaa8b5353fcf4c500

Authored by ly525
1 parent 9ce21af3

chore: group plugins

front-end/h5/src/components/core/editor.js
... ... @@ -40,6 +40,70 @@ export default {
40 40 this.mixinPluginCustomComponents2Editor()
41 41 },
42 42 /**
  43 + * 在左侧或顶部导航上显示可用的组件快捷方式,用户点击之后,即可将其添加到中间画布上
  44 + * @param {Object} group: {children, title, icon}
  45 + */
  46 + renderPluginShortcut (group) {
  47 + return group.children.length === 1
  48 + ? this.renderSinglePluginShortcut(group)
  49 + : this.renderMultiPluginShortcuts(group)
  50 + },
  51 + /**
  52 + * 渲染多个插件的快捷方式
  53 + * @param {Object} group: {children, title, icon}
  54 + */
  55 + renderMultiPluginShortcuts (group) {
  56 + const plugins = group.children
  57 + return <el-popover
  58 + placement="bottom"
  59 + width="400"
  60 + trigger="hover">
  61 + {
  62 + plugins.sort().map(item => (
  63 + <el-button
  64 + class='ma-0 no-border-radius'
  65 + onClick={this.clone.bind(this, item)}
  66 + >
  67 + <i
  68 + class={['fa', `fa-${item.icon}`]}
  69 + aria-hidden='true'
  70 + style='display: block;font-size: 16px;margin-bottom: 10px;'
  71 + />
  72 + <span>{ item.title }</span>
  73 + </el-button>
  74 + ))
  75 + }
  76 + <el-button slot="reference" class='ma-0 no-border-radius'>
  77 + <i
  78 + class={['fa', `fa-${group.icon}`]}
  79 + aria-hidden='true'
  80 + style='display: block;font-size: 16px;margin-bottom: 10px;'
  81 + />
  82 + <span class="plugin-item__text">{group.title}</span>
  83 + </el-button>
  84 + </el-popover>
  85 + },
  86 + /**
  87 + * #!zh: 渲染单个插件的快捷方式
  88 + * #!en: render shortcut for single plugin
  89 + * @param {Object} group: {children, title, icon}
  90 + */
  91 + renderSinglePluginShortcut ({ children }) {
  92 + const [plugin] = children
  93 + return <el-button
  94 + class='ma-0 no-border-radius'
  95 + style={{ width: '100%' }}
  96 + onClick={this.clone.bind(this, plugin)}
  97 + >
  98 + <i
  99 + class={['fa', `fa-${plugin.icon}`]}
  100 + aria-hidden='true'
  101 + style='display: block;font-size: 16px;margin-bottom: 10px;'
  102 + />
  103 + <span class="plugin-item__text">{ plugin.title }</span>
  104 + </el-button>
  105 + },
  106 + /**
43 107 * #!zh: renderCanvas 渲染中间画布
44 108 * elements
45 109 * @param {*} h
... ... @@ -85,21 +149,15 @@ export default {
85 149 <el-tabs tab-position="left" class="lb-tabs">
86 150 <el-tab-pane label='组件列表'>
87 151 <div class="full-height">
88   - {this.visiblePluginList.sort().map(item => {
89   - return (
90   - <el-button
91   - class='plugin-item ma-0 no-border-radius'
92   - onClick={this.clone.bind(this, item)}
93   - >
94   - <i
95   - class={['fa', `fa-${item.icon}`]}
96   - aria-hidden='true'
97   - style='display: block;font-size: 16px;margin-bottom: 10px;'
98   - />
99   - <span>{ item.title }</span>
100   - </el-button>
101   - )
102   - })}
  152 + <el-row gutter={20}>
  153 + {
  154 + this.groups.sort().map(group => (
  155 + <el-col span={12} style={{ marginTop: '10px' }}>
  156 + {this.renderPluginShortcut(group)}
  157 + </el-col>
  158 + ))
  159 + }
  160 + </el-row>
103 161 </div>
104 162 </el-tab-pane>
105 163 <el-tab-pane label='页面管理'>
... ...
front-end/h5/src/views/Editor.vue
... ... @@ -11,14 +11,53 @@ const PluginList = [
11 11 icon: 'hand-pointer-o',
12 12 component: LbpButton,
13 13 visible: true,
14   - name: 'lbp-button'
  14 + name: 'lbp-button',
  15 + children: [
  16 + {
  17 + title: '按钮',
  18 + icon: 'hand-pointer-o',
  19 + component: LbpButton,
  20 + visible: true,
  21 + name: 'lbp-button'
  22 + }
  23 + ]
15 24 },
16 25 {
17 26 title: '图片',
18 27 icon: 'image',
19 28 component: LbpPicture,
20 29 visible: true,
21   - name: 'lbp-picture'
  30 + name: 'lbp-picture',
  31 + children: [
  32 + {
  33 + title: '图片',
  34 + icon: 'image',
  35 + component: LbpPicture,
  36 + visible: true,
  37 + name: 'lbp-picture'
  38 + }
  39 + ]
  40 + },
  41 + {
  42 + title: '表单',
  43 + icon: 'wpforms',
  44 + visible: true,
  45 + children: [
  46 + {
  47 + title: '按钮',
  48 + icon: 'hand-pointer-o',
  49 + component: LbpButton,
  50 + visible: true,
  51 + name: 'lbp-button'
  52 + },
  53 + {
  54 + title: '图片',
  55 + icon: 'image',
  56 + component: LbpPicture,
  57 + visible: true,
  58 + name: 'lbp-picture'
  59 + }
  60 + ]
22 61 }
23 62 ]
24 63  
... ... @@ -28,6 +67,9 @@ export default {
28 67 // !#zh 显示在侧边栏或顶部的 可用组件列表
29 68 visiblePluginList () {
30 69 return PluginList.filter(p => p.visible)
  70 + },
  71 + groups () {
  72 + return PluginList.filter(p => p.visible)
31 73 }
32 74 },
33 75 methods: {
... ... @@ -57,16 +99,6 @@ $designerWidthHalf: $designerWidth / 2;
57 99  
58 100 }
59 101  
60   -.plugin-item {
61   - border: 1px solid #f1efef;
62   - width: 49%;
63   - padding: 12px 12px;
64   -
65   - &:nth-child(even) {
66   - margin: 4px 0 4px 2% !important;
67   - }
68   -}
69   -
70 102 .canvas-wrapper {
71 103 position: relative;
72 104 top: 5%;
... ...