|
|
@ -6,7 +6,10 @@ |
|
|
|
@dragleave="dragleave" |
|
|
|
@dragover="dragover" |
|
|
|
@drop="drop" |
|
|
|
@mousedown="clearActive" |
|
|
|
> |
|
|
|
{{ current }} |
|
|
|
{{ history.length }} |
|
|
|
<Shape |
|
|
|
v-for="(item, index) in componentList" |
|
|
|
ref="shape" |
|
|
@ -16,9 +19,17 @@ |
|
|
|
movingIndex != -1 && movingIndex != index ? 'staying' : '', |
|
|
|
]" |
|
|
|
:key="index" |
|
|
|
@update="update" |
|
|
|
@over="over" |
|
|
|
:index="index" |
|
|
|
@changeSize="changeSize($event, index)" |
|
|
|
:style="[$computeStyle(item.style)]" |
|
|
|
> |
|
|
|
<customComponent :detail="item" :key="index" /> |
|
|
|
<customComponent |
|
|
|
:style="[$computeStyle(item.style, true)]" |
|
|
|
:detail="item" |
|
|
|
:key="index" |
|
|
|
/> |
|
|
|
</Shape> |
|
|
|
<MakeLine ref="makeline"> </MakeLine> |
|
|
|
</div> |
|
|
@ -31,6 +42,11 @@ import Shape from "./Shape"; |
|
|
|
import customComponent from "./customComponent"; |
|
|
|
import MakeLine from "./MakeLine"; |
|
|
|
export default { |
|
|
|
provide() { |
|
|
|
return { |
|
|
|
active: this.activeComponent, |
|
|
|
}; |
|
|
|
}, |
|
|
|
components: { |
|
|
|
Shape, |
|
|
|
customComponent, |
|
|
@ -41,29 +57,94 @@ export default { |
|
|
|
isEnter: false, |
|
|
|
movingIndex: -1, |
|
|
|
activeIndex: -1, |
|
|
|
current: 0, |
|
|
|
componentList: [], |
|
|
|
history: [], |
|
|
|
activeComponent: { |
|
|
|
index: -1, |
|
|
|
comp: null, |
|
|
|
}, |
|
|
|
}; |
|
|
|
}, |
|
|
|
created () { |
|
|
|
created() { |
|
|
|
// 更新了一个组件 |
|
|
|
this.$event.$on("@editor:publish:updateOne",(item,index)=>{ |
|
|
|
this.$event.$on("@editor:publish:updateOne", (item, index) => { |
|
|
|
this.componentList.splice(index, 1, item); |
|
|
|
// 绑定历史记录 |
|
|
|
// 更新了组件状态 |
|
|
|
this.$event.$emit("@editor:notice:update",item,index); |
|
|
|
}) |
|
|
|
this.$refs.makeline.listenerChange(this.componentList, index); |
|
|
|
this.$event.$emit("@editor:notice:update", item, index); |
|
|
|
}); |
|
|
|
this.$event.$on("@editor:publish:chexiao", () => { |
|
|
|
if (this.current - 1 >= 0) { |
|
|
|
// 深克隆 |
|
|
|
this.componentList = cloneDeep(this.history[this.current - 1]); |
|
|
|
this.current -= 1; |
|
|
|
} |
|
|
|
}); |
|
|
|
this.$event.$on("@editor:publish:cz", () => { |
|
|
|
if (this.current + 1 < this.history.length) { |
|
|
|
// 深克隆 |
|
|
|
this.componentList = cloneDeep(this.history[this.current + 1]); |
|
|
|
this.current += 1; |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
beforeDestroy(){ |
|
|
|
this.$event.$off("@editor:publish:updateOne") |
|
|
|
beforeDestroy() { |
|
|
|
this.$event.$off("@editor:publish:updateOne"); |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
update() { |
|
|
|
this.$event.$emit( |
|
|
|
"@editor:notice:update", |
|
|
|
this.componentList[this.activeIndex], |
|
|
|
this.activeIndex |
|
|
|
); |
|
|
|
// this.$refs.makeline.listenerChange( |
|
|
|
// this.componentList, |
|
|
|
// this.activeIndex, |
|
|
|
// (item, index) => { |
|
|
|
// this.$event.$emit("@editor:notice:update", item, index); |
|
|
|
// }, |
|
|
|
// true |
|
|
|
// ); |
|
|
|
}, |
|
|
|
over() { |
|
|
|
this.history.push(cloneDeep(this.componentList)); |
|
|
|
this.current = this.history.length - 1; |
|
|
|
}, |
|
|
|
clearActive() { |
|
|
|
this.$refs.makeline.removeAll(); |
|
|
|
this.activeIndex = -1; |
|
|
|
this.$event.$emit("@editor:publish:unActive"); |
|
|
|
this.activeComponent.comp = null; |
|
|
|
this.activeComponent.index = -1; |
|
|
|
}, |
|
|
|
changeSize(sty, index) { |
|
|
|
let el = this.componentList[index]; |
|
|
|
el.style.width = sty.w; |
|
|
|
el.style.height = sty.h; |
|
|
|
el.style.left = sty.l; |
|
|
|
el.style.top = sty.t; |
|
|
|
|
|
|
|
this.componentList.splice(index, 1, el); |
|
|
|
// 派发组件更新事件 |
|
|
|
this.$event.$emit("@editor:notice:update", el, index); |
|
|
|
}, |
|
|
|
mousedown(ev, index) { |
|
|
|
ev.stopPropagation(); |
|
|
|
let startX = ev.clientX; |
|
|
|
let startY = ev.clientY; |
|
|
|
let startW = this.$refs.shape[index].$el.offsetLeft; |
|
|
|
let startH = this.$refs.shape[index].$el.offsetTop; |
|
|
|
this.activeIndex = index |
|
|
|
this.$event.$emit("@editor:publish:activeOne",this.componentList[index],index); |
|
|
|
this.activeIndex = index; |
|
|
|
this.activeComponent.comp = this.componentList[index]; |
|
|
|
this.activeComponent.index = index; |
|
|
|
this.$event.$emit( |
|
|
|
"@editor:publish:activeOne", |
|
|
|
this.componentList[index], |
|
|
|
index |
|
|
|
); |
|
|
|
let isMoving = false; |
|
|
|
document.onmousemove = (ex) => { |
|
|
|
if (!isMoving && Math.abs(ex.clientX - startX) > 1) { |
|
|
@ -80,14 +161,22 @@ export default { |
|
|
|
el.style.top = offsetY; |
|
|
|
this.componentList.splice(index, 1, el); |
|
|
|
// 派发组件更新事件 |
|
|
|
this.$event.$emit("@editor:notice:update",el,index); |
|
|
|
this.$refs.makeline.listenerChange(this.componentList, index,(item,index)=>{ |
|
|
|
this.$event.$emit("@editor:notice:update",item,index); |
|
|
|
}); |
|
|
|
this.$event.$emit("@editor:notice:update", el, index); |
|
|
|
this.$refs.makeline.listenerChange( |
|
|
|
this.componentList, |
|
|
|
index, |
|
|
|
(item, index) => { |
|
|
|
this.$event.$emit("@editor:notice:update", item, index); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
}; |
|
|
|
document.onmouseup = (ex) => { |
|
|
|
// 绑定历史记录 |
|
|
|
if (isMoving) { |
|
|
|
this.history.push(cloneDeep(this.componentList)); |
|
|
|
this.current = this.history.length - 1; |
|
|
|
} |
|
|
|
this.$refs.makeline.removeAll(); |
|
|
|
isMoving = false; |
|
|
|
this.movingIndex = -1; |
|
|
@ -107,6 +196,7 @@ export default { |
|
|
|
drop(ev) { |
|
|
|
ev.stopPropagation(); |
|
|
|
try { |
|
|
|
this.clearActive(); |
|
|
|
this.isEnter = false; |
|
|
|
var { id, x, y } = JSON.parse( |
|
|
|
decodeURIComponent(ev.dataTransfer.getData("component-transfer")) |
|
|
@ -117,6 +207,8 @@ export default { |
|
|
|
el.style.left = offsetX; |
|
|
|
el.style.top = offsetY; |
|
|
|
this.componentList.push(el); |
|
|
|
this.history.push(cloneDeep(this.componentList)); |
|
|
|
this.current = this.history.length - 1; |
|
|
|
} catch (error) { |
|
|
|
console.warn(error); |
|
|
|
} |
|
|
|