2021-03-30 16:11:59 +08:00
|
|
|
<template>
|
|
|
|
<div class="home">
|
|
|
|
<Toolbar />
|
|
|
|
|
|
|
|
<main>
|
|
|
|
<!-- 左侧组件列表 -->
|
2021-04-07 09:49:07 +08:00
|
|
|
<!-- <section class="left">-->
|
|
|
|
<!-- <ComponentList />-->
|
|
|
|
<!-- </section>-->
|
2021-03-30 16:11:59 +08:00
|
|
|
<!-- 中间画布 -->
|
|
|
|
<section class="center">
|
|
|
|
<div
|
|
|
|
class="content"
|
|
|
|
@drop="handleDrop"
|
|
|
|
@dragover="handleDragOver"
|
|
|
|
@mousedown="handleMouseDown"
|
|
|
|
@mouseup="deselectCurComponent"
|
|
|
|
>
|
|
|
|
<Editor />
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Editor from '@/components/Editor/index'
|
|
|
|
import ComponentList from '@/components/ComponentList' // 左侧列表组件
|
|
|
|
import AttrList from '@/components/canvas/components/AttrList' // 右侧属性列表
|
|
|
|
import AnimationList from '@/components/canvas/components/AnimationList' // 右侧动画列表
|
|
|
|
import EventList from '@/components/canvas/components/EventList' // 右侧事件列表
|
|
|
|
import componentList from '@/components/canvas/custom-component/component-list' // 左侧列表数据
|
|
|
|
import Toolbar from '@/components/Toolbar'
|
|
|
|
import { deepCopy } from '@/utils/utils'
|
|
|
|
import { mapState } from 'vuex'
|
|
|
|
import generateID from '@/utils/generateID'
|
2021-10-13 14:19:17 +08:00
|
|
|
// import { listenGlobalKeyDown } from '@/utils/shortcutKey'
|
2021-03-30 16:11:59 +08:00
|
|
|
|
|
|
|
export default {
|
2021-06-24 14:31:01 +08:00
|
|
|
// eslint-disable-next-line vue/no-unused-components
|
2021-03-30 16:11:59 +08:00
|
|
|
components: { Editor, ComponentList, AttrList, AnimationList, EventList, Toolbar },
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
activeName: 'attr',
|
|
|
|
reSelectAnimateIndex: undefined
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: mapState([
|
|
|
|
'componentData',
|
|
|
|
'curComponent',
|
|
|
|
'isClickComponent',
|
|
|
|
'canvasStyleData'
|
|
|
|
]),
|
|
|
|
created() {
|
|
|
|
this.restore()
|
|
|
|
// 全局监听按键事件
|
2021-10-12 18:38:33 +08:00
|
|
|
// listenGlobalKeyDown()
|
2021-03-30 16:11:59 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
restore() {
|
|
|
|
// 用保存的数据恢复画布
|
|
|
|
if (localStorage.getItem('canvasData')) {
|
|
|
|
this.$store.commit('setComponentData', this.resetID(JSON.parse(localStorage.getItem('canvasData'))))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (localStorage.getItem('canvasStyle')) {
|
|
|
|
this.$store.commit('setCanvasStyle', JSON.parse(localStorage.getItem('canvasStyle')))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resetID(data) {
|
2021-05-20 16:45:27 +08:00
|
|
|
if (data) {
|
2021-05-05 22:14:23 +08:00
|
|
|
data.forEach(item => {
|
2021-06-24 14:31:01 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2021-05-20 16:45:27 +08:00
|
|
|
item.type !== 'custom' && (item.id = uuid.v1())
|
2021-05-05 22:14:23 +08:00
|
|
|
})
|
|
|
|
}
|
2021-03-30 16:11:59 +08:00
|
|
|
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
|
|
|
|
handleDrop(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
|
|
|
|
let component
|
|
|
|
const id = e.dataTransfer.getData('componentId')
|
|
|
|
componentList.forEach(componentTemp => {
|
2021-06-24 14:31:01 +08:00
|
|
|
if (id === componentTemp.id) {
|
2021-03-30 16:11:59 +08:00
|
|
|
component = deepCopy(componentTemp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// const component = deepCopy(componentList[e.dataTransfer.getData('index')])
|
|
|
|
component.style.top = e.offsetY
|
|
|
|
component.style.left = e.offsetX
|
|
|
|
component.id = generateID()
|
|
|
|
this.$store.commit('addComponent', { component })
|
2021-09-01 14:03:55 +08:00
|
|
|
this.$store.commit('recordSnapshot','handleDrop')
|
2021-03-30 16:11:59 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
handleDragOver(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
e.dataTransfer.dropEffect = 'copy'
|
|
|
|
},
|
|
|
|
|
|
|
|
handleMouseDown() {
|
|
|
|
this.$store.commit('setClickComponentStatus', false)
|
|
|
|
},
|
|
|
|
|
|
|
|
deselectCurComponent(e) {
|
|
|
|
if (!this.isClickComponent) {
|
|
|
|
this.$store.commit('setCurComponent', { component: null, index: null })
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0 左击 1 滚轮 2 右击
|
2021-06-24 14:31:01 +08:00
|
|
|
if (e.button !== 2) {
|
2021-03-30 16:11:59 +08:00
|
|
|
this.$store.commit('hideContextMenu')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.home {
|
|
|
|
height: 100vh;
|
|
|
|
background: #fff;
|
|
|
|
|
|
|
|
main {
|
|
|
|
height: calc(100% - 64px);
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.left {
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 200px;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
padding-top: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.right {
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 262px;
|
|
|
|
right: 0;
|
|
|
|
top: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.center {
|
|
|
|
margin-left: 200px;
|
|
|
|
margin-right: 262px;
|
|
|
|
background: #f5f5f5;
|
|
|
|
height: 100%;
|
|
|
|
overflow: auto;
|
|
|
|
padding: 20px;
|
|
|
|
|
|
|
|
.content {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.placeholder {
|
|
|
|
text-align: center;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|