2021-03-03 15:06:52 +08:00
|
|
|
<template>
|
|
|
|
<el-col>
|
|
|
|
<el-row>
|
|
|
|
<el-row style="height: 26px;">
|
|
|
|
<span style="line-height: 26px;">
|
|
|
|
{{ $t('dataset.add_db_table') }}
|
|
|
|
</span>
|
|
|
|
<el-row style="float: right">
|
|
|
|
<el-button size="mini" @click="cancel">
|
|
|
|
{{ $t('dataset.cancel') }}
|
|
|
|
</el-button>
|
|
|
|
<el-button size="mini" type="primary" :disabled="checkTableList.length < 1" @click="save">
|
|
|
|
{{ $t('dataset.confirm') }}
|
|
|
|
</el-button>
|
|
|
|
</el-row>
|
|
|
|
</el-row>
|
2021-03-11 14:36:02 +08:00
|
|
|
<el-divider />
|
2021-03-03 15:06:52 +08:00
|
|
|
<el-row>
|
|
|
|
<el-form :inline="true">
|
|
|
|
<el-form-item class="form-item">
|
|
|
|
<el-select v-model="dataSource" filterable :placeholder="$t('dataset.pls_slc_data_source')" size="mini">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:key="item.id"
|
|
|
|
:label="item.name"
|
|
|
|
:value="item.id"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item class="form-item">
|
|
|
|
<el-radio v-model="mode" label="0">{{ $t('dataset.direct_connect') }}</el-radio>
|
|
|
|
<el-radio v-model="mode" label="1">{{ $t('dataset.sync_data') }}</el-radio>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item class="form-item" style="float: right;">
|
|
|
|
<el-input
|
|
|
|
v-model="searchTable"
|
|
|
|
size="mini"
|
|
|
|
:placeholder="$t('dataset.search')"
|
|
|
|
prefix-icon="el-icon-search"
|
|
|
|
clearable
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</el-row>
|
2021-03-15 15:51:34 +08:00
|
|
|
<el-row style="overflow: auto;height: 60vh;">
|
2021-03-03 15:06:52 +08:00
|
|
|
<el-checkbox-group v-model="checkTableList" size="small">
|
|
|
|
<el-checkbox
|
2021-03-12 14:17:26 +08:00
|
|
|
v-for="t in tableData"
|
2021-03-03 15:06:52 +08:00
|
|
|
:key="t"
|
|
|
|
border
|
|
|
|
:label="t"
|
|
|
|
/>
|
|
|
|
</el-checkbox-group>
|
|
|
|
</el-row>
|
|
|
|
</el-row>
|
|
|
|
</el-col>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-03-03 18:35:51 +08:00
|
|
|
import { listDatasource, post } from '@/api/dataset/dataset'
|
|
|
|
|
2021-03-03 15:06:52 +08:00
|
|
|
export default {
|
2021-03-11 14:36:02 +08:00
|
|
|
name: 'AddDB',
|
2021-03-03 18:35:51 +08:00
|
|
|
props: {
|
2021-03-15 18:24:38 +08:00
|
|
|
param: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
}
|
2021-03-03 18:35:51 +08:00
|
|
|
},
|
2021-03-03 15:06:52 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchTable: '',
|
|
|
|
options: [],
|
|
|
|
dataSource: '',
|
|
|
|
tables: [],
|
|
|
|
checkTableList: [],
|
2021-03-12 14:17:26 +08:00
|
|
|
mode: '0',
|
|
|
|
tableData: []
|
2021-03-03 15:06:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
dataSource(val) {
|
|
|
|
if (val) {
|
2021-03-03 18:35:51 +08:00
|
|
|
post('/datasource/getTables', { id: val }).then(response => {
|
2021-03-03 15:06:52 +08:00
|
|
|
this.tables = response.data
|
2021-03-12 14:17:26 +08:00
|
|
|
this.tableData = JSON.parse(JSON.stringify(this.tables))
|
2021-03-03 18:35:51 +08:00
|
|
|
})
|
2021-03-03 15:06:52 +08:00
|
|
|
}
|
2021-03-12 14:17:26 +08:00
|
|
|
},
|
|
|
|
searchTable(val) {
|
|
|
|
if (val && val !== '') {
|
|
|
|
this.tableData = JSON.parse(JSON.stringify(this.tables.filter(ele => { return ele.includes(val) })))
|
|
|
|
} else {
|
|
|
|
this.tableData = JSON.parse(JSON.stringify(this.tables))
|
|
|
|
}
|
2021-03-03 15:06:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.initDataSource()
|
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
this.initDataSource()
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
initDataSource() {
|
2021-03-03 18:35:51 +08:00
|
|
|
listDatasource().then(response => {
|
2021-03-03 15:06:52 +08:00
|
|
|
this.options = response.data
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
|
|
|
// console.log(this.checkTableList);
|
|
|
|
// console.log(this.scene);
|
2021-03-03 18:35:51 +08:00
|
|
|
const sceneId = this.param.id
|
2021-03-03 15:06:52 +08:00
|
|
|
const dataSourceId = this.dataSource
|
|
|
|
const tables = []
|
|
|
|
const mode = this.mode
|
|
|
|
this.checkTableList.forEach(function(name) {
|
|
|
|
tables.push({
|
|
|
|
name: name,
|
|
|
|
sceneId: sceneId,
|
|
|
|
dataSourceId: dataSourceId,
|
|
|
|
type: 'db',
|
|
|
|
mode: parseInt(mode)
|
|
|
|
})
|
|
|
|
})
|
2021-03-03 18:35:51 +08:00
|
|
|
post('/dataset/table/batchAdd', tables).then(response => {
|
|
|
|
this.$store.dispatch('dataset/setSceneData', new Date().getTime())
|
2021-03-03 15:06:52 +08:00
|
|
|
this.cancel()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.dataReset()
|
2021-03-03 18:35:51 +08:00
|
|
|
// this.$router.push('/dataset/home')
|
|
|
|
this.$emit('switchComponent', { name: '' })
|
2021-03-03 15:06:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
dataReset() {
|
|
|
|
this.searchTable = ''
|
|
|
|
this.options = []
|
|
|
|
this.dataSource = ''
|
|
|
|
this.tables = []
|
|
|
|
this.checkTableList = []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.el-divider--horizontal {
|
|
|
|
margin: 12px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.form-item {
|
|
|
|
margin-bottom: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-checkbox {
|
|
|
|
margin-bottom: 14px;
|
|
|
|
margin-left: 0;
|
|
|
|
margin-right: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-checkbox.is-bordered + .el-checkbox.is-bordered {
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
2021-03-15 18:18:11 +08:00
|
|
|
|
|
|
|
span{
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
2021-03-03 15:06:52 +08:00
|
|
|
</style>
|