Commit cce6ac60fc75ffa6a52f6f7859242951417a1c46

Authored by ly525
1 parent ff410b22

refactor(guideline): (en)update element position with the adsorption line; (zh)根据吸附线位置,更新元素的位置;

front-end/h5/src/components/core/editor/canvas/edit.js
... ... @@ -15,17 +15,21 @@ export default {
15 15 },
16 16 methods: {
17 17 ...mapActions('element', [
18   - 'setEditingElement' // -> this.foo()
  18 + 'setEditingElement', // -> this.foo()
  19 + 'setElementPosition', // -> this.foo()
  20 + 'setElementShape' // -> this.foo()
19 21 ]),
20 22 // TODO #!zh: 优化代码
21 23 // generate vertical line
22 24 drawVLine (newLeft) {
23   - this.editingElement.commonStyle.left = newLeft
  25 + // this.editingElement.commonStyle.left = newLeft
  26 + this.setElementPosition({ left: newLeft })
24 27 this.vLines = [{ left: newLeft }]
25 28 },
26 29 // generate horizontal line
27 30 drawHLine (newTop) {
28   - this.editingElement.commonStyle.top = newTop
  31 + // this.editingElement.commonStyle.top = newTop
  32 + this.setElementPosition({ top: newTop })
29 33 this.hLines = [{ top: newTop }]
30 34 },
31 35 calcX (newLeft) {
... ...
front-end/h5/src/store/modules/element.js
... ... @@ -12,6 +12,12 @@ const getters = {
12 12 const actions = {
13 13 setEditingElement ({ commit }, payload) {
14 14 commit('setEditingElement', payload)
  15 + },
  16 + setElementPosition ({ commit }, payload) {
  17 + commit('setElementPosition', payload)
  18 + },
  19 + setElementShape ({ commit }, payload) {
  20 + commit('setElementShape', payload)
15 21 }
16 22 }
17 23  
... ... @@ -19,6 +25,12 @@ const actions = {
19 25 const mutations = {
20 26 setEditingElement (state, payload) {
21 27 state.editingElement = payload
  28 + },
  29 + setElementCommonStyle (state, commonStyle) {
  30 + state.editingElement.commonStyle = {
  31 + ...state.editingElement.commonStyle,
  32 + ...commonStyle
  33 + }
22 34 }
23 35 }
24 36  
... ...