Commit 4fb2f41ead253d3e22f586428dd91e7cc8f4eab4
1 parent
13cf3423
perform: update contextmenu
Showing
2 changed files
with
41 additions
and
26 deletions
front-end/h5/src/components/core/editor/canvas/edit.js
| ... | ... | @@ -92,16 +92,22 @@ export default { |
| 92 | 92 | this.calcY(top) |
| 93 | 93 | }, |
| 94 | 94 | bindContextMenu (e) { |
| 95 | - e.preventDefault() // 不显示默认的右击菜单 | |
| 96 | - if ( | |
| 97 | - e.target.classList.contains('element-on-edit-canvas') || | |
| 98 | - e.target.parentElement.classList.contains('element-on-edit-canvas') | |
| 99 | - ) { | |
| 100 | - const { x, y } = this.$el.getBoundingClientRect() | |
| 101 | - this.contextmenuPos = [e.clientX - x, e.clientY - y] | |
| 102 | - } else { | |
| 103 | - this.hideContextMenu() | |
| 104 | - } | |
| 95 | + // 优化右击菜单的显示,去除冗余的无效逻辑 | |
| 96 | + const { x, y } = this.$el.getBoundingClientRect() | |
| 97 | + this.contextmenuPos = [e.clientX - x, e.clientY - y] | |
| 98 | + // console.log(e.target) | |
| 99 | + // console.log(e.target.classList) | |
| 100 | + // // e.preventDefault() // 不显示默认的右击菜单 | |
| 101 | + // if ( | |
| 102 | + // e.target.classList.contains('element-on-edit-canvas') || | |
| 103 | + // e.target.parentElement.classList.contains('element-on-edit-canvas') | |
| 104 | + // ) { | |
| 105 | + // const { x, y } = this.$el.getBoundingClientRect() | |
| 106 | + // console.log(x, y) | |
| 107 | + // this.contextmenuPos = [e.clientX - x, e.clientY - y] | |
| 108 | + // } else { | |
| 109 | + // this.hideContextMenu() | |
| 110 | + // } | |
| 105 | 111 | }, |
| 106 | 112 | hideContextMenu () { |
| 107 | 113 | this.contextmenuPos = [] |
| ... | ... | @@ -128,7 +134,9 @@ export default { |
| 128 | 134 | this.handleClickCanvas(e) |
| 129 | 135 | }} |
| 130 | 136 | onContextmenu={e => { |
| 131 | - this.bindContextMenu(e) | |
| 137 | + e.preventDefault() | |
| 138 | + e.stopPropagation() | |
| 139 | + // this.bindContextMenu(e) | |
| 132 | 140 | }} |
| 133 | 141 | > |
| 134 | 142 | { |
| ... | ... | @@ -147,6 +155,11 @@ export default { |
| 147 | 155 | // 当点击编辑画布上的其它区域(clickEvent.target.classList 不包含下面的 className)的时候,设置 editingElement=null |
| 148 | 156 | class: 'element-on-edit-canvas', |
| 149 | 157 | props: element.getProps(), // #6 #3 |
| 158 | + // nativeOn: { | |
| 159 | + // contextmenu: e => { | |
| 160 | + // this.bindContextMenu(e) | |
| 161 | + // } | |
| 162 | + // }, | |
| 150 | 163 | on: { |
| 151 | 164 | // 高亮当前点击的元素 |
| 152 | 165 | // click: () => this.setEditingElement(element) |
| ... | ... | @@ -180,6 +193,9 @@ export default { |
| 180 | 193 | handlePointMouseUpProp={() => { |
| 181 | 194 | this.recordElementRect() |
| 182 | 195 | }} |
| 196 | + nativeOnContextmenu={e => { | |
| 197 | + this.bindContextMenu(e) | |
| 198 | + }} | |
| 183 | 199 | > |
| 184 | 200 | {h(element.name, data)} |
| 185 | 201 | </Shape> |
| ... | ... | @@ -202,6 +218,7 @@ export default { |
| 202 | 218 | position={this.contextmenuPos} |
| 203 | 219 | onSelect={({ item, key, selectedKeys }) => { |
| 204 | 220 | this.elementManager({ type: key }) |
| 221 | + this.hideContextMenu() | |
| 205 | 222 | }} |
| 206 | 223 | onHideMenu={this.hideContextMenu} |
| 207 | 224 | /> | ... | ... |
front-end/h5/src/components/core/support/contexmenu.js
| 1 | 1 | |
| 2 | -import { contains } from '../../../utils/dom-helper.js' | |
| 2 | +// import { contains } from '../../../utils/dom-helper.js' | |
| 3 | 3 | |
| 4 | 4 | const contextmenuOptions = [ |
| 5 | 5 | { |
| ... | ... | @@ -42,7 +42,6 @@ const horizontalMenuStyle = { |
| 42 | 42 | lineHeight: '35px', |
| 43 | 43 | border: 'none', |
| 44 | 44 | borderTop: '1px solid #eee' |
| 45 | - // borderRight: '1px solid #eee' | |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | export default { |
| ... | ... | @@ -54,23 +53,22 @@ export default { |
| 54 | 53 | }, |
| 55 | 54 | methods: { |
| 56 | 55 | handleSelectMenu ({ item, key, selectedKeys }) { |
| 57 | - // this.elementManager({ type: key }) | |
| 58 | - this.$emit('select', { item, key, selectedKeys }) | |
| 56 | + this.$emit('select', { item, key, selectedKeys }) // elementManager({ type: key }) | |
| 59 | 57 | }, |
| 60 | 58 | hideContextMenu () { |
| 61 | - this.$emit('hide-menu') | |
| 59 | + this.$emit('hideMenu') | |
| 62 | 60 | }, |
| 63 | 61 | 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 | - } | |
| 62 | + // const contextmenu = this.$refs.contextmenu | |
| 63 | + // if ( | |
| 64 | + // e && | |
| 65 | + // e.relatedTarget && | |
| 66 | + // contextmenu && | |
| 67 | + // contextmenu.$el && | |
| 68 | + // contains(e.relatedTarget, contextmenu.$el) | |
| 69 | + // ) { | |
| 70 | + // return | |
| 71 | + // } | |
| 74 | 72 | this.hideContextMenu() |
| 75 | 73 | } |
| 76 | 74 | }, | ... | ... |