Skip to content

Commit f0f68fd

Browse files
committed
fix: drag move active element
1 parent 1d45405 commit f0f68fd

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/components/viewport/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ export default {
116116
}
117117
},
118118
119-
// FIXME: indexOf('image') 替换图片
119+
// 替换图片
120120
replaceImage (e) {
121-
if (this.id.toLowerCase().indexOf('image') > -1) {
121+
if (this.$store.state.activeElement.isUpload) {
122122
window.$communicator.$emit('upload', payload => {
123123
this.$store.commit('replaceImage', payload)
124124
})

src/components/viewport/ref-lines.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ export default {
3131
guides () {
3232
var state = this.$store.state
3333
var guides = []
34-
var index = state.index
34+
var uuid = state.uuid
3535
36-
state.widgets.forEach((item, i) => {
36+
state.widgets.forEach(item => {
3737
// 排除选中元素
38-
if (item.hasGuide && i === index) return
38+
if (item.hasGuide && item.uuid === uuid) return
3939
// 排除容器中的元件
4040
if (item.hasGuide && item.belong !== 'page') return
4141

src/store/actions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
export default {
22
addWidget ({ state, commit }, item) {
3-
if (item.isUpload) {
3+
if (item.setting.isUpload) {
44
window.$communicator.$emit('upload', (payload) => {
55
commit('addWidget', { data: payload, item })
66
}, true)
77
} else {
88
commit('addWidget', { item })
99
// 设置选中
1010
commit('select', {
11-
type: item.setting.type,
12-
index: state.widgets.length - 1
11+
uuid: state.widgets[state.widgets.length - 1].uuid
1312
})
1413
}
1514
},

src/store/mutation.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ export default {
66
state.uuid = payload.uuid
77
if (payload.uuid === -1) {
88
state.activeElement = state.page
9+
state.type = 'page'
910
} else {
10-
state.activeElement = state.widgets.find(w => w.uuid === payload.uuid)
11+
let widget = state.widgets.find(w => w.uuid === payload.uuid)
12+
state.activeElement = widget
13+
state.type = widget.type
1114
}
1215
},
1316

@@ -146,8 +149,8 @@ export default {
146149

147150
// 重置 activeElement
148151
state.activeElement = state.page
149-
state.type = 'page'
150-
state.index = -1
152+
// state.type = 'page'
153+
state.uuid = -1
151154
},
152155

153156
// 添加组件

0 commit comments

Comments
 (0)