dataease-dm/frontend/src/views/panel/list/PanelList.vue

542 lines
14 KiB
Vue
Raw Normal View History

2021-03-08 14:31:09 +08:00
<template xmlns:el-col="http://www.w3.org/1999/html">
<el-col>
2021-03-08 18:43:28 +08:00
<!-- panel list -->
<el-col>
2021-03-08 14:31:09 +08:00
<el-row>
<span class="header-title">默认仪表盘</span>
<div class="block">
<el-tree
:default-expanded-keys="expandedArray"
2021-03-08 18:43:28 +08:00
:data="defaultData"
2021-03-08 14:31:09 +08:00
node-key="id"
:expand-on-click-node="true"
@node-click="panelDefaultClick"
>
2021-03-16 18:28:19 +08:00
<span slot-scope="{ data }" class="custom-tree-node">
2021-03-08 14:31:09 +08:00
<span>
<span>
<el-button
icon="el-icon-picture-outline"
type="text"
/>
</span>
<span style="margin-left: 6px">{{ data.name }}</span>
</span>
</span>
</el-tree>
</div>
</el-row>
<el-row>
<span class="header-title">仪表盘列表</span>
</el-row>
<el-col class="custom-tree-container">
<div class="block">
<el-tree
:default-expanded-keys="expandedArray"
:data="tData"
node-key="id"
:expand-on-click-node="true"
@node-click="nodeClick"
>
<span slot-scope="{ node, data }" class="custom-tree-node">
<span>
2021-03-08 18:43:28 +08:00
<span v-if="data.nodeType === 'panel'">
2021-03-08 14:31:09 +08:00
<el-button
2021-03-08 18:43:28 +08:00
icon="el-icon-picture-outline"
2021-03-08 14:31:09 +08:00
type="text"
/>
</span>
<span style="margin-left: 6px">{{ data.name }}</span>
</span>
<span>
2021-03-08 18:43:28 +08:00
<span v-if="data.nodeType ==='folder'" @click.stop>
2021-03-08 14:31:09 +08:00
<el-dropdown trigger="click" size="small" @command="clickAdd">
<span class="el-dropdown-link">
<el-button
icon="el-icon-plus"
type="text"
size="small"
/>
</span>
<el-dropdown-menu slot="dropdown">
2021-03-08 18:43:28 +08:00
<el-dropdown-item icon="el-icon-circle-plus" :command="beforeClickAdd('folder',data,node)">
{{ $t('panel.groupAdd') }}
2021-03-08 14:31:09 +08:00
</el-dropdown-item>
2021-03-08 18:43:28 +08:00
<el-dropdown-item icon="el-icon-folder-add" :command="beforeClickAdd('panel',data,node)">
{{ $t('panel.panelAdd') }}
2021-03-08 14:31:09 +08:00
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</span>
<span style="margin-left: 12px;" @click.stop>
<el-dropdown trigger="click" size="small" @command="clickMore">
<span class="el-dropdown-link">
<el-button
icon="el-icon-more"
type="text"
size="small"
/>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item icon="el-icon-edit-outline" :command="beforeClickMore('rename',data,node)">
2021-03-08 18:43:28 +08:00
{{ $t('panel.rename') }}
2021-03-08 14:31:09 +08:00
</el-dropdown-item>
<el-dropdown-item icon="el-icon-delete" :command="beforeClickMore('delete',data,node)">
2021-03-08 18:43:28 +08:00
{{ $t('panel.delete') }}
2021-03-08 14:31:09 +08:00
</el-dropdown-item>
2021-03-16 18:28:19 +08:00
<el-dropdown-item v-if="data.nodeType==='panel'" icon="el-icon-share" :command="beforeClickMore('share',data,node)">
{{ $t('panel.share') }}
</el-dropdown-item>
2021-03-08 14:31:09 +08:00
</el-dropdown-menu>
</el-dropdown>
</span>
</span>
</span>
</el-tree>
</div>
</el-col>
<el-dialog :title="dialogTitle" :visible="editGroup" :show-close="false" width="30%">
<el-form ref="groupForm" :model="groupForm" :rules="groupFormRules">
<el-form-item :label="$t('commons.name')" prop="name">
2021-03-08 21:10:16 +08:00
<el-input v-model="groupForm.name" />
2021-03-08 14:31:09 +08:00
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
2021-03-08 18:43:28 +08:00
<el-button size="mini" @click="close()">{{ $t('panel.cancel') }}</el-button>
<el-button type="primary" size="mini" @click="saveGroup(groupForm)">{{ $t('panel.confirm') }}
2021-03-08 14:31:09 +08:00
</el-button>
</div>
</el-dialog>
2021-03-16 18:28:19 +08:00
<el-dialog
2021-03-17 11:22:18 +08:00
:title="authTitle"
2021-03-16 18:28:19 +08:00
:visible.sync="authVisible"
2021-03-17 18:50:29 +08:00
custom-class="de-dialog"
2021-03-16 18:28:19 +08:00
>
2021-03-18 16:55:31 +08:00
<grant-auth v-if="authVisible" :resource-id="authResourceId" @close-grant="closeGrant" />
<!-- <span slot="footer" class="dialog-footer">
2021-03-16 18:28:19 +08:00
<el-button @click="authVisible = false"> </el-button>
<el-button type="primary" @click="authVisible = false"> </el-button>
2021-03-18 16:55:31 +08:00
</span> -->
2021-03-16 18:28:19 +08:00
</el-dialog>
2021-03-08 14:31:09 +08:00
</el-col>
</el-col>
</template>
<script>
2021-03-17 11:22:18 +08:00
import GrantAuth from '../GrantAuth'
2021-03-08 21:10:16 +08:00
import { loadTable, getScene, addGroup, delGroup, addTable, delTable, groupTree, defaultTree } from '@/api/panel/panel'
export default {
name: 'PanelList',
2021-03-17 11:22:18 +08:00
components: { GrantAuth },
2021-03-08 21:10:16 +08:00
data() {
return {
2021-03-17 11:22:18 +08:00
authTitle: null,
authResourceId: null,
2021-03-16 18:28:19 +08:00
authVisible: false,
2021-03-08 21:10:16 +08:00
defaultData: [],
dialogTitle: '',
search: '',
editGroup: false,
editTable: false,
tData: [],
tableData: [],
currGroup: {},
expandedArray: [],
groupForm: {
name: null,
pid: null,
level: 0,
nodeType: null,
children: [],
sort: 'node_type desc,name asc'
2021-03-08 14:31:09 +08:00
},
2021-03-08 21:10:16 +08:00
tableForm: {
name: '',
mode: '',
sort: 'node_type asc,create_time desc,name asc'
2021-03-08 14:31:09 +08:00
},
2021-03-08 21:10:16 +08:00
groupFormRules: {
name: [
{ required: true, message: this.$t('commons.input_content'), trigger: 'blur' }
]
2021-03-08 14:31:09 +08:00
},
2021-03-08 21:10:16 +08:00
tableFormRules: {
name: [
{ required: true, message: this.$t('commons.input_content'), trigger: 'blur' }
],
mode: [
{ required: true, message: this.$t('commons.input_content'), trigger: 'blur' }
]
}
}
},
computed: {
},
watch: {
// search(val){
// this.groupForm.name = val;
// this.tree(this.groupForm);
// }
},
mounted() {
this.defaultTree()
this.tree(this.groupForm)
this.refresh()
this.tableTree()
// this.$router.push('/dataset');
},
methods: {
clickAdd(param) {
// console.log(param);
this.add(param.type)
this.groupForm.pid = param.data.id
this.groupForm.level = param.data.level + 1
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
beforeClickAdd(type, data, node) {
return {
'type': type,
'data': data,
'node': node
}
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
clickMore(param) {
console.log(param)
switch (param.type) {
case 'rename':
this.add(param.data.nodeType)
this.groupForm = JSON.parse(JSON.stringify(param.data))
break
case 'move':
break
case 'delete':
this.delete(param.data)
break
case 'editTable':
this.editTable = true
this.tableForm = JSON.parse(JSON.stringify(param.data))
this.tableForm.mode = this.tableForm.mode + ''
break
case 'deleteTable':
this.deleteTable(param.data)
break
2021-03-16 18:28:19 +08:00
case 'share':
this.share(param.data)
break
2021-03-08 21:10:16 +08:00
}
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
beforeClickMore(type, data, node) {
return {
'type': type,
'data': data,
'node': node
}
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
add(nodeType) {
switch (nodeType) {
case 'folder':
this.dialogTitle = this.$t('panel.groupAdd')
break
case 'panel':
this.dialogTitle = this.$t('panel.panelAdd')
break
}
this.groupForm.nodeType = nodeType
this.editGroup = true
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
saveGroup(group) {
// console.log(group);
this.$refs['groupForm'].validate((valid) => {
if (valid) {
addGroup(group).then(res => {
this.close()
2021-03-08 14:31:09 +08:00
this.$message({
2021-03-08 21:10:16 +08:00
message: this.$t('commons.save_success'),
2021-03-08 14:31:09 +08:00
type: 'success',
showClose: true
})
this.tree(this.groupForm)
})
2021-03-08 21:10:16 +08:00
} else {
this.$message({
message: this.$t('commons.input_content'),
type: 'error',
showClose: true
})
return false
}
})
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
saveTable(table) {
// console.log(table)
table.mode = parseInt(table.mode)
this.$refs['tableForm'].validate((valid) => {
if (valid) {
addTable(table).then(response => {
this.closeTable()
2021-03-08 14:31:09 +08:00
this.$message({
2021-03-08 21:10:16 +08:00
message: this.$t('commons.save_success'),
2021-03-08 14:31:09 +08:00
type: 'success',
showClose: true
})
this.tableTree()
// this.$router.push('/dataset/home')
2021-03-08 21:10:16 +08:00
this.$emit('switchComponent', { name: '' })
2021-03-08 14:31:09 +08:00
this.$store.dispatch('dataset/setTable', null)
})
2021-03-08 21:10:16 +08:00
} else {
this.$message({
message: this.$t('commons.input_content'),
type: 'error',
showClose: true
})
return false
2021-03-08 14:31:09 +08:00
}
2021-03-08 21:10:16 +08:00
})
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
delete(data) {
this.$confirm(this.$t('panel.confirm_delete'), this.$t('panel.tips'), {
confirmButtonText: this.$t('panel.confirm'),
cancelButtonText: this.$t('panel.cancel'),
type: 'warning'
}).then(() => {
delGroup(data.id).then(response => {
this.$message({
type: 'success',
message: this.$t('panel.delete_success'),
showClose: true
})
this.tree(this.groupForm)
2021-03-08 18:43:28 +08:00
})
2021-03-08 21:10:16 +08:00
}).catch(() => {
})
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
deleteTable(data) {
this.$confirm(this.$t('panel.confirm_delete'), this.$t('panel.tips'), {
confirmButtonText: this.$t('panel.confirm'),
cancelButtonText: this.$t('panel.cancel'),
type: 'warning'
}).then(() => {
delTable(data.id).then(response => {
this.$message({
type: 'success',
message: this.$t('panel.delete_success'),
showClose: true
2021-03-08 14:31:09 +08:00
})
2021-03-08 21:10:16 +08:00
this.tableTree()
// this.$router.push('/dataset/home')
this.$emit('switchComponent', { name: '' })
this.$store.dispatch('dataset/setTable', null)
})
}).catch(() => {
})
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
close() {
this.editGroup = false
this.groupForm = {
name: null,
pid: null,
level: 0,
nodeType: null,
children: [],
sort: 'node_type desc,name asc'
}
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
closeTable() {
this.editTable = false
this.tableForm = {
name: ''
}
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
tree(group) {
groupTree(group).then(res => {
this.tData = res.data
})
},
defaultTree() {
const requestInfo = {
panelType: 'system'
}
defaultTree(requestInfo).then(res => {
this.defaultData = res.data
})
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
tableTree() {
this.tableData = []
if (this.currGroup.id) {
loadTable({
sort: 'type asc,create_time desc,name asc',
sceneId: this.currGroup.id
}).then(res => {
this.tableData = res.data
})
}
},
nodeClick(data, node) {
if (data.nodeType === 'panel') {
this.currGroup = data
this.$store.dispatch('panel/setPanelInfo', data)
2021-03-08 21:10:16 +08:00
}
if (node.expanded) {
this.expandedArray.push(data.id)
} else {
const index = this.expandedArray.indexOf(data.id)
if (index > -1) {
this.expandedArray.splice(index, 1)
2021-03-08 14:31:09 +08:00
}
2021-03-08 21:10:16 +08:00
}
// console.log(this.expandedArray);
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
back() {
this.sceneMode = false
// const route = this.$store.state.permission.currentRoutes
// console.log(route)
// this.$router.push('/dataset/index')
this.$store.dispatch('dataset/setSceneData', null)
this.$emit('switchComponent', { name: '' })
},
2021-03-08 18:43:28 +08:00
2021-03-08 21:10:16 +08:00
clickAddData(param) {
// console.log(param);
switch (param.type) {
case 'db':
this.addDB()
break
case 'sql':
this.$message(param.type)
break
case 'excel':
this.$message(param.type)
break
case 'custom':
this.$message(param.type)
break
}
},
2021-03-08 18:43:28 +08:00
2021-03-08 21:10:16 +08:00
beforeClickAddData(type) {
return {
'type': type
}
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
addDB() {
// this.$router.push({
// name: 'add_db',
// params: {
// scene: this.currGroup
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
// }
// })
this.$emit('switchComponent', { name: 'AddDB', param: this.currGroup })
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
sceneClick(data, node) {
// console.log(data);
this.$store.dispatch('dataset/setTable', null)
this.$store.dispatch('dataset/setTable', data.id)
// this.$router.push({
// name: 'table',
// params: {
// table: data
// }
// })
this.$emit('switchComponent', { name: 'ViewTable' })
},
2021-03-08 14:31:09 +08:00
2021-03-08 21:10:16 +08:00
refresh() {
const path = this.$route.path
if (path === '/dataset/table') {
this.sceneMode = true
const sceneId = this.$store.state.dataset.sceneData
getScene(sceneId).then(res => {
this.currGroup = res.data
})
}
},
panelDefaultClick(data, node) {
console.log(data)
console.log(node)
this.$store.dispatch('panel/setPanelInfo', data)
2021-03-08 21:10:16 +08:00
// 切换view
this.$emit('switchComponent', { name: 'PanelView' })
2021-03-16 18:28:19 +08:00
},
share(data) {
2021-03-17 11:22:18 +08:00
this.authResourceId = data.id
2021-03-17 18:50:29 +08:00
this.authTitle = '把[' + data.label + ']分享给'
2021-03-16 18:28:19 +08:00
this.authVisible = true
},
2021-03-18 16:55:31 +08:00
closeGrant() {
2021-03-17 18:50:29 +08:00
this.authResourceId = null
2021-03-18 16:55:31 +08:00
this.authVisible = false
2021-03-08 14:31:09 +08:00
}
}
2021-03-08 21:10:16 +08:00
}
2021-03-08 14:31:09 +08:00
</script>
<style scoped>
.header-title {
font-size: 14px;
flex: 1;
color: #606266;
font-weight: bold;
}
.el-divider--horizontal {
margin: 12px 0
}
.search-input {
padding: 12px 0;
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
.custom-position {
flex: 1;
display: flex;
align-items: center;
font-size: 14px;
flex-flow: row nowrap;
}
.form-item {
margin-bottom: 0;
}
.title-css {
height: 26px;
}
.title-text {
line-height: 26px;
}
2021-03-17 11:22:18 +08:00
2021-03-08 14:31:09 +08:00
</style>