dataease/frontend/src/views/panel/ViewSelect/index.vue

205 lines
5.5 KiB
Vue
Raw Normal View History

2021-03-23 13:58:49 +08:00
<template>
2021-06-04 12:22:34 +08:00
<el-col v-loading="loading">
<el-row style="margin-top: 5px">
<el-row style="margin-left: 5px;margin-right: 5px">
2021-09-22 17:52:53 +08:00
<el-col :span="selectModel ? 23 : 16">
<el-input
v-model="templateFilterText"
:placeholder="$t('panel.filter_keywords')"
size="mini"
clearable
prefix-icon="el-icon-search"
/>
</el-col>
2021-09-22 17:52:53 +08:00
<el-col v-if="!selectModel" :span="7">
<el-button type="primary" size="mini" style="float: right" @click="newChart">新建 </el-button>
</el-col>
</el-row>
<el-row style="margin-top: 5px">
<el-tree
ref="templateTree"
:default-expanded-keys="defaultExpandedKeys"
2021-09-22 17:52:53 +08:00
:show-checkbox="selectModel"
:data="data"
node-key="id"
:props="defaultProps"
draggable
:allow-drop="allowDrop"
:allow-drag="allowDrag"
:expand-on-click-node="true"
:filter-node-method="filterNode"
:highlight-current="true"
@node-drag-start="handleDragStart"
@node-click="nodeClick"
2021-09-22 17:52:53 +08:00
@check="checkChanged"
@node-drag-end="dragEnd"
>
<span slot-scope="{ node, data }" class="custom-tree-node">
<span>
<span v-if="data.type==='scene'||data.type==='group'">
<el-button
icon="el-icon-folder"
type="text"
/>
</span>
<span v-else>
<svg-icon :icon-class="data.type" style="width: 14px;height: 14px" />
</span>
<span style="margin-left: 6px;font-size: 14px">{{ data.name }}</span>
</span>
</span>
</el-tree>
</el-row>
2021-06-04 12:22:34 +08:00
<!-- <el-row v-if="detailItem&&detailItem.snapshot" class="detail-class">-->
<!-- <el-card class="filter-card-class">-->
<!-- <div slot="header" class="button-div-class">-->
<!-- <span>{{ detailItem.name }}</span>-->
<!-- </div>-->
<!-- <img draggable="false" class="view-list-thumbnails" :src="detailItem.snapshot" alt="">-->
<!-- </el-card>-->
<!-- </el-row>-->
</el-row>
</el-col>
2021-03-23 13:58:49 +08:00
</template>
<script>
import { tree, findOne } from '@/api/panel/view'
import componentList from '@/components/canvas/custom-component/component-list'
import { deepCopy } from '@/components/canvas/utils/utils'
2021-03-23 13:58:49 +08:00
export default {
name: 'ViewSelect',
2021-09-22 17:52:53 +08:00
props: {
selectModel: {
type: Boolean,
default: false
}
},
2021-03-23 13:58:49 +08:00
data() {
return {
templateFilterText: '',
defaultExpandedKeys: [],
2021-03-23 13:58:49 +08:00
defaultProps: {
children: 'children',
2021-09-26 17:55:31 +08:00
label: 'name',
disabled: 'disabled'
2021-03-23 13:58:49 +08:00
},
data: [],
showdetail: false,
2021-06-04 12:22:34 +08:00
detailItem: null,
loading: false
2021-03-23 13:58:49 +08:00
}
},
watch: {
templateFilterText(val) {
this.$refs.templateTree.filter(val)
2021-03-23 13:58:49 +08:00
}
},
created() {
this.loadData()
},
methods: {
filterNode(value, data) {
if (!value) return true
return data.name.indexOf(value) !== -1
},
nodeClick(data, node) {
findOne(data.id).then(res => {
this.detailItem = res.data
})
},
2021-03-23 13:58:49 +08:00
loadData() {
const param = {}
2021-06-04 12:22:34 +08:00
this.loading = true
2021-03-23 13:58:49 +08:00
tree(param).then(res => {
2021-09-26 17:55:31 +08:00
const nodeDatas = res.data
if (this.selectModel) {
this.setParentDisable(nodeDatas)
}
this.data = nodeDatas
2021-06-04 12:22:34 +08:00
this.loading = false
2021-03-23 13:58:49 +08:00
})
},
2021-03-25 19:16:32 +08:00
handleDragStart(node, ev) {
this.$store.commit('setDragComponentInfo', this.viewComponentInfo())
2021-03-25 19:16:32 +08:00
ev.dataTransfer.effectAllowed = 'copy'
const dataTrans = {
type: 'view',
id: node.data.id
}
ev.dataTransfer.setData('componentInfo', JSON.stringify(dataTrans))
},
dragEnd() {
console.log('dragEnd')
this.$store.commit('clearDragComponentInfo')
},
2021-03-25 19:16:32 +08:00
// 判断节点能否被拖拽
allowDrag(draggingNode) {
if (draggingNode.data.type === 'scene' || draggingNode.data.type === 'group') {
2021-03-25 19:16:32 +08:00
return false
} else {
return true
}
},
allowDrop(draggingNode, dropNode, type) {
return false
},
newChart() {
this.$emit('newChart')
2021-09-22 17:52:53 +08:00
},
2021-09-22 17:52:53 +08:00
checkChanged(node, status) {
this.$refs.templateTree.setCheckedNodes([])
if (status.checkedKeys && status.checkedKeys.length > 0) {
this.$refs.templateTree.setCheckedNodes([node])
}
},
getCurrentSelected() {
const nodes = this.$refs.templateTree.getCheckedNodes(true, false)
return nodes
},
2021-09-26 17:55:31 +08:00
setParentDisable(nodes) {
nodes.forEach(node => {
if (node.type === 'group') {
node.disabled = true
}
if (node.children && node.children.length > 0) {
this.setParentDisable(node.children)
}
})
},
viewComponentInfo() {
let component
// 用户视图设置 复制一个模板
componentList.forEach(componentTemp => {
if (componentTemp.type === 'view') {
component = deepCopy(componentTemp)
}
})
return component
2021-03-23 13:58:49 +08:00
}
2021-03-25 19:16:32 +08:00
2021-03-23 13:58:49 +08:00
}
}
</script>
<style lang="scss" scoped>
2021-03-25 19:16:32 +08:00
.top-div-class {
2021-03-23 13:58:49 +08:00
max-height: calc(100vh - 335px);
width: 100%;
position: fixed;
overflow-y : auto
2021-03-25 19:16:32 +08:00
}
.detail-class {
width: 300px;
2021-03-23 13:58:49 +08:00
position: fixed;
bottom: 0px;
2021-03-25 19:16:32 +08:00
}
.view-list-thumbnails {
2021-03-23 13:58:49 +08:00
width: 100%;
height: 100%;
2021-03-25 19:16:32 +08:00
}
2021-03-23 13:58:49 +08:00
</style>