2021-03-03 15:06:52 +08:00
|
|
|
<template>
|
2021-04-28 18:39:01 +08:00
|
|
|
<el-row style="display: flex;flex-direction: column;height: 100%">
|
|
|
|
<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>
|
2021-03-03 15:06:52 +08:00
|
|
|
</el-row>
|
2021-04-28 18:39:01 +08:00
|
|
|
</el-row>
|
|
|
|
<el-divider />
|
|
|
|
<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"
|
2021-03-03 15:06:52 +08:00
|
|
|
/>
|
2021-04-28 18:39:01 +08:00
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item class="form-item">
|
|
|
|
<el-select v-model="mode" filterable :placeholder="$t('dataset.connect_mode')" size="mini">
|
2021-05-12 12:25:49 +08:00
|
|
|
<el-option :label="$t('dataset.direct_connect')" value="0" />
|
|
|
|
<el-option :label="$t('dataset.sync_data')" value="1" :disabled="!kettleRunning" />
|
2021-04-28 18:39:01 +08:00
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2021-07-08 15:05:25 +08:00
|
|
|
|
|
|
|
<el-form-item class="form-item" v-if="mode === '1'">
|
|
|
|
<el-select v-model="syncType" filterable :placeholder="$t('dataset.connect_mode')" size="mini">
|
|
|
|
<el-option :label="$t('dataset.sync_now')" value="sync_now" />
|
|
|
|
<el-option :label="$t('dataset.sync_latter')" value="sync_latter" />
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
|
2021-04-28 18:39:01 +08:00
|
|
|
<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
|
2021-03-03 15:06:52 +08:00
|
|
|
/>
|
2021-04-28 18:39:01 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
2021-03-03 15:06:52 +08:00
|
|
|
</el-row>
|
2021-04-28 18:39:01 +08:00
|
|
|
<el-col style="overflow-y: auto;">
|
|
|
|
<el-checkbox-group v-model="checkTableList" size="small">
|
2021-04-30 12:08:39 +08:00
|
|
|
<el-tooltip v-for="t in tableData" :key="t.name" :disabled="t.enableCheck" effect="dark" :content="$t('dataset.table_already_add_to')+': '+t.datasetPath" placement="bottom">
|
|
|
|
<el-checkbox
|
|
|
|
border
|
|
|
|
:label="t.name"
|
|
|
|
:disabled="!t.enableCheck"
|
|
|
|
/>
|
|
|
|
</el-tooltip>
|
2021-04-28 18:39:01 +08:00
|
|
|
</el-checkbox-group>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
2021-03-03 15:06:52 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-05-12 12:25:49 +08:00
|
|
|
import { listDatasource, post, isKettleRunning } from '@/api/dataset/dataset'
|
2021-03-03 18:35:51 +08:00
|
|
|
|
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',
|
2021-07-08 15:05:25 +08:00
|
|
|
syncType: 'sync_now',
|
2021-05-11 19:09:32 +08:00
|
|
|
tableData: [],
|
|
|
|
kettleRunning: false
|
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 !== '') {
|
2021-04-30 16:18:18 +08:00
|
|
|
this.tableData = JSON.parse(JSON.stringify(this.tables.filter(ele => { return ele.name.includes(val) })))
|
2021-03-12 14:17:26 +08:00
|
|
|
} else {
|
|
|
|
this.tableData = JSON.parse(JSON.stringify(this.tables))
|
|
|
|
}
|
2021-03-03 15:06:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.initDataSource()
|
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
this.initDataSource()
|
|
|
|
},
|
2021-05-12 12:25:49 +08:00
|
|
|
created() {
|
2021-05-11 19:09:32 +08:00
|
|
|
this.kettleState()
|
|
|
|
},
|
2021-03-03 15:06:52 +08:00
|
|
|
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
|
|
|
|
})
|
|
|
|
},
|
2021-05-12 12:25:49 +08:00
|
|
|
kettleState() {
|
2021-05-11 19:09:32 +08:00
|
|
|
isKettleRunning().then(res => {
|
|
|
|
this.kettleRunning = res.data
|
|
|
|
})
|
|
|
|
},
|
2021-03-03 15:06:52 +08:00
|
|
|
save() {
|
|
|
|
// console.log(this.checkTableList);
|
|
|
|
// console.log(this.scene);
|
2021-06-02 11:59:33 +08:00
|
|
|
let ds = {}
|
|
|
|
this.options.forEach(ele => {
|
|
|
|
if (ele.id === this.dataSource) {
|
|
|
|
ds = ele
|
|
|
|
}
|
|
|
|
})
|
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
|
2021-07-08 15:05:25 +08:00
|
|
|
const syncType = this.syncType
|
2021-03-03 15:06:52 +08:00
|
|
|
this.checkTableList.forEach(function(name) {
|
|
|
|
tables.push({
|
2021-06-02 11:59:33 +08:00
|
|
|
name: ds.name + '_' + name,
|
2021-03-03 15:06:52 +08:00
|
|
|
sceneId: sceneId,
|
|
|
|
dataSourceId: dataSourceId,
|
|
|
|
type: 'db',
|
2021-07-08 15:05:25 +08:00
|
|
|
syncType: syncType,
|
2021-06-02 11:59:33 +08:00
|
|
|
mode: parseInt(mode),
|
|
|
|
info: JSON.stringify({ table: name })
|
2021-03-03 15:06:52 +08:00
|
|
|
})
|
|
|
|
})
|
2021-03-03 18:35:51 +08:00
|
|
|
post('/dataset/table/batchAdd', tables).then(response => {
|
2021-06-19 11:42:14 +08:00
|
|
|
// this.$store.dispatch('dataset/setSceneData', new Date().getTime())
|
|
|
|
this.$emit('saveSuccess', tables[0])
|
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>
|