Commit 9eb1bab3a9a9c9f9dec551fb2ce61ac73715e32d

Authored by ly525
1 parent 8635c9fa

update contextmenu style

front-end/h5/src/components/core/editor/canvas/edit.js
1 1 import { mapState, mapActions } from 'vuex'
2 2 import Shape from '../../support/shape'
3   -import { contains } from '../../../../utils/dom-helper'
4   -
5   -const contextmenuOptions = [
6   - {
7   - i18nLabel: 'editor.centerPanel.contextMenu.copy',
8   - label: '复制',
9   - value: 'copy'
10   - },
11   - {
12   - i18nLabel: 'editor.centerPanel.contextMenu.delete',
13   - label: '删除',
14   - value: 'delete'
15   - },
16   - {
17   - i18nLabel: 'editor.centerPanel.contextMenu.moveToTop',
18   - label: '置顶',
19   - value: 'move2Top'
20   - },
21   - {
22   - i18nLabel: 'editor.centerPanel.contextMenu.moveToBottom',
23   - label: '置底',
24   - value: 'move2Bottom'
25   - },
26   - {
27   - i18nLabel: 'editor.centerPanel.contextMenu.moveUp',
28   - label: '上移',
29   - value: 'addZindex'
30   - },
31   - {
32   - i18nLabel: 'editor.centerPanel.contextMenu.moveDown',
33   - label: '下移',
34   - value: 'minusZindex'
35   - }
36   -]
  3 +import ContextMenu from '../../support/contexmenu'
37 4  
38 5 export default {
39 6 props: ['elements', 'handleClickElementProp', 'handleClickCanvasProp'],
... ... @@ -230,43 +197,14 @@ export default {
230 197 ))
231 198 }
232 199 {
233   - this.contextmenuPos.length
234   - ? <a-menu
235   - ref="contextmenu"
236   - onSelect={({ item, key, selectedKeys }) => {
237   - this.elementManager({ type: key })
238   - }}
239   - // refrence: https://github.com/vueComponent/ant-design-vue/blob/master/components/vc-trigger/Trigger.jsx#L205
240   - onMouseleave={(e) => {
241   - const contextmenu = this.$refs.contextmenu
242   - if (
243   - e &&
244   - e.relatedTarget &&
245   - contextmenu &&
246   - contextmenu.$el &&
247   - contains(e.relatedTarget, contextmenu.$el)
248   - ) {
249   - return
250   - }
251   - this.hideContextMenu()
252   - }}
253   - style={{
254   - left: this.contextmenuPos[0] + 'px',
255   - top: this.contextmenuPos[1] + 'px',
256   - userSelect: 'none',
257   - position: 'absolute',
258   - zIndex: 999
259   - }}
260   - >
261   - { contextmenuOptions.map(option => (
262   - <a-menu-item
263   - key={option.value}
264   - data-command={option.value}
265   - >{this.$t(option.i18nLabel)}</a-menu-item>
266   - ))
267   - }
268   - </a-menu>
269   - : null
  200 + this.contextmenuPos.length &&
  201 + <ContextMenu
  202 + position={this.contextmenuPos}
  203 + onSelect={({ item, key, selectedKeys }) => {
  204 + this.elementManager({ type: key })
  205 + }}
  206 + onHideMenu={this.hideContextMenu}
  207 + />
270 208 }
271 209 </div>
272 210 )
... ...
front-end/h5/src/components/core/support/contexmenu.js 0 → 100644
  1 +
  2 +import { contains } from '../../../utils/dom-helper.js'
  3 +
  4 +const contextmenuOptions = [
  5 + {
  6 + i18nLabel: 'editor.centerPanel.contextMenu.copy',
  7 + label: '复制',
  8 + value: 'copy'
  9 + },
  10 + {
  11 + i18nLabel: 'editor.centerPanel.contextMenu.delete',
  12 + label: '删除',
  13 + value: 'delete'
  14 + }
  15 +]
  16 +
  17 +const zindexContextMenu = [
  18 + {
  19 + i18nLabel: 'editor.centerPanel.contextMenu.moveToTop',
  20 + label: '置顶',
  21 + value: 'move2Top'
  22 + },
  23 + {
  24 + i18nLabel: 'editor.centerPanel.contextMenu.moveToBottom',
  25 + label: '置底',
  26 + value: 'move2Bottom'
  27 + },
  28 + {
  29 + i18nLabel: 'editor.centerPanel.contextMenu.moveUp',
  30 + label: '上移',
  31 + value: 'addZindex'
  32 + },
  33 + {
  34 + i18nLabel: 'editor.centerPanel.contextMenu.moveDown',
  35 + label: '下移',
  36 + value: 'minusZindex'
  37 + }
  38 +]
  39 +
  40 +const horizontalMenuStyle = {
  41 + height: '35px',
  42 + lineHeight: '35px',
  43 + border: 'none',
  44 + borderTop: '1px solid #eee'
  45 + // borderRight: '1px solid #eee'
  46 +}
  47 +
  48 +export default {
  49 + props: {
  50 + position: {
  51 + type: Array,
  52 + default: () => []
  53 + }
  54 + },
  55 + methods: {
  56 + handleSelectMenu ({ item, key, selectedKeys }) {
  57 + // this.elementManager({ type: key })
  58 + this.$emit('select', { item, key, selectedKeys })
  59 + },
  60 + hideContextMenu () {
  61 + this.$emit('hide-menu')
  62 + },
  63 + handleMouseLeave (e) {
  64 + const contextmenu = this.$refs.contextmenu
  65 + if (
  66 + e &&
  67 + e.relatedTarget &&
  68 + contextmenu &&
  69 + contextmenu.$el &&
  70 + contains(e.relatedTarget, contextmenu.$el)
  71 + ) {
  72 + return
  73 + }
  74 + this.hideContextMenu()
  75 + }
  76 + },
  77 + render (h) {
  78 + const contextStyle = {
  79 + left: this.position[0] + 'px',
  80 + top: this.position[1] + 'px',
  81 + userSelect: 'none',
  82 + position: 'absolute',
  83 + zIndex: 999
  84 + }
  85 + return (
  86 + <a-card
  87 + bodyStyle={{ padding: '4px' }}
  88 + ref="contextmenu"
  89 + style={contextStyle}
  90 + // refrence: https://github.com/vueComponent/ant-design-vue/blob/master/components/vc-trigger/Trigger.jsx#L205
  91 + onMouseleave={this.handleMouseLeave}
  92 + >
  93 + <a-menu
  94 + inlineIndent={4}
  95 + mode="inline"
  96 + onSelect={this.handleSelectMenu}
  97 + style={{ border: 'none' }}
  98 + >
  99 + { contextmenuOptions.map(option => (
  100 + <a-menu-item
  101 + key={option.value}
  102 + data-command={option.value}
  103 + style={{ height: '30px', lineHeight: '30px', margin: 0 }}
  104 + >{this.$t(option.i18nLabel)}</a-menu-item>
  105 + ))
  106 + }
  107 + </a-menu>
  108 + <a-menu
  109 + mode="horizontal"
  110 + ref="contextmenu"
  111 + onSelect={this.handleSelectMenu}
  112 + style={horizontalMenuStyle}
  113 + >
  114 + { zindexContextMenu.map(option => (
  115 + <a-menu-item
  116 + key={option.value}
  117 + data-command={option.value}
  118 + style={{ height: '35px', lineHeight: '35px', padding: '0 4px 4px' }}
  119 + >{this.$t(option.i18nLabel)}</a-menu-item>
  120 + ))
  121 + }
  122 + </a-menu>
  123 + </a-card>
  124 + )
  125 + }
  126 +}
... ...