提交 1538ff64 authored 作者: wangjiahao's avatar wangjiahao

feat:增加预览连接功能

上级 ea7efe56
<template> <template>
<div class="bg" v-if="show"> <div v-if="show" class="bg">
<el-button @click="close" class="close">关闭</el-button> <el-button class="close" @click="close">关闭</el-button>
<div class="canvas-container"> <div class="canvas-container">
<div class="canvas" <div
class="canvas"
:style="{ :style="{
width: changeStyleWithScale(canvasStyleData.width) + 'px', width: changeStyleWithScale(canvasStyleData.width) + 'px',
height: changeStyleWithScale(canvasStyleData.height) + 'px', height: changeStyleWithScale(canvasStyleData.height) + 'px',
...@@ -23,22 +24,26 @@ import { getStyle } from '@/components/canvas/utils/style' ...@@ -23,22 +24,26 @@ import { getStyle } from '@/components/canvas/utils/style'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import ComponentWrapper from './ComponentWrapper' import ComponentWrapper from './ComponentWrapper'
import { changeStyleWithScale } from '@/components/canvas/utils/translate' import { changeStyleWithScale } from '@/components/canvas/utils/translate'
import { uuid } from 'vue-uuid'
export default { export default {
components: { ComponentWrapper },
model: { model: {
prop: 'show', prop: 'show',
event: 'change', event: 'change'
}, },
props: { props: {
show: { show: {
type: Boolean, type: Boolean,
default: false, default: false
}
}, },
created() {
this.restore()
}, },
components: { ComponentWrapper },
computed: mapState([ computed: mapState([
'componentData', 'componentData',
'canvasStyleData', 'canvasStyleData'
]), ]),
methods: { methods: {
changeStyleWithScale, changeStyleWithScale,
...@@ -48,41 +53,41 @@ export default { ...@@ -48,41 +53,41 @@ export default {
close() { close() {
this.$emit('change', false) this.$emit('change', false)
}, },
restore() {
debugger
// 用保存的数据恢复画布
if (localStorage.getItem('canvasData')) {
this.componentData = this.resetID(JSON.parse(localStorage.getItem('canvasData')))
}
if (localStorage.getItem('canvasStyle')) {
this.canvasStyleData = JSON.parse(localStorage.getItem('canvasStyle'))
this.$store.commit('setCanvasStyle', JSON.parse(localStorage.getItem('canvasStyle')))
}
}, },
resetID(data) {
data.forEach(item => {
item.id = uuid.v1()
})
return data
}
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.bg { .bg {
width: 100%; width: 100%;
height: 100%; height: 100%;
top: 0;
left: 0;
position: fixed;
background: rgb(0, 0, 0, .5);
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
overflow: auto;
padding: 20px;
.canvas-container { .canvas-container {
width: calc(100% - 40px); width: 100%;
height: calc(100% - 120px); height: 100%;
overflow: auto; overflow: auto;
.canvas { .canvas {
background: #fff;
position: relative; position: relative;
margin: auto; margin: auto;
} }
} }
.close {
position: absolute;
right: 20px;
top: 100px;
} }
}
</style> </style>
<template>
<div class="bg">
<div id="preview-parent" class="canvas-container">
<div
class="canvas"
:style="{
width: changeStyleWithScale(canvasStyleData.width) + 'px',
height: changeStyleWithScale(canvasStyleData.height) + 'px',
}"
>
<ComponentWrapper
v-for="(item, index) in componentData"
:key="index"
:config="item"
/>
</div>
</div>
</div>
</template>
<script>
import { getStyle } from '@/components/canvas/utils/style'
import { mapState } from 'vuex'
import ComponentWrapper from './ComponentWrapper'
import { changeStyleWithScale } from '@/components/canvas/utils/translate'
import { uuid } from 'vue-uuid'
export default {
components: { ComponentWrapper },
model: {
prop: 'show',
event: 'change'
},
props: {
show: {
type: Boolean,
default: false
}
},
computed: mapState([
'componentData',
'canvasStyleData'
]),
mounted() {
// 计算组件当前合适宽度
},
created() {
this.restore()
},
methods: {
changeStyleWithScale,
getStyle,
close() {
this.$emit('change', false)
},
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) {
data.forEach(item => {
item.id = uuid.v1()
})
return data
}
}
}
</script>
<style lang="scss" scoped>
.bg {
width: 100%;
height: 100%;
.canvas-container {
width: 100%;
height: 100%;
overflow: auto;
.canvas {
position: relative;
margin: auto;
}
}
}
</style>
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<el-button class="el-icon-circle-check" size="mini" circle @click="save" /> <el-button class="el-icon-circle-check" size="mini" circle @click="save" />
</el-tooltip> </el-tooltip>
<el-tooltip content="预览"> <el-tooltip content="预览">
<el-button class="el-icon-view" size="mini" circle @click="preview" /> <el-button class="el-icon-view" size="mini" circle @click="clickPreview" />
</el-tooltip> </el-tooltip>
<span style="float: right;margin-left: 10px"> <span style="float: right;margin-left: 10px">
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
</div> </div>
<!-- 预览 --> <!-- 预览 -->
<PreviewEject v-model="isShowPreview" @change="handlePreviewChange" /> <!-- <PreviewEject v-model="isShowPreview" @change="handlePreviewChange" />-->
</div> </div>
</template> </template>
...@@ -216,6 +216,13 @@ export default { ...@@ -216,6 +216,13 @@ export default {
handlePreviewChange() { handlePreviewChange() {
this.$store.commit('setEditMode', 'edit') this.$store.commit('setEditMode', 'edit')
},
clickPreview() {
localStorage.setItem('canvasData', JSON.stringify(this.componentData))
localStorage.setItem('canvasStyle', JSON.stringify(this.canvasStyleData))
const url = '#/preview'
window.open(url, '_blank')
} }
} }
} }
......
...@@ -73,7 +73,7 @@ export const constantRoutes = [ ...@@ -73,7 +73,7 @@ export const constantRoutes = [
}, },
{ {
path: '/preview', path: '/preview',
component: () => import('@/views/panel/preview/index'), component: () => import('@/components/canvas/components/Editor/PreviewFullScreen'),
hidden: true hidden: true
}, },
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</span> </span>
<span style="float: right;line-height: 40px;"> <span style="float: right;line-height: 40px;">
<el-tooltip content="预览"> <el-tooltip content="预览">
<el-button class="el-icon-view" size="mini" circle /> <el-button class="el-icon-view" size="mini" circle @click="clickPreview" />
</el-tooltip> </el-tooltip>
</span> </span>
</el-row> </el-row>
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
</template> </template>
<script> <script>
import Preview from '@/components/canvas/components/Editor/Preview' import Preview from '@/components/canvas/components/Editor/Preview'
import { mapState } from 'vuex'
export default { export default {
name: 'PanelViewShow', name: 'PanelViewShow',
...@@ -36,12 +37,22 @@ export default { ...@@ -36,12 +37,22 @@ export default {
computed: { computed: {
panelInfo() { panelInfo() {
return this.$store.state.panel.panelInfo return this.$store.state.panel.panelInfo
} },
...mapState([
'componentData',
'canvasStyleData'
])
}, },
mounted() { mounted() {
}, },
methods: { methods: {
clickPreview() {
localStorage.setItem('canvasData', JSON.stringify(this.componentData))
localStorage.setItem('canvasStyle', JSON.stringify(this.canvasStyleData))
const url = '#/preview'
window.open(url, '_blank')
}
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论