Commit 9d9f7ec3c219883faf948de54b0fb5d0e8c88bbf
Committed by
小小鲁班
1 parent
329f47da
perf: improve context menu interaction; !#zh: 优化右键菜单的交互体验
Showing
2 changed files
with
10 additions
and
20 deletions
front-end/h5/src/components/core/editor/canvas/edit.js
| ... | ... | @@ -241,6 +241,11 @@ export default { |
| 241 | 241 | element={element} |
| 242 | 242 | active={this.editingElement === element} |
| 243 | 243 | handleMousedownProp={() => { |
| 244 | + // 优化右键菜单的交互体验: | |
| 245 | + // 原来的交互为:鼠标一旦离开 contextmenu,即刻消失 | |
| 246 | + // 带来的体验问题:有时候鼠标不小心滑到右键菜单外边,还没操作完,菜单消失了 | |
| 247 | + // 改进:1. 鼠标离开,右键菜单不消失 2. 点击画布的时候,隐藏右键菜单(包含点击editingElement + 画布) | |
| 248 | + this.hideContextMenu() | |
| 244 | 249 | // 在 shape 上面添加 mousedown,而非 plugin 本身添加 onClick 的原因: |
| 245 | 250 | // 在 mousedown 的时候,即可激活 editingElement(当前选中元素) |
| 246 | 251 | // 这样,就不用等到鼠标抬起的时候,也就是 plugin 的 onClick 生效的时候,才给选中的元素添加边框等选中效果 | ... | ... |
front-end/h5/src/components/core/support/contexmenu.js
| 1 | 1 | |
| 2 | -// import { contains } from '../../../utils/dom-helper.js' | |
| 3 | - | |
| 2 | +/** | |
| 3 | + * jsx 相关参考链接: | |
| 4 | + * onMouseleave: https://github.com/vueComponent/ant-design-vue/blob/master/components/vc-trigger/Trigger.jsx#L205 | |
| 5 | + * | |
| 6 | + */ | |
| 4 | 7 | const contextmenuOptions = [ |
| 5 | 8 | { |
| 6 | 9 | i18nLabel: 'editor.centerPanel.contextMenu.copy', |
| ... | ... | @@ -54,22 +57,6 @@ export default { |
| 54 | 57 | methods: { |
| 55 | 58 | handleSelectMenu ({ item, key, selectedKeys }) { |
| 56 | 59 | this.$emit('select', { item, key, selectedKeys }) // elementManager({ type: key }) |
| 57 | - }, | |
| 58 | - hideContextMenu () { | |
| 59 | - this.$emit('hideMenu') | |
| 60 | - }, | |
| 61 | - handleMouseLeave (e) { | |
| 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 | - // } | |
| 72 | - this.hideContextMenu() | |
| 73 | 60 | } |
| 74 | 61 | }, |
| 75 | 62 | render (h) { |
| ... | ... | @@ -85,8 +72,6 @@ export default { |
| 85 | 72 | bodyStyle={{ padding: '4px' }} |
| 86 | 73 | ref="contextmenu" |
| 87 | 74 | style={contextStyle} |
| 88 | - // refrence: https://github.com/vueComponent/ant-design-vue/blob/master/components/vc-trigger/Trigger.jsx#L205 | |
| 89 | - onMouseleave={this.handleMouseLeave} | |
| 90 | 75 | > |
| 91 | 76 | <a-menu |
| 92 | 77 | inlineIndent={4} | ... | ... |