element.js
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Element from '../../components/core/models/element'
import { getEditorConfigForEditingElement, swapZindex } from '../../utils/element'
// actions
export const actions = {
setEditingElement ({ commit }, payload) {
commit('setEditingElement', payload)
const vm = (payload && payload.name) ? getEditorConfigForEditingElement(payload.name) : null
commit('setEditingElementEditorConfig', vm)
},
setElementPosition ({ commit }, payload) {
commit('setElementCommonStyle', payload)
},
setElementShape ({ commit }, payload) {
commit('setElementCommonStyle', payload)
},
recordElementRect ({ commit }, payload = {}) {
commit('recordRect', payload)
},
elementManager ({ commit }, payload) {
commit('elementManager', payload)
}
}
// mutations
export const mutations = {
setEditingElement (state, payload) {
state.editingElement = payload
},
setEditingElementEditorConfig (state, payload) {
state.editingElementEditorConfig = payload
},
setElementCommonStyle (state, payload) {
state.editingElement.commonStyle = {
...state.editingElement.commonStyle,
...payload
}
},
elementManager (state, { type, value }) {
const { editingPage, editingElement } = state
const elements = editingPage.elements
const len = elements.length
switch (type) {
case 'add':
value = {
...value,
zindex: len + 1
}
const element = new Element(value)
elements.push(element)
break
case 'copy':
elements.push(state.editingElement.clone({ zindex: len + 1 }))
break
case 'delete':
{
const index = elements.findIndex(e => e.uuid === editingElement.uuid)
if (index !== -1) {
// let newElements = elements.slice()
// newElements.splice(index, 1)
// state.editingPage.elements = newElements
state.editingPage.elements.splice(index, 1)
}
state.editingElement = null
}
break
case 'move2Top':
case 'move2Bottom':
{
const index = elements.findIndex(e => e.uuid === editingElement.uuid)
elements.splice(index, 1)
const newElements = type === 'move2Top' ? [...elements, editingElement] : [editingElement, ...elements]
newElements.forEach((ele, i, arr) => {
ele.commonStyle.zindex = i + 1
})
state.editingPage.elements = newElements
}
break
case 'addZindex':
case 'minusZindex':
const maxZindex = elements.length
const eleZindex = editingElement.commonStyle.zindex
if (eleZindex === maxZindex || eleZindex === 1) return
const flag = type === 'addZindex' ? 1 : -1
const swapElement = elements.find(ele => ele.commonStyle.zindex === eleZindex + flag * 1)
swapZindex(editingElement, swapElement)
break
default:
}
},
recordRect (state, { type, value }) {
}
}