dataease-dm/frontend/src/views/panel/edit/index.vue

483 lines
14 KiB
Vue
Raw Normal View History

2021-03-22 19:05:35 +08:00
<template>
2021-05-06 23:40:34 +08:00
<el-row>
2021-05-20 00:33:07 +08:00
<el-header class="de-header">
<el-col :span="8" style="text-overflow:ellipsis;overflow: hidden;white-space: nowrap;color: #606266;font-size: 16px">
<span style="line-height: 35px;">
{{ $t('commons.name') }} {{ panelInfo.name || '测试仪表板' }}
</span>
</el-col>
2021-05-06 23:40:34 +08:00
<!--横向工具栏-->
2021-05-20 00:33:07 +08:00
<el-col :span="16">
<Toolbar @showPanel="showPanel" @close-left-panel="closeLeftPanel" @previewFullScreen="previewFullScreen" />
2021-05-20 00:33:07 +08:00
</el-col>
</el-header>
<de-container>
<de-aside-container class="ms-aside-container">
<div style="width: 60px; left: 0px; top: 0px; bottom: 0px; position: absolute">
<div style="width: 60px;height: 100%;overflow: hidden auto;position: relative;margin: 0px auto;">
<!-- 视图图表 -->
<div class="button-div-class" style=" width: 24px;height: 24px;text-align: center;line-height: 1;position: relative;margin: 32px auto 0px;font-size:150%;">
<el-button circle class="el-icon-circle-plus-outline" size="mini" @click="showPanel(0)" />
</div>
<!-- 视图文字 -->
<div style="position: relative; margin: 18px auto 30px">
<div style="max-width: 100%;text-align: center;white-space: nowrap;text-overflow: ellipsis;position: relative;flex-shrink: 0;">
{{ $t('panel.view') }}
2021-03-22 19:05:35 +08:00
</div>
</div>
<!-- 视图分割线 -->
<div style="height: 1px; position: relative; margin: 0px auto;background-color:#E6E6E6;">
<div style="width: 60px;height: 1px;line-height: 1px;text-align: center;white-space: pre;text-overflow: ellipsis;position: relative;flex-shrink: 0;" />
</div>
<!-- 过滤组件 -->
<div tabindex="-1" style="position: relative; margin: 20px auto">
<div style="height: 60px; position: relative">
<div class="button-div-class" style=" text-align: center;line-height: 1;position: absolute;inset: 0px 0px 45px; ">
<el-button circle class="el-icon-s-tools" size="mini" @click="showPanel(1)" />
2021-03-22 19:05:35 +08:00
</div>
<div style=" position: absolute;left: 0px;right: 0px;bottom: 10px; height: 16px;">
<div style=" max-width: 100%;text-align: center;white-space: nowrap;text-overflow: ellipsis;position: relative;flex-shrink: 0;">
{{ $t('panel.module') }}
2021-03-22 19:05:35 +08:00
</div>
</div>
</div>
</div>
</div>
</div>
<!-- <div ref="leftPanel" :class="{show:show}" class="leftPanel-container">-->
<!-- <div />-->
<!-- <div v-if="show" class="leftPanel">-->
<!-- <div style="height:100%;overflow-y: auto">-->
<!-- <view-select v-show=" show && showIndex===0" />-->
<!-- <filter-group v-show=" show &&showIndex===1" />-->
<!-- <subject-setting v-show=" show &&showIndex===2" />-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
</de-aside-container>
<!--画布区域-->
<el-main>
<el-drawer
title="我是标题"
:visible.sync="show"
:with-header="false"
style="position: absolute;"
direction="ltr"
:modal="false"
:size="drawerSize"
:wrapper-closable="false"
:close-on-press-escape="false"
:modal-append-to-body="true"
>
<view-select v-show=" show && showIndex===0" />
<filter-group v-show=" show &&showIndex===1" />
<subject-setting v-show=" show &&showIndex===2" />
</el-drawer>
<div
class="content this_canvas"
@drop="handleDrop"
@dragover="handleDragOver"
@mousedown="handleMouseDown"
@mouseup="deselectCurComponent"
>
<Editor />
</div>
</el-main>
</de-container>
2021-04-01 17:40:12 +08:00
2021-04-06 19:10:16 +08:00
<el-dialog
2021-04-15 10:33:22 +08:00
v-if="filterVisible && panelInfo.id"
2021-05-14 18:51:35 +08:00
:title="$t('panel.module')"
2021-04-06 19:10:16 +08:00
:visible.sync="filterVisible"
custom-class="de-filter-dialog"
>
2021-04-16 17:26:13 +08:00
<filter-dialog v-if="filterVisible && currentWidget" :widget-info="currentWidget" :component-info="currentFilterCom" @re-fresh-component="reFreshComponent">
<component
:is="currentFilterCom.component"
:id="'component' + currentFilterCom.id"
class="component"
:style="currentFilterCom.style"
:element="currentFilterCom"
:in-draw="false"
2021-04-08 11:39:00 +08:00
/>
2021-04-07 18:19:38 +08:00
</filter-dialog>
2021-04-08 11:39:00 +08:00
<div style="text-align: end !important;margin: 0 15px !important;">
<span slot="footer">
2021-05-19 11:59:04 +08:00
<el-button size="mini" @click="cancelFilter">{{ $t('commons.cancel') }}</el-button>
<el-button :disabled="!currentFilterCom.options.attrs.fieldId" type="primary" size="mini" @click="sureFilter">{{ $t('commons.confirm') }}</el-button>
2021-04-08 11:39:00 +08:00
</span>
</div>
2021-04-06 19:10:16 +08:00
</el-dialog>
<el-dialog
v-if="previewVisible"
:visible.sync="previewVisible"
:fullscreen="true"
custom-class="preview-dialog"
>
<PreviewFullScreen />
</el-dialog>
2021-05-06 23:40:34 +08:00
</el-row>
2021-03-22 19:05:35 +08:00
</template>
<script>
import DeMainContainer from '@/components/dataease/DeMainContainer'
import DeContainer from '@/components/dataease/DeContainer'
import DeAsideContainer from '@/components/dataease/DeAsideContainer'
import { addClass, removeClass } from '@/utils'
import FilterGroup from '../filter'
2021-03-23 13:58:49 +08:00
import ViewSelect from '../ViewSelect'
import SubjectSetting from '../SubjectSetting'
2021-03-23 17:16:51 +08:00
import bus from '@/utils/bus'
2021-03-30 15:38:32 +08:00
import Editor from '@/components/canvas/components/Editor/index'
import { deepCopy } from '@/components/canvas/utils/utils'
import componentList from '@/components/canvas/custom-component/component-list' // 左侧列表数据
import { listenGlobalKeyDown } from '@/components/canvas/utils/shortcutKey'
2021-03-25 19:16:32 +08:00
import { mapState } from 'vuex'
import { uuid } from 'vue-uuid'
2021-03-30 15:38:32 +08:00
import Toolbar from '@/components/canvas/components/Toolbar'
2021-03-29 14:57:04 +08:00
import { get } from '@/api/panel/panel'
import PreviewFullScreen from '@/components/canvas/components/Editor/PreviewFullScreen'
2021-03-26 12:26:48 +08:00
// 引入样式
2021-03-30 15:38:32 +08:00
import '@/components/canvas/assets/iconfont/iconfont.css'
import '@/components/canvas/styles/animate.css'
2021-05-18 15:33:39 +08:00
// import '@/components/canvas/styles/reset.css'
2021-04-22 12:16:30 +08:00
2021-03-30 19:01:46 +08:00
import { ApplicationContext } from '@/utils/ApplicationContext'
2021-04-06 19:10:16 +08:00
import FilterDialog from '../filter/filterDialog'
2021-03-22 19:05:35 +08:00
export default {
2021-04-01 17:40:12 +08:00
name: 'PanelEdit',
2021-03-22 19:05:35 +08:00
components: {
DeMainContainer,
DeContainer,
DeAsideContainer,
FilterGroup,
2021-03-23 13:58:49 +08:00
ViewSelect,
2021-03-26 12:26:48 +08:00
Editor,
2021-04-06 19:10:16 +08:00
Toolbar,
FilterDialog,
SubjectSetting,
PreviewFullScreen
2021-03-22 19:05:35 +08:00
},
data() {
return {
drawerSize: '300px',
visible: false,
2021-03-22 19:05:35 +08:00
show: false,
2021-04-01 17:40:12 +08:00
editView: false,
2021-03-23 13:58:49 +08:00
clickNotClose: false,
2021-03-25 19:16:32 +08:00
showIndex: -1,
activeName: 'attr',
2021-04-06 19:10:16 +08:00
reSelectAnimateIndex: undefined,
2021-04-08 11:39:00 +08:00
filterVisible: false,
2021-04-16 17:26:13 +08:00
currentWidget: null,
2021-05-07 19:20:47 +08:00
currentFilterCom: null,
subjectVisible: false,
previewVisible: false
2021-03-22 19:05:35 +08:00
}
},
2021-03-29 14:57:04 +08:00
computed: {
panelInfo() {
return this.$store.state.panel.panelInfo
},
...mapState([
'componentData',
'curComponent',
'isClickComponent',
2021-04-19 10:47:07 +08:00
'canvasStyleData',
'curComponentIndex'
2021-03-29 14:57:04 +08:00
])
},
2021-03-22 19:05:35 +08:00
watch: {
show(value) {
if (value && !this.clickNotClose) {
this.addEventClick()
}
if (value) {
addClass(document.body, 'showRightPanel')
} else {
removeClass(document.body, 'showRightPanel')
}
2021-03-29 14:57:04 +08:00
},
panelInfo(newVal, oldVal) {
this.init(newVal.id)
2021-03-22 19:05:35 +08:00
}
},
2021-03-25 19:16:32 +08:00
created() {
2021-03-29 14:57:04 +08:00
this.init(this.$store.state.panel.panelInfo.id)
// this.restore()
2021-03-25 19:16:32 +08:00
// 全局监听按键事件
listenGlobalKeyDown()
},
2021-03-22 19:05:35 +08:00
mounted() {
// this.insertToBody()
2021-03-25 19:16:32 +08:00
bus.$on('component-on-drag', () => {
this.show = false
})
2021-04-19 10:47:07 +08:00
bus.$on('component-dialog-edit', () => {
this.eidtDialog()
})
bus.$on('previewFullScreenClose', () => {
this.previewVisible = false
})
2021-03-22 19:05:35 +08:00
},
beforeDestroy() {
const elx = this.$refs.rightPanel
2021-03-23 18:17:31 +08:00
elx && elx.remove()
2021-03-22 19:05:35 +08:00
},
methods: {
2021-03-29 14:57:04 +08:00
init(panelId) {
// 如果临时画布有数据 则使用临时画布数据(视图编辑的时候 会保存临时画布数据)
const componentDataTemp = this.$store.state.panel.componentDataTemp
const canvasStyleDataTemp = this.$store.state.panel.canvasStyleDataTemp
if (componentDataTemp && canvasStyleDataTemp) {
this.$store.commit('setComponentData', this.resetID(JSON.parse(componentDataTemp)))
this.$store.commit('setCanvasStyle', JSON.parse(canvasStyleDataTemp))
} else if (panelId) {
2021-03-29 14:57:04 +08:00
get('panel/group/findOne/' + panelId).then(response => {
2021-04-09 18:19:45 +08:00
this.$store.commit('setComponentData', this.resetID(JSON.parse(response.data.panelData)))
2021-05-05 22:14:23 +08:00
const panelStyle = JSON.parse(response.data.panelStyle)
this.$store.commit('setCanvasStyle', panelStyle)
2021-03-29 14:57:04 +08:00
})
}
},
2021-03-22 19:05:35 +08:00
save() {
},
toDir() {
this.$router.replace('/panel/index')
},
showPanel(type) {
debugger
if (this.showIndex === -1 || this.showIndex === type) {
this.$nextTick(() => (this.show = !this.show))
}
2021-03-23 13:58:49 +08:00
this.showIndex = type
2021-03-22 19:05:35 +08:00
},
addEventClick() {
window.addEventListener('click', this.closeSidebar)
},
closeSidebar(evt) {
const parent = evt.target.closest('.button-div-class')
const self = evt.target.closest('.el-drawer__wrapper')
// 点击样式按钮 排除
const stick = evt.target.closest('.el-icon-magic-stick')
if (!parent && !self && !stick) {
debugger
2021-03-22 19:05:35 +08:00
this.show = false
window.removeEventListener('click', this.closeSidebar)
2021-03-23 13:58:49 +08:00
this.showIndex = -1
2021-03-22 19:05:35 +08:00
}
},
// insertToBody() {
// this.$nextTick(() => {
// const elx = this.$refs.leftPanel
// const body = document.querySelector('body')
// body.insertBefore(elx, body.firstChild)
// })
// },
2021-03-25 19:16:32 +08:00
resetID(data) {
2021-05-05 22:14:23 +08:00
if (data) {
data.forEach(item => {
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-25 19:16:32 +08:00
return data
},
handleDrop(e) {
2021-03-26 11:37:32 +08:00
e.preventDefault()
e.stopPropagation()
2021-03-25 19:16:32 +08:00
let component
2021-03-26 11:37:32 +08:00
const newComponentId = uuid.v1()
2021-04-15 10:33:22 +08:00
2021-03-25 19:16:32 +08:00
const componentInfo = JSON.parse(e.dataTransfer.getData('componentInfo'))
2021-03-26 11:37:32 +08:00
// 用户视图设置 复制一个模板
2021-03-25 19:16:32 +08:00
if (componentInfo.type === 'view') {
componentList.forEach(componentTemp => {
if (componentTemp.type === 'view') {
component = deepCopy(componentTemp)
const propValue = {
2021-03-26 11:37:32 +08:00
id: newComponentId,
2021-03-25 19:16:32 +08:00
viewId: componentInfo.id
}
component.propValue = propValue
}
})
2021-03-31 16:35:10 +08:00
} else {
2021-04-08 11:39:00 +08:00
this.currentWidget = ApplicationContext.getService(componentInfo.id)
2021-04-15 10:33:22 +08:00
2021-04-19 10:47:07 +08:00
this.currentFilterCom = this.currentWidget.getDrawPanel()
2021-04-16 17:26:13 +08:00
this.currentFilterCom.style.top = e.offsetY
this.currentFilterCom.style.left = e.offsetX
this.currentFilterCom.id = newComponentId
if (this.currentWidget.filterDialog) {
2021-04-06 19:10:16 +08:00
this.show = false
2021-04-09 11:58:03 +08:00
this.openFilterDiolog()
2021-04-06 19:10:16 +08:00
return
}
2021-04-16 17:26:13 +08:00
component = deepCopy(this.currentFilterCom)
2021-03-25 19:16:32 +08:00
}
2021-03-26 11:37:32 +08:00
component.style.top = e.offsetY
component.style.left = e.offsetX
component.id = newComponentId
2021-03-25 19:16:32 +08:00
this.$store.commit('addComponent', { component })
this.$store.commit('recordSnapshot')
2021-04-16 17:26:13 +08:00
this.clearCurrentInfo()
},
clearCurrentInfo() {
this.currentWidget = null
this.currentFilterCom = null
2021-03-25 19:16:32 +08:00
},
handleDragOver(e) {
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
},
handleMouseDown() {
console.log('handleMouseDown123')
this.$store.commit('setClickComponentStatus', false)
},
deselectCurComponent(e) {
console.log('deselectCurComponent123')
if (!this.isClickComponent) {
this.$store.commit('setCurComponent', { component: null, index: null })
}
// 0 左击 1 滚轮 2 右击
2021-03-26 11:37:32 +08:00
if (e.button !== 2) {
2021-03-25 19:16:32 +08:00
this.$store.commit('hideContextMenu')
}
2021-04-06 19:10:16 +08:00
},
2021-04-09 11:58:03 +08:00
openFilterDiolog() {
2021-04-06 19:10:16 +08:00
this.filterVisible = true
2021-04-08 11:39:00 +08:00
},
cancelFilter() {
this.filterVisible = false
this.currentWidget = null
2021-04-16 17:26:13 +08:00
this.clearCurrentInfo()
2021-04-08 11:39:00 +08:00
},
sureFilter() {
2021-04-16 17:26:13 +08:00
const component = deepCopy(this.currentFilterCom)
2021-04-19 10:47:07 +08:00
// this.$store.commit('addComponent', { component })
this.$store.commit('setComponentWithId', component)
2021-04-08 11:39:00 +08:00
this.$store.commit('recordSnapshot')
this.cancelFilter()
2021-04-08 18:18:08 +08:00
},
reFreshComponent(component) {
2021-04-16 17:26:13 +08:00
this.currentFilterCom = component
this.$forceUpdate()
2021-04-19 10:47:07 +08:00
},
eidtDialog() {
const serviceName = this.curComponent.serviceName
this.currentWidget = ApplicationContext.getService(serviceName)
this.currentFilterCom = this.curComponent
this.openFilterDiolog()
2021-05-07 19:20:47 +08:00
},
closeLeftPanel() {
debugger
2021-05-07 19:20:47 +08:00
this.show = false
2021-05-20 16:45:27 +08:00
// this.beforeDestroy()
},
previewFullScreen() {
this.previewVisible = true
2021-03-22 19:05:35 +08:00
}
2021-03-22 19:05:35 +08:00
}
}
</script>
<style scoped>
.ms-aside-container {
height: calc(100vh - 91px);
2021-05-06 23:40:34 +08:00
min-width: 40px;
2021-03-22 19:05:35 +08:00
max-width: 60px;
border: none;
}
2021-05-18 17:31:28 +08:00
.ms-main-container {
height: calc(100vh - 91px);
}
2021-03-22 19:05:35 +08:00
.de-header {
height: 35px !important;
border-bottom: 1px solid #E6E6E6;
}
.showLeftPanel {
overflow: hidden;
position: relative;
2021-05-06 23:40:34 +08:00
width: 100%;
2021-03-22 19:05:35 +08:00
}
</style>
<style lang="scss" scoped>
.leftPanel-background {
position: fixed;
top: 0;
left: 0;
opacity: 0;
transition: opacity .3s cubic-bezier(.7, .3, .1, 1);
background: rgba(0, 0, 0, .2);
z-index: -1;
}
.leftPanel {
width: 100%;
max-width: 300px;
2021-03-22 19:05:35 +08:00
height: calc(100vh - 91px);
position: fixed;
top: 91px;
left: 60px;
box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
transition: all .25s cubic-bezier(.7, .3, .1, 1);
transform: translate(100%);
background: #fff;
z-index: 1003;
2021-03-22 19:05:35 +08:00
}
.show {
transition: all .3s cubic-bezier(.7, .3, .1, 1);
.leftPanel-background {
z-index: 1002;
2021-03-22 19:05:35 +08:00
opacity: 1;
width: 100%;
height: 100%;
}
.leftPanel {
transform: translate(0);
}
}
.this_canvas{
height: calc(100vh - 91px);
overflow: auto;
}
.el-main{
height: calc(100vh - 91px);
padding: 0!important;
overflow: auto;
position: relative;
}
.el-main >>> .el-drawer__wrapper{
width: 310px!important;
}
2021-03-22 19:05:35 +08:00
</style>