2021-06-22 11:19:58 +08:00
|
|
|
<template xmlns:el-col="http://www.w3.org/1999/html">
|
2021-07-01 10:47:28 +08:00
|
|
|
<el-col class="tree-style">
|
2021-06-17 18:58:46 +08:00
|
|
|
<el-col>
|
2021-06-22 11:19:58 +08:00
|
|
|
<el-row class="title-css">
|
|
|
|
<span class="title-text">
|
|
|
|
{{ $t('commons.datasource') }}
|
2021-06-17 18:58:46 +08:00
|
|
|
</span>
|
2021-06-23 15:28:06 +08:00
|
|
|
<el-button v-permission="['datasource:add']" icon="el-icon-plus" type="text" size="mini" style="float: right;" @click="addFolder" />
|
2021-06-22 11:19:58 +08:00
|
|
|
|
|
|
|
</el-row>
|
|
|
|
<el-divider />
|
|
|
|
<el-row>
|
|
|
|
<el-form>
|
|
|
|
<el-form-item class="form-item">
|
|
|
|
<el-input
|
|
|
|
v-model="key"
|
|
|
|
size="mini"
|
|
|
|
:placeholder="$t('chart.search')"
|
|
|
|
prefix-icon="el-icon-search"
|
|
|
|
clearable
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
2021-06-17 18:58:46 +08:00
|
|
|
</el-row>
|
2021-06-22 11:19:58 +08:00
|
|
|
|
2021-06-17 18:58:46 +08:00
|
|
|
<el-col class="custom-tree-container">
|
|
|
|
<div class="block">
|
|
|
|
<el-tree
|
2021-06-18 10:59:51 +08:00
|
|
|
ref="myDsTree"
|
2021-06-17 18:58:46 +08:00
|
|
|
:default-expanded-keys="expandedArray"
|
|
|
|
:data="tData"
|
|
|
|
node-key="id"
|
2021-06-18 10:59:51 +08:00
|
|
|
default-expand-all
|
2021-06-17 18:58:46 +08:00
|
|
|
:expand-on-click-node="true"
|
2021-06-18 10:59:51 +08:00
|
|
|
:filter-node-method="filterNode"
|
2021-06-17 18:58:46 +08:00
|
|
|
@node-click="nodeClick"
|
|
|
|
>
|
|
|
|
<span slot-scope="{ node, data }" class="custom-tree-node-list father">
|
2021-06-22 11:19:58 +08:00
|
|
|
<span style="display: flex;flex: 1;width: 0;">
|
2021-08-16 12:46:34 +08:00
|
|
|
<span v-if="data.type !== 'folder' && data.status !== 'Error'">
|
2021-06-21 12:38:04 +08:00
|
|
|
<svg-icon icon-class="datasource" class="ds-icon-scene" />
|
2021-06-17 18:58:46 +08:00
|
|
|
</span>
|
2021-08-16 12:46:34 +08:00
|
|
|
<span v-if="data.status === 'Error'">
|
2021-08-27 17:56:10 +08:00
|
|
|
<svg-icon icon-class="exclamationmark" class="ds-icon-scene" />
|
|
|
|
<el-tooltip v-if="data.status === 'Error'" style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;" effect="dark" :content="$t('datasource.in_valid')" placement="right">
|
|
|
|
<el-button type="text" :style="!!data.msgNode ? {'color': 'red'} : {}"> {{ data.name }} </el-button>
|
|
|
|
</el-tooltip>
|
|
|
|
</span>
|
2021-06-17 18:58:46 +08:00
|
|
|
<span v-if="data.type === 'folder'">
|
|
|
|
<i class="el-icon-folder" />
|
|
|
|
</span>
|
2021-08-16 12:46:34 +08:00
|
|
|
<span v-if=" data.status !== 'Error'" style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
|
|
|
|
{{ data.name }}
|
|
|
|
</span>
|
|
|
|
|
2021-06-17 18:58:46 +08:00
|
|
|
</span>
|
|
|
|
<span class="child">
|
|
|
|
<span v-if="data.type ==='folder'" @click.stop>
|
2021-06-24 11:09:07 +08:00
|
|
|
<span class="el-dropdown-link">
|
2021-06-17 18:58:46 +08:00
|
|
|
<el-button
|
2021-06-23 15:28:06 +08:00
|
|
|
v-permission="['datasource:add']"
|
2021-06-17 18:58:46 +08:00
|
|
|
icon="el-icon-plus"
|
|
|
|
type="text"
|
|
|
|
size="small"
|
|
|
|
@click="addFolderWithType(data)"
|
|
|
|
/>
|
2021-06-24 11:09:07 +08:00
|
|
|
</span>
|
2021-06-17 18:58:46 +08:00
|
|
|
|
|
|
|
</span>
|
|
|
|
<span v-if="data.type !=='folder'" style="margin-left: 12px;" @click.stop>
|
2021-06-23 15:28:06 +08:00
|
|
|
<span v-if="hasDataPermission('manage',data.privileges)" class="el-dropdown-link">
|
2021-06-22 11:54:53 +08:00
|
|
|
<el-button
|
|
|
|
icon="el-icon-delete"
|
|
|
|
type="text"
|
|
|
|
size="small"
|
|
|
|
@click="_handleDelete(data)"
|
|
|
|
/>
|
|
|
|
</span>
|
2021-06-17 18:58:46 +08:00
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</el-tree>
|
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
</el-col>
|
|
|
|
</el-col>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { listDatasource, delDs } from '@/api/system/datasource'
|
2021-06-23 15:28:06 +08:00
|
|
|
|
2021-06-17 18:58:46 +08:00
|
|
|
export default {
|
|
|
|
name: 'DsTree',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
expandedArray: [],
|
2021-06-18 10:59:51 +08:00
|
|
|
tData: [],
|
|
|
|
showSearchInput: false,
|
|
|
|
key: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
key(val) {
|
|
|
|
this.$refs.myDsTree.filter(val)
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.queryTreeDatas()
|
2021-07-05 18:18:06 +08:00
|
|
|
// console.log('permis:' + JSON.stringify(this.$store.getters.permissions))
|
2021-06-17 18:58:46 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2021-06-18 10:59:51 +08:00
|
|
|
filterNode(value, data) {
|
|
|
|
if (!value) return true
|
|
|
|
return data.name.indexOf(value) !== -1
|
|
|
|
},
|
|
|
|
showSearchWidget() {
|
|
|
|
this.showSearchInput = true
|
|
|
|
},
|
|
|
|
closeSearchWidget() {
|
|
|
|
this.key = ''
|
|
|
|
this.showSearchInput = false
|
|
|
|
},
|
2021-06-17 18:58:46 +08:00
|
|
|
queryTreeDatas() {
|
|
|
|
listDatasource().then(res => {
|
|
|
|
this.tData = this.buildTree(res.data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
buildTree(array) {
|
|
|
|
const types = {}
|
|
|
|
const newArr = []
|
|
|
|
for (let index = 0; index < array.length; index++) {
|
|
|
|
const element = array[index]
|
2021-08-27 17:56:10 +08:00
|
|
|
if (this.msgNodeId) {
|
|
|
|
if (element.id === this.msgNodeId) {
|
|
|
|
element.msgNode = true
|
|
|
|
}
|
|
|
|
}
|
2021-06-17 18:58:46 +08:00
|
|
|
if (!(element.type in types)) {
|
|
|
|
types[element.type] = []
|
|
|
|
// newArr.push(...element, ...{ children: types[element.type] })
|
2021-06-23 18:59:14 +08:00
|
|
|
newArr.push({ id: element.type, name: this.transTypeToName(element.type), type: 'folder', children: types[element.type] })
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
|
|
|
types[element.type].push(element)
|
|
|
|
// newArr.children.push({ id: element.id, label: element.name })
|
|
|
|
}
|
|
|
|
return newArr
|
|
|
|
},
|
|
|
|
|
2021-06-23 18:59:14 +08:00
|
|
|
transTypeToName(type) {
|
|
|
|
if (type === 'mysql') {
|
|
|
|
return 'MySQL'
|
|
|
|
} else if (type === 'sqlServer') {
|
|
|
|
return 'SQL Server'
|
2021-07-05 18:18:06 +08:00
|
|
|
} else if (type === 'oracle') {
|
2021-07-01 15:08:57 +08:00
|
|
|
return 'Oracle'
|
2021-08-27 17:56:10 +08:00
|
|
|
} else if (type === 'pg') {
|
2021-08-10 19:11:14 +08:00
|
|
|
return 'PostgreSQL'
|
2021-06-23 18:59:14 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-06-17 18:58:46 +08:00
|
|
|
addFolder() {
|
|
|
|
this.switchMain('DsForm')
|
|
|
|
},
|
|
|
|
addFolderWithType(data) {
|
|
|
|
this.switchMain('DsForm', { type: data.id })
|
|
|
|
},
|
|
|
|
nodeClick(node, data) {
|
|
|
|
if (node.type === 'folder') return
|
|
|
|
this.showInfo(data)
|
|
|
|
},
|
|
|
|
|
|
|
|
clickFileMore(param) {
|
|
|
|
const { optType, data } = param
|
|
|
|
switch (optType) {
|
|
|
|
case 'edit':
|
|
|
|
this.edit(data)
|
|
|
|
break
|
|
|
|
case 'delete':
|
|
|
|
this._handleDelete(data)
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeClickFile(optType, data, node) {
|
|
|
|
return { optType, data, node }
|
|
|
|
},
|
|
|
|
edit(row) {
|
|
|
|
this.switchMain('DsForm', row)
|
|
|
|
},
|
|
|
|
showInfo(row) {
|
|
|
|
const param = { ...row.data, ...{ showModel: 'show' }}
|
|
|
|
this.switchMain('DsForm', param)
|
|
|
|
},
|
|
|
|
_handleDelete(datasource) {
|
|
|
|
this.$confirm(this.$t('datasource.delete_warning'), '', {
|
|
|
|
confirmButtonText: this.$t('commons.confirm'),
|
|
|
|
cancelButtonText: this.$t('commons.cancel'),
|
|
|
|
type: 'warning'
|
|
|
|
}).then(() => {
|
|
|
|
delDs(datasource.id).then(res => {
|
|
|
|
this.$success(this.$t('commons.delete_success'))
|
2021-06-17 19:34:46 +08:00
|
|
|
this.queryTreeDatas()
|
2021-06-17 18:58:46 +08:00
|
|
|
})
|
|
|
|
}).catch(() => {
|
|
|
|
this.$message({
|
|
|
|
type: 'info',
|
|
|
|
message: this.$t('commons.delete_cancelled')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
switchMain(component, componentParam) {
|
|
|
|
this.$emit('switch-main', {
|
|
|
|
component,
|
|
|
|
componentParam
|
|
|
|
})
|
2021-08-27 17:56:10 +08:00
|
|
|
},
|
|
|
|
markInvalid(msgParam) {
|
|
|
|
const param = JSON.parse(msgParam)
|
|
|
|
const msgNodeId = param.id
|
|
|
|
this.msgNodeId = msgNodeId
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.tData.forEach(folder => {
|
|
|
|
const nodes = folder.children
|
|
|
|
nodes.forEach(node => {
|
|
|
|
if (node.id === msgNodeId) {
|
|
|
|
node.msgNode = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
2021-06-22 11:19:58 +08:00
|
|
|
.el-divider--horizontal {
|
|
|
|
margin: 12px 0
|
|
|
|
}
|
|
|
|
|
|
|
|
.search-input {
|
|
|
|
padding: 12px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.custom-tree-container{
|
|
|
|
margin-top: 10px;
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.custom-tree-node {
|
|
|
|
flex: 1;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
font-size: 14px;
|
|
|
|
padding-right:8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.custom-tree-node-list {
|
|
|
|
flex: 1;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
font-size: 14px;
|
|
|
|
padding:0 8px;
|
|
|
|
}
|
|
|
|
|
2021-06-22 11:19:58 +08:00
|
|
|
.tree-list>>>.el-tree-node__expand-icon.is-leaf{
|
|
|
|
display: none;
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
2021-06-22 11:19:58 +08:00
|
|
|
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
.dialog-css >>> .el-dialog__header {
|
|
|
|
padding: 20px 20px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.dialog-css >>> .el-dialog__body {
|
2021-06-17 18:58:46 +08:00
|
|
|
padding: 10px 20px 20px;
|
|
|
|
}
|
|
|
|
|
2021-06-22 11:19:58 +08:00
|
|
|
.form-item>>>.el-form-item__label{
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.scene-title{
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
.scene-title-name{
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
display: inline-block;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
2021-06-17 18:58:46 +08:00
|
|
|
.father .child {
|
2021-08-04 11:57:39 +08:00
|
|
|
/*display: none;*/
|
|
|
|
visibility: hidden;
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
|
|
|
.father:hover .child {
|
2021-08-04 11:57:39 +08:00
|
|
|
/*display: inline;*/
|
|
|
|
visibility: visible;
|
2021-06-17 18:58:46 +08:00
|
|
|
}
|
2021-07-01 10:47:28 +08:00
|
|
|
.tree-style {
|
|
|
|
padding: 10px 15px;
|
|
|
|
height: 100%;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
2021-08-27 17:56:10 +08:00
|
|
|
.msg-node-class {
|
|
|
|
color: red;
|
|
|
|
>>> i{
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
}
|
2021-06-17 18:58:46 +08:00
|
|
|
</style>
|