Skip to content

Commit

Permalink
feat(canvas): Place the element where the mouse is released; !#zh: 将元…
Browse files Browse the repository at this point in the history
…素放在鼠标松开的位置
  • Loading branch information
ly525 committed Aug 30, 2020
1 parent c5edcfa commit cb5569c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions front-end/h5/src/components/core/editor/drag-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default {
methods: {
/**
*
* @param {*} element
* @param {*} element shortcutItem
* @param {*} e
*/
handleDragStartFromMixin (element, e) {
Expand Down Expand Up @@ -129,7 +129,7 @@ export default {
const position = canvasWrapper.getBoundingClientRect()
this.dragElement && this.clone({
...this.dragElement,
customStyle: {
dragStyle: {
left: e.clientX - layerX - position.left,
top: e.clientY - layerY - position.top
}
Expand Down
9 changes: 6 additions & 3 deletions front-end/h5/src/components/core/models/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ class Element {
return {
...defaultStyle,
zindex: ele.zindex,
...(ele.extra && ele.extra.defaultStyle)
...(ele.extra && ele.extra.defaultStyle),
...ele.dragStyle // 拖拽结束落点的top、left
}
}

getPluginProps (ele) {
if (typeof ele.pluginProps === 'object') {
return cloneObj({ ...ele.pluginProps, uuid: this.uuid })
}
return this.getDefaultPluginProps(ele.props, ele.shortcutProps)
return this.getDefaultPluginProps(ele)
}

// init prop of plugin
getDefaultPluginProps (props = {}, shortcutProps) {
getDefaultPluginProps (ele) {
const { props = {}, shortcutProps = {} } = ele

let pluginProps = {
uuid: this.uuid
}
Expand Down
2 changes: 2 additions & 0 deletions front-end/h5/src/store/modules/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const mutations = {
case 'add':
const vm = getVM(value.name)
vm.$options.shortcutProps = value.shortcutProps
// 用于拖拽结束,确定最终放置的位置
vm.$options.dragStyle = value.dragStyle // {left: Number, top: Number}
const element = new Element(vm.$options)
elements.push(element)
break
Expand Down

0 comments on commit cb5569c

Please sign in to comment.