提交 fcb579d4 authored 作者: wangjiahao's avatar wangjiahao

feat:增加背景图片

上级 2ce81bba
差异被折叠。
<template> <template>
<div class="mark-line"> <div class="mark-line">
<div <div
v-for="line in lines" v-for="line in lines"
:key="line" :key="line"
class="line" class="line"
...@@ -145,7 +145,7 @@ export default { ...@@ -145,7 +145,7 @@ export default {
}, },
], ],
} }
const needToShow = [] const needToShow = []
const { rotate } = this.curComponent.style const { rotate } = this.curComponent.style
Object.keys(conditions).forEach(key => { Object.keys(conditions).forEach(key => {
...@@ -153,9 +153,9 @@ export default { ...@@ -153,9 +153,9 @@ export default {
conditions[key].forEach((condition) => { conditions[key].forEach((condition) => {
if (!condition.isNearly) return if (!condition.isNearly) return
// 修改当前组件位移 // 修改当前组件位移
this.$store.commit('setShapeSingleStyle', { this.$store.commit('setShapeSingleStyle', {
key, key,
value: rotate != 0? this.translatecurComponentShift(key, condition, curComponentStyle) : condition.dragShift, value: rotate !== 0? this.translatecurComponentShift(key, condition, curComponentStyle) : condition.dragShift,
}) })
condition.lineNode.style[key] = `${condition.lineShift}px` condition.lineNode.style[key] = `${condition.lineShift}px`
...@@ -165,7 +165,7 @@ export default { ...@@ -165,7 +165,7 @@ export default {
// 同一方向上同时显示三条线可能不太美观,因此才有了这个解决方案 // 同一方向上同时显示三条线可能不太美观,因此才有了这个解决方案
// 同一方向上的线只显示一条,例如多条横条只显示一条横线 // 同一方向上的线只显示一条,例如多条横条只显示一条横线
if (needToShow.length) { if (needToShow.length) {
this.chooseTheTureLine(needToShow, isDownward, isRightward) this.chooseTheTureLine(needToShow, isDownward, isRightward)
} }
}) })
...@@ -173,7 +173,7 @@ export default { ...@@ -173,7 +173,7 @@ export default {
translatecurComponentShift(key, condition, curComponentStyle) { translatecurComponentShift(key, condition, curComponentStyle) {
const { width, height } = this.curComponent.style const { width, height } = this.curComponent.style
if (key == 'top') { if (key === 'top') {
return Math.round(condition.dragShift - (height - curComponentStyle.height) / 2) return Math.round(condition.dragShift - (height - curComponentStyle.height) / 2)
} }
...@@ -246,4 +246,4 @@ export default { ...@@ -246,4 +246,4 @@ export default {
width: 1px; width: 1px;
height: 100%; height: 100%;
} }
</style> </style>
\ No newline at end of file
...@@ -199,7 +199,7 @@ export default { ...@@ -199,7 +199,7 @@ export default {
handleMouseDownOnShape(e) { handleMouseDownOnShape(e) {
this.$store.commit('setClickComponentStatus', true) this.$store.commit('setClickComponentStatus', true)
if (this.element.component != 'v-text' && this.element.component != 'rect-shape') { if (this.element.component !== 'v-text' && this.element.component !== 'rect-shape') {
e.preventDefault() e.preventDefault()
} }
...@@ -329,7 +329,7 @@ export default { ...@@ -329,7 +329,7 @@ export default {
}, },
isNeedLockProportion() { isNeedLockProportion() {
if (this.element.component != 'Group') return false if (this.element.component !== 'Group') return false
const ratates = [0, 90, 180, 360] const ratates = [0, 90, 180, 360]
for (const component of this.element.propValue) { for (const component of this.element.propValue) {
if (!ratates.includes(mod360(parseInt(component.style.rotate)))) { if (!ratates.includes(mod360(parseInt(component.style.rotate)))) {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
> >
<component <component
:is="item.component" :is="item.component"
v-if="item.component != 'v-text'" v-if="item.component !== 'v-text'"
:id="'component' + item.id" :id="'component' + item.id"
class="component" class="component"
:style="getComponentStyle(item.style)" :style="getComponentStyle(item.style)"
...@@ -106,7 +106,7 @@ export default { ...@@ -106,7 +106,7 @@ export default {
handleMouseDown(e) { handleMouseDown(e) {
// 如果没有选中组件 在画布上点击时需要调用 e.preventDefault() 防止触发 drop 事件 // 如果没有选中组件 在画布上点击时需要调用 e.preventDefault() 防止触发 drop 事件
if (!this.curComponent || (this.curComponent.component != 'v-text' && this.curComponent.component != 'rect-shape')) { if (!this.curComponent || (this.curComponent.component !== 'v-text' && this.curComponent.component !== 'rect-shape')) {
e.preventDefault() e.preventDefault()
} }
...@@ -141,7 +141,7 @@ export default { ...@@ -141,7 +141,7 @@ export default {
document.removeEventListener('mousemove', move) document.removeEventListener('mousemove', move)
document.removeEventListener('mouseup', up) document.removeEventListener('mouseup', up)
if (e.clientX == startX && e.clientY == startY) { if (e.clientX === startX && e.clientY === startY) {
this.hideArea() this.hideArea()
return return
} }
...@@ -173,7 +173,7 @@ export default { ...@@ -173,7 +173,7 @@ export default {
let right = -Infinity; let bottom = -Infinity let right = -Infinity; let bottom = -Infinity
areaData.forEach(component => { areaData.forEach(component => {
let style = {} let style = {}
if (component.component == 'Group') { if (component.component === 'Group') {
component.propValue.forEach(item => { component.propValue.forEach(item => {
const rectInfo = $(`#component${item.id}`).getBoundingClientRect() const rectInfo = $(`#component${item.id}`).getBoundingClientRect()
style.left = rectInfo.left - this.editorX style.left = rectInfo.left - this.editorX
...@@ -255,7 +255,7 @@ export default { ...@@ -255,7 +255,7 @@ export default {
getShapeStyle(style) { getShapeStyle(style) {
const result = {}; const result = {};
['width', 'height', 'top', 'left', 'rotate'].forEach(attr => { ['width', 'height', 'top', 'left', 'rotate'].forEach(attr => {
if (attr != 'rotate') { if (attr !== 'rotate') {
result[attr] = style[attr] + 'px' result[attr] = style[attr] + 'px'
} else { } else {
result.transform = 'rotate(' + style[attr] + 'deg)' result.transform = 'rotate(' + style[attr] + 'deg)'
......
...@@ -14,10 +14,12 @@ export const commonAttr = { ...@@ -14,10 +14,12 @@ export const commonAttr = {
// 编辑器左侧组件列表 // 编辑器左侧组件列表
const list = [ const list = [
{ {
id: '10001',
component: 'v-text', component: 'v-text',
label: '文字', label: '文字',
propValue: '双击编辑文字', propValue: '双击编辑文字',
icon: 'wenben', icon: 'wenben',
type: 'other',
style: { style: {
width: 200, width: 200,
height: 22, height: 22,
...@@ -30,10 +32,12 @@ const list = [ ...@@ -30,10 +32,12 @@ const list = [
} }
}, },
{ {
id: '10002',
component: 'v-button', component: 'v-button',
label: '按钮', label: '按钮',
propValue: '按钮', propValue: '按钮',
icon: 'button', icon: 'button',
type: 'other',
style: { style: {
width: 100, width: 100,
height: 34, height: 34,
...@@ -50,9 +54,11 @@ const list = [ ...@@ -50,9 +54,11 @@ const list = [
} }
}, },
{ {
id: '10003',
component: 'Picture', component: 'Picture',
label: '图片', label: '图片',
icon: 'tupian', icon: 'tupian',
type: 'other',
propValue: require('@/assets/title.jpg'), propValue: require('@/assets/title.jpg'),
style: { style: {
width: 300, width: 300,
...@@ -61,10 +67,25 @@ const list = [ ...@@ -61,10 +67,25 @@ const list = [
} }
}, },
{ {
id: '10003-1',
component: 'Picture',
label: '背景-科技1',
icon: 'tupian',
type: 'other',
propValue: require('@/assets/bg-kj-1.jpg'),
style: {
width: 600,
height: 300,
borderRadius: ''
}
},
{
id: '10004',
component: 'rect-shape', component: 'rect-shape',
label: '矩形', label: '矩形',
propValue: '&nbsp;', propValue: '&nbsp;',
icon: 'juxing', icon: 'juxing',
type: 'other',
style: { style: {
width: 200, width: 200,
height: 200, height: 200,
...@@ -82,6 +103,7 @@ const list = [ ...@@ -82,6 +103,7 @@ const list = [
} }
}, },
{ {
id: '10005',
component: 'user-view', component: 'user-view',
label: '用户视图', label: '用户视图',
propValue: '', propValue: '',
......
...@@ -122,7 +122,7 @@ export default { ...@@ -122,7 +122,7 @@ export default {
} }
// 0 左击 1 滚轮 2 右击 // 0 左击 1 滚轮 2 右击
if (e.button != 2) { if (e.button !== 2) {
this.$store.commit('hideContextMenu') this.$store.commit('hideContextMenu')
} }
} }
......
...@@ -110,12 +110,10 @@ import bus from '@/utils/bus' ...@@ -110,12 +110,10 @@ import bus from '@/utils/bus'
import Editor from '@/components/Editor/index' import Editor from '@/components/Editor/index'
import { deepCopy } from '@/utils/utils' import { deepCopy } from '@/utils/utils'
import componentList from '@/custom-component/component-list' // 左侧列表数据 import componentList from '@/custom-component/component-list' // 左侧列表数据
import generateID from '@/utils/generateID'
import { listenGlobalKeyDown } from '@/utils/shortcutKey' import { listenGlobalKeyDown } from '@/utils/shortcutKey'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { uuid } from 'vue-uuid' import { uuid } from 'vue-uuid'
export default { export default {
components: { components: {
DeMainContainer, DeMainContainer,
...@@ -225,24 +223,38 @@ export default { ...@@ -225,24 +223,38 @@ export default {
return data return data
}, },
handleDrop(e) { handleDrop(e) {
e.preventDefault()
e.stopPropagation()
let component let component
const newComponentId = uuid.v1()
console.log('handleDrop123') console.log('handleDrop123')
const componentInfo = JSON.parse(e.dataTransfer.getData('componentInfo')) const componentInfo = JSON.parse(e.dataTransfer.getData('componentInfo'))
// 用户视图设置 复制一个模板
if (componentInfo.type === 'view') { if (componentInfo.type === 'view') {
componentList.forEach(componentTemp => { componentList.forEach(componentTemp => {
if (componentTemp.type === 'view') { if (componentTemp.type === 'view') {
component = deepCopy(componentTemp) component = deepCopy(componentTemp)
component.style.top = e.offsetY
component.style.left = e.offsetX
component.id = uuid.v1()
const propValue = { const propValue = {
id: component.id, id: newComponentId,
viewId: componentInfo.id viewId: componentInfo.id
} }
component.propValue = propValue component.propValue = propValue
} }
}) })
} }
debugger
// 其他组件设置
componentList.forEach(componentTemp => {
if (componentInfo.id === componentTemp.id) {
component = deepCopy(componentTemp)
}
})
component.style.top = e.offsetY
component.style.left = e.offsetX
component.id = newComponentId
this.$store.commit('addComponent', { component }) this.$store.commit('addComponent', { component })
this.$store.commit('recordSnapshot') this.$store.commit('recordSnapshot')
}, },
...@@ -267,7 +279,7 @@ export default { ...@@ -267,7 +279,7 @@ export default {
} }
// 0 左击 1 滚轮 2 右击 // 0 左击 1 滚轮 2 右击
if (e.button != 2) { if (e.button !== 2) {
this.$store.commit('hideContextMenu') this.$store.commit('hideContextMenu')
} }
} }
......
...@@ -5,11 +5,16 @@ ...@@ -5,11 +5,16 @@
<div slot="header"> <div slot="header">
<span>卡片名称</span> <span>卡片名称</span>
</div> </div>
<div style="position: relative;margin-left: 5px;"> <div style="position: relative;margin-left: 5px;" @dragstart="handleDragStart">
<div v-for="o in 4" :key="o" class="item"> <div
<div draggable> v-for="(item, index) in componentList"
<el-button style="width: 90px;" size="mini" type="primary" icon="el-icon-edit" plain> {{ '条件 ' + o }}</el-button> :key="index"
</div> :data-id="item.id"
draggable
:data-index="index"
>
<span class="iconfont" :class="'icon-' + item.icon" />
<span>{{ item.label }}</span>
</div> </div>
</div> </div>
...@@ -18,16 +23,23 @@ ...@@ -18,16 +23,23 @@
</template> </template>
<script> <script>import componentList from '@/custom-component/component-list'
export default { export default {
name: 'FilterGroup', name: 'FilterGroup',
data() { data() {
return { return {
componentList
} }
}, },
methods: { methods: {
handleDragStart(ev) {
ev.dataTransfer.effectAllowed = 'copy'
const dataTrans = {
type: 'other',
id: ev.target.dataset.id
}
ev.dataTransfer.setData('componentInfo', JSON.stringify(dataTrans))
}
} }
} }
</script> </script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论