Commit cb5569c044ae14238afd62813f3fe9aadd723277
1 parent
c5edcfaf
feat(canvas): Place the element where the mouse is released; !#zh: 将元素放在鼠标松开的位置
Showing
3 changed files
with
10 additions
and
5 deletions
front-end/h5/src/components/core/editor/drag-mixin.js
| ... | ... | @@ -70,7 +70,7 @@ export default { |
| 70 | 70 | methods: { |
| 71 | 71 | /** |
| 72 | 72 | * |
| 73 | - * @param {*} element | |
| 73 | + * @param {*} element shortcutItem | |
| 74 | 74 | * @param {*} e |
| 75 | 75 | */ |
| 76 | 76 | handleDragStartFromMixin (element, e) { |
| ... | ... | @@ -129,7 +129,7 @@ export default { |
| 129 | 129 | const position = canvasWrapper.getBoundingClientRect() |
| 130 | 130 | this.dragElement && this.clone({ |
| 131 | 131 | ...this.dragElement, |
| 132 | - customStyle: { | |
| 132 | + dragStyle: { | |
| 133 | 133 | left: e.clientX - layerX - position.left, |
| 134 | 134 | top: e.clientY - layerY - position.top |
| 135 | 135 | } | ... | ... |
front-end/h5/src/components/core/models/element.js
| ... | ... | @@ -44,7 +44,8 @@ class Element { |
| 44 | 44 | return { |
| 45 | 45 | ...defaultStyle, |
| 46 | 46 | zindex: ele.zindex, |
| 47 | - ...(ele.extra && ele.extra.defaultStyle) | |
| 47 | + ...(ele.extra && ele.extra.defaultStyle), | |
| 48 | + ...ele.dragStyle // 拖拽结束落点的top、left | |
| 48 | 49 | } |
| 49 | 50 | } |
| 50 | 51 | |
| ... | ... | @@ -52,11 +53,13 @@ class Element { |
| 52 | 53 | if (typeof ele.pluginProps === 'object') { |
| 53 | 54 | return cloneObj({ ...ele.pluginProps, uuid: this.uuid }) |
| 54 | 55 | } |
| 55 | - return this.getDefaultPluginProps(ele.props, ele.shortcutProps) | |
| 56 | + return this.getDefaultPluginProps(ele) | |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | // init prop of plugin |
| 59 | - getDefaultPluginProps (props = {}, shortcutProps) { | |
| 60 | + getDefaultPluginProps (ele) { | |
| 61 | + const { props = {}, shortcutProps = {} } = ele | |
| 62 | + | |
| 60 | 63 | let pluginProps = { |
| 61 | 64 | uuid: this.uuid |
| 62 | 65 | } | ... | ... |
front-end/h5/src/store/modules/element.js
| ... | ... | @@ -41,6 +41,8 @@ export const mutations = { |
| 41 | 41 | case 'add': |
| 42 | 42 | const vm = getVM(value.name) |
| 43 | 43 | vm.$options.shortcutProps = value.shortcutProps |
| 44 | + // 用于拖拽结束,确定最终放置的位置 | |
| 45 | + vm.$options.dragStyle = value.dragStyle // {left: Number, top: Number} | |
| 44 | 46 | const element = new Element(vm.$options) |
| 45 | 47 | elements.push(element) |
| 46 | 48 | break | ... | ... |