Commit 7bd33cb77225c6c306d93a944ebc9db9c7593470
1 parent
9d9f7ec3
refactor: update contextmenu style
Showing
3 changed files
with
45 additions
and
35 deletions
front-end/h5/src/components/core/editor/canvas/edit.js
| @@ -119,19 +119,6 @@ export default { | @@ -119,19 +119,6 @@ export default { | ||
| 119 | // 优化右击菜单的显示,去除冗余的无效逻辑 | 119 | // 优化右击菜单的显示,去除冗余的无效逻辑 |
| 120 | const { x, y } = this.$el.getBoundingClientRect() | 120 | const { x, y } = this.$el.getBoundingClientRect() |
| 121 | this.contextmenuPos = [e.clientX - x, e.clientY - y] | 121 | this.contextmenuPos = [e.clientX - x, e.clientY - y] |
| 122 | - // console.log(e.target) | ||
| 123 | - // console.log(e.target.classList) | ||
| 124 | - // // e.preventDefault() // 不显示默认的右击菜单 | ||
| 125 | - // if ( | ||
| 126 | - // e.target.classList.contains('element-on-edit-canvas') || | ||
| 127 | - // e.target.parentElement.classList.contains('element-on-edit-canvas') | ||
| 128 | - // ) { | ||
| 129 | - // const { x, y } = this.$el.getBoundingClientRect() | ||
| 130 | - // console.log(x, y) | ||
| 131 | - // this.contextmenuPos = [e.clientX - x, e.clientY - y] | ||
| 132 | - // } else { | ||
| 133 | - // this.hideContextMenu() | ||
| 134 | - // } | ||
| 135 | }, | 122 | }, |
| 136 | hideContextMenu () { | 123 | hideContextMenu () { |
| 137 | this.contextmenuPos = [] | 124 | this.contextmenuPos = [] |
| @@ -289,7 +276,13 @@ export default { | @@ -289,7 +276,13 @@ export default { | ||
| 289 | { | 276 | { |
| 290 | this.contextmenuPos.length | 277 | this.contextmenuPos.length |
| 291 | ? <ContextMenu | 278 | ? <ContextMenu |
| 292 | - position={this.contextmenuPos} | 279 | + style={{ |
| 280 | + left: this.contextmenuPos[0] + 'px', | ||
| 281 | + top: this.contextmenuPos[1] + 'px', | ||
| 282 | + userSelect: 'none', | ||
| 283 | + position: 'absolute', | ||
| 284 | + zIndex: 999 | ||
| 285 | + }} | ||
| 293 | onSelect={({ item, key, selectedKeys }) => { | 286 | onSelect={({ item, key, selectedKeys }) => { |
| 294 | this.elementManager({ type: key }) | 287 | this.elementManager({ type: key }) |
| 295 | this.hideContextMenu() | 288 | this.hideContextMenu() |
front-end/h5/src/components/core/support/contexmenu.js
| 1 | 1 | ||
| 2 | /** | 2 | /** |
| 3 | + * 右键菜单 | ||
| 4 | + * | ||
| 5 | + * 效果: | ||
| 6 | + * - 复制 | ||
| 7 | + * - 删除 | ||
| 8 | + * - 置顶、置底、上移、下移 | ||
| 9 | + * | ||
| 3 | * jsx 相关参考链接: | 10 | * jsx 相关参考链接: |
| 4 | * onMouseleave: https://github.com/vueComponent/ant-design-vue/blob/master/components/vc-trigger/Trigger.jsx#L205 | 11 | * onMouseleave: https://github.com/vueComponent/ant-design-vue/blob/master/components/vc-trigger/Trigger.jsx#L205 |
| 5 | * | 12 | * |
| 6 | */ | 13 | */ |
| 14 | + | ||
| 15 | +import './contexmenu.scss' | ||
| 16 | + | ||
| 17 | +// 垂直菜单 | ||
| 7 | const contextmenuOptions = [ | 18 | const contextmenuOptions = [ |
| 8 | { | 19 | { |
| 9 | i18nLabel: 'editor.centerPanel.contextMenu.copy', | 20 | i18nLabel: 'editor.centerPanel.contextMenu.copy', |
| @@ -17,6 +28,7 @@ const contextmenuOptions = [ | @@ -17,6 +28,7 @@ const contextmenuOptions = [ | ||
| 17 | } | 28 | } |
| 18 | ] | 29 | ] |
| 19 | 30 | ||
| 31 | +// 水平菜单 | ||
| 20 | const zindexContextMenu = [ | 32 | const zindexContextMenu = [ |
| 21 | { | 33 | { |
| 22 | i18nLabel: 'editor.centerPanel.contextMenu.moveToTop', | 34 | i18nLabel: 'editor.centerPanel.contextMenu.moveToTop', |
| @@ -40,13 +52,6 @@ const zindexContextMenu = [ | @@ -40,13 +52,6 @@ const zindexContextMenu = [ | ||
| 40 | } | 52 | } |
| 41 | ] | 53 | ] |
| 42 | 54 | ||
| 43 | -const horizontalMenuStyle = { | ||
| 44 | - height: '35px', | ||
| 45 | - lineHeight: '35px', | ||
| 46 | - border: 'none', | ||
| 47 | - borderTop: '1px solid #eee' | ||
| 48 | -} | ||
| 49 | - | ||
| 50 | export default { | 55 | export default { |
| 51 | props: { | 56 | props: { |
| 52 | position: { | 57 | position: { |
| @@ -60,45 +65,36 @@ export default { | @@ -60,45 +65,36 @@ export default { | ||
| 60 | } | 65 | } |
| 61 | }, | 66 | }, |
| 62 | render (h) { | 67 | render (h) { |
| 63 | - const contextStyle = { | ||
| 64 | - left: this.position[0] + 'px', | ||
| 65 | - top: this.position[1] + 'px', | ||
| 66 | - userSelect: 'none', | ||
| 67 | - position: 'absolute', | ||
| 68 | - zIndex: 999 | ||
| 69 | - } | ||
| 70 | return ( | 68 | return ( |
| 71 | <a-card | 69 | <a-card |
| 72 | bodyStyle={{ padding: '4px' }} | 70 | bodyStyle={{ padding: '4px' }} |
| 73 | - ref="contextmenu" | ||
| 74 | - style={contextStyle} | 71 | + class="contextmenu" |
| 75 | > | 72 | > |
| 76 | <a-menu | 73 | <a-menu |
| 77 | inlineIndent={4} | 74 | inlineIndent={4} |
| 78 | mode="inline" | 75 | mode="inline" |
| 79 | onSelect={this.handleSelectMenu} | 76 | onSelect={this.handleSelectMenu} |
| 80 | - style={{ border: 'none' }} | 77 | + class="contextmenu__vertical-menus" |
| 81 | > | 78 | > |
| 82 | { contextmenuOptions.map(option => ( | 79 | { contextmenuOptions.map(option => ( |
| 83 | <a-menu-item | 80 | <a-menu-item |
| 84 | key={option.value} | 81 | key={option.value} |
| 85 | data-command={option.value} | 82 | data-command={option.value} |
| 86 | - style={{ height: '30px', lineHeight: '30px', margin: 0 }} | 83 | + class="contextmenu__vertical-menus__item" |
| 87 | >{this.$t(option.i18nLabel)}</a-menu-item> | 84 | >{this.$t(option.i18nLabel)}</a-menu-item> |
| 88 | )) | 85 | )) |
| 89 | } | 86 | } |
| 90 | </a-menu> | 87 | </a-menu> |
| 91 | <a-menu | 88 | <a-menu |
| 92 | mode="horizontal" | 89 | mode="horizontal" |
| 93 | - ref="contextmenu" | ||
| 94 | onSelect={this.handleSelectMenu} | 90 | onSelect={this.handleSelectMenu} |
| 95 | - style={horizontalMenuStyle} | 91 | + class="contextmenu__horizontal-menus" |
| 96 | > | 92 | > |
| 97 | { zindexContextMenu.map(option => ( | 93 | { zindexContextMenu.map(option => ( |
| 98 | <a-menu-item | 94 | <a-menu-item |
| 99 | key={option.value} | 95 | key={option.value} |
| 100 | data-command={option.value} | 96 | data-command={option.value} |
| 101 | - style={{ height: '35px', lineHeight: '35px', padding: '0 4px 4px' }} | 97 | + class="contextmenu__horizontal-menus__item" |
| 102 | >{this.$t(option.i18nLabel)}</a-menu-item> | 98 | >{this.$t(option.i18nLabel)}</a-menu-item> |
| 103 | )) | 99 | )) |
| 104 | } | 100 | } |
front-end/h5/src/components/core/support/contexmenu.scss
0 → 100644
| 1 | +.contextmenu { | ||
| 2 | + &__horizontal-menus { | ||
| 3 | + height: 32px; | ||
| 4 | + line-height: 32px; | ||
| 5 | + border: none; | ||
| 6 | + border-top: 1px solid #eee; | ||
| 7 | + | ||
| 8 | + &__item { | ||
| 9 | + padding: 0 4px 4px; | ||
| 10 | + } | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + &__vertical-menus { | ||
| 14 | + border: none; | ||
| 15 | + &__item { | ||
| 16 | + height: 22px !important; | ||
| 17 | + line-height: 22px !important; | ||
| 18 | + margin: 0; | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | +} |