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,7 +70,7 @@ export default { | ||
| 70 | methods: { | 70 | methods: { |
| 71 | /** | 71 | /** |
| 72 | * | 72 | * |
| 73 | - * @param {*} element | 73 | + * @param {*} element shortcutItem |
| 74 | * @param {*} e | 74 | * @param {*} e |
| 75 | */ | 75 | */ |
| 76 | handleDragStartFromMixin (element, e) { | 76 | handleDragStartFromMixin (element, e) { |
| @@ -129,7 +129,7 @@ export default { | @@ -129,7 +129,7 @@ export default { | ||
| 129 | const position = canvasWrapper.getBoundingClientRect() | 129 | const position = canvasWrapper.getBoundingClientRect() |
| 130 | this.dragElement && this.clone({ | 130 | this.dragElement && this.clone({ |
| 131 | ...this.dragElement, | 131 | ...this.dragElement, |
| 132 | - customStyle: { | 132 | + dragStyle: { |
| 133 | left: e.clientX - layerX - position.left, | 133 | left: e.clientX - layerX - position.left, |
| 134 | top: e.clientY - layerY - position.top | 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,7 +44,8 @@ class Element { | ||
| 44 | return { | 44 | return { |
| 45 | ...defaultStyle, | 45 | ...defaultStyle, |
| 46 | zindex: ele.zindex, | 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,11 +53,13 @@ class Element { | ||
| 52 | if (typeof ele.pluginProps === 'object') { | 53 | if (typeof ele.pluginProps === 'object') { |
| 53 | return cloneObj({ ...ele.pluginProps, uuid: this.uuid }) | 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 | // init prop of plugin | 59 | // init prop of plugin |
| 59 | - getDefaultPluginProps (props = {}, shortcutProps) { | 60 | + getDefaultPluginProps (ele) { |
| 61 | + const { props = {}, shortcutProps = {} } = ele | ||
| 62 | + | ||
| 60 | let pluginProps = { | 63 | let pluginProps = { |
| 61 | uuid: this.uuid | 64 | uuid: this.uuid |
| 62 | } | 65 | } |
front-end/h5/src/store/modules/element.js
| @@ -41,6 +41,8 @@ export const mutations = { | @@ -41,6 +41,8 @@ export const mutations = { | ||
| 41 | case 'add': | 41 | case 'add': |
| 42 | const vm = getVM(value.name) | 42 | const vm = getVM(value.name) |
| 43 | vm.$options.shortcutProps = value.shortcutProps | 43 | vm.$options.shortcutProps = value.shortcutProps |
| 44 | + // 用于拖拽结束,确定最终放置的位置 | ||
| 45 | + vm.$options.dragStyle = value.dragStyle // {left: Number, top: Number} | ||
| 44 | const element = new Element(vm.$options) | 46 | const element = new Element(vm.$options) |
| 45 | elements.push(element) | 47 | elements.push(element) |
| 46 | break | 48 | break |