dataease/frontend/src/views/dataset/add/AddCustom.vue

291 lines
7.8 KiB
Vue
Raw Normal View History

<template>
<el-col>
2021-05-10 15:22:36 +08:00
<el-row style="height: 26px;">
<span style="line-height: 26px;">
2021-05-12 14:45:13 +08:00
{{ param.tableId?$t('dataset.edit_custom_table'):$t('dataset.add_custom_table') }}
2021-05-10 15:22:36 +08:00
</span>
<el-row style="float: right">
<el-button size="mini" @click="cancel">
{{ $t('dataset.cancel') }}
</el-button>
<el-button :disabled="!name || checkedList.length === 0" size="mini" type="primary" @click="save">
{{ $t('dataset.confirm') }}
</el-button>
</el-row>
</el-row>
2021-05-10 15:22:36 +08:00
<el-divider />
<el-row>
<el-form :inline="true">
2021-06-08 16:30:20 +08:00
<el-form-item class="form-item" :label="$t('commons.name')">
2021-05-10 15:22:36 +08:00
<el-input v-model="name" size="mini" :placeholder="$t('commons.name')" />
</el-form-item>
</el-form>
</el-row>
<el-col style="display: flex;flex-direction: row">
2021-05-10 15:30:35 +08:00
<el-col class="panel-height" style="width: 220px;border-right:solid 1px #dcdfe6;border-top:solid 1px #dcdfe6;padding-right: 15px;overflow-y: auto;">
<dataset-group-selector :custom-type="customType" :table="table" :mode="1" :checked-list="checkedList" :union-data="unionData" @getTable="getTable" />
2021-05-10 15:22:36 +08:00
</el-col>
2021-05-10 15:30:35 +08:00
<el-col class="panel-height" style="width: 235px;border-top:solid 1px #dcdfe6;padding: 0 15px;overflow-y: auto;">
2021-05-10 15:22:36 +08:00
<dataset-custom-field :table="table" :checked-list="checkedList" @getChecked="getChecked" />
</el-col>
2021-05-11 10:48:59 +08:00
<el-col class="panel-height" style="flex: 1;overflow: hidden;">
<el-card class="box-card dataPreview" shadow="never">
<div slot="header" class="clearfix">
<span>{{ $t('dataset.data_preview') }}</span>
</div>
<ux-grid
ref="plxTable"
size="mini"
style="width: 100%;"
:height="height"
:checkbox-config="{highlight: true}"
:width-resize="true"
>
<ux-table-column
v-for="field in fields"
:key="field.fieldName"
min-width="200px"
:field="field.fieldName"
:title="field.remarks"
:resizable="true"
/>
</ux-grid>
<span class="table-count">
{{ $t('dataset.preview_show') }}
<span class="span-number">1000</span>
{{ $t('dataset.preview_item') }}
</span>
</el-card>
2021-05-10 15:22:36 +08:00
</el-col>
</el-col>
</el-col>
</template>
<script>
2021-05-12 14:45:13 +08:00
import { post, getTable } from '@/api/dataset/dataset'
2021-05-10 15:22:36 +08:00
import DatasetGroupSelector from '../common/DatasetGroupSelector'
import DatasetCustomField from '../common/DatasetCustomField'
export default {
name: 'AddCustom',
2021-05-10 15:22:36 +08:00
components: { DatasetCustomField, DatasetGroupSelector },
props: {
param: {
type: Object,
default: null
}
},
data() {
return {
2021-06-08 16:30:20 +08:00
name: '自定义数据集',
2021-05-10 15:22:36 +08:00
table: {},
checkedList: [],
2021-05-10 15:30:35 +08:00
unionData: [],
height: 500,
data: [],
fields: [],
customType: ['db', 'sql', 'excel']
}
},
watch: {
2021-05-10 15:22:36 +08:00
'checkedList': function() {
// console.log(this.checkedList)
2021-05-12 14:45:13 +08:00
this.getUnionData()
2021-05-10 15:22:36 +08:00
}
},
mounted() {
2021-05-10 15:30:35 +08:00
window.onresize = () => {
this.calHeight()
}
this.calHeight()
2021-05-12 14:45:13 +08:00
if (this.param && this.param.id && this.param.tableId) {
this.getCustomTable()
this.getUnionData()
}
},
methods: {
2021-05-10 15:30:35 +08:00
calHeight() {
const that = this
setTimeout(function() {
const currentHeight = document.documentElement.clientHeight
2021-05-11 10:48:59 +08:00
that.height = currentHeight - 56 - 15 - 26 - 25 - 43 - 16 - 37 - 20 - 10
2021-05-10 15:30:35 +08:00
}, 10)
},
2021-05-10 15:22:36 +08:00
getTable(table) {
// console.log(table)
this.table = table
},
getChecked(tableCheckedField) {
// console.log(tableCheckedField)
if (tableCheckedField.checkedFields && tableCheckedField.checkedFields.length > 0) {
if (!this.checkedList.some(ele => ele.tableId === tableCheckedField.tableId)) {
this.checkedList.push(tableCheckedField)
} else {
this.checkedList.forEach(ele => {
if (ele.tableId === tableCheckedField.tableId) {
ele.checkedFields = tableCheckedField.checkedFields
}
})
}
} else {
let index = -1
for (let i = 0; i < this.checkedList.length; i++) {
if (this.checkedList[i].tableId === tableCheckedField.tableId) {
index = i
break
}
}
if (index > -1) {
this.checkedList.splice(index, 1)
}
}
// console.log(this.checkedList)
2021-05-12 14:45:13 +08:00
this.getData()
},
getData() {
2021-05-10 15:22:36 +08:00
// request to get data
if (this.checkedList.length > 0) {
const table = {
id: this.param.tableId,
name: this.name,
sceneId: this.param.id,
dataSourceId: null,
type: 'custom',
mode: 1,
info: '{"list":' + JSON.stringify(this.checkedList) + '}'
}
post('/dataset/table/customPreview', table).then(response => {
console.log(response)
2021-05-10 15:30:35 +08:00
this.fields = response.data.fields
this.data = response.data.data
const datas = this.data
this.$refs.plxTable.reloadData(datas)
})
2021-05-10 18:11:57 +08:00
} else {
this.fields = []
this.data = []
const datas = this.data
this.$refs.plxTable.reloadData(datas)
2021-05-10 15:22:36 +08:00
}
},
2021-05-12 14:45:13 +08:00
getUnionData() {
if (this.checkedList && this.checkedList.length > 0) {
// 根据第一个选择的数据集找到关联视图
post('dataset/union/listByTableId/' + this.checkedList[0].tableId, {}).then(response => {
// console.log(response)
this.unionData = response.data
})
} else {
this.unionData = []
}
},
2021-05-10 15:22:36 +08:00
save() {
if (!this.name || this.name === '') {
this.$message({
showClose: true,
message: this.$t('dataset.pls_input_name'),
type: 'error'
})
return
}
if (this.name.length > 50) {
this.$message({
showClose: true,
message: this.$t('dataset.char_can_not_more_50'),
type: 'error'
})
return
}
2021-05-10 15:22:36 +08:00
const table = {
id: this.param.tableId,
name: this.name,
sceneId: this.param.id,
dataSourceId: null,
type: 'custom',
mode: 1,
info: '{"list":' + JSON.stringify(this.checkedList) + '}'
}
post('/dataset/table/update', table).then(response => {
this.$store.dispatch('dataset/setSceneData', new Date().getTime())
this.cancel()
})
},
2021-05-12 14:45:13 +08:00
getCustomTable() {
getTable(this.param.tableId).then(response => {
const table = response.data
this.name = table.name
this.checkedList = JSON.parse(table.info).list
this.getCheckTable(this.checkedList[0].tableId)
this.getData()
})
},
getCheckTable(tableId) {
getTable(tableId).then(response => {
this.table = response.data
})
},
cancel() {
2021-05-13 17:41:05 +08:00
// this.dataReset()
if (this.param.tableId) {
this.$emit('switchComponent', { name: 'ViewTable', param: this.param.tableId })
} else {
this.$emit('switchComponent', { name: '' })
}
},
dataReset() {
2021-05-10 15:22:36 +08:00
}
}
}
</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-05-11 10:48:59 +08:00
.dataPreview>>>.el-card__header{
padding: 6px 8px;
}
.dataPreview>>>.el-card__body{
padding:10px;
}
span{
font-size: 14px;
}
2021-05-10 15:22:36 +08:00
.panel-height{
height: calc(100vh - 56px - 15px - 26px - 25px - 43px);
}
2021-05-11 10:48:59 +08:00
.span-number{
2021-06-03 11:28:44 +08:00
color: #0a7be0;
2021-05-11 10:48:59 +08:00
}
.table-count{
color: #606266;
}
</style>