dataease/frontend/src/views/dataset/data/ViewTable.vue

156 lines
4.3 KiB
Vue
Raw Normal View History

2021-03-03 15:06:52 +08:00
<template>
<el-row style="height: 100%;overflow-y: hidden;width: 100%;">
<el-row style="height: 26px;">
<el-popover
placement="right-start"
width="400"
trigger="click"
@show="showTab"
@hide="hideTab"
>
<dataset-chart-detail type="dataset" :data="table" :tab-status="tabStatus" />
<span slot="reference" style="line-height: 26px;cursor: pointer;">
{{ table.name }}
</span>
</el-popover>
<el-row style="float: right">
2021-05-12 14:45:13 +08:00
<el-button v-if="table.type ==='custom'" size="mini" @click="editCustom">
{{ $t('dataset.edit_custom_table') }}
</el-button>
<el-button v-if="table.type ==='sql'" size="mini" @click="editSql">
{{ $t('dataset.edit_sql') }}
</el-button>
<el-button size="mini" @click="edit">
2021-05-12 14:45:13 +08:00
{{ $t('dataset.edit_field') }}
</el-button>
<!-- <el-button size="mini" type="primary" @click="createChart">-->
<!-- {{$t('dataset.create_view')}}-->
<!-- </el-button>-->
2021-03-03 15:06:52 +08:00
</el-row>
</el-row>
<el-divider />
<el-tabs v-model="tabActive">
<el-tab-pane :label="$t('dataset.data_preview')" name="dataPreview">
<tab-data-preview :table="table" :fields="fields" :data="data" :page="page" :form="tableViewRowForm" @reSearch="reSearch" />
</el-tab-pane>
<el-tab-pane v-if="table.type !== 'custom' && table.mode === 1" :label="$t('dataset.join_view')" name="joinView">
<union-view :table="table" />
</el-tab-pane>
<el-tab-pane v-if="table.mode === 1 && (table.type === 'db' || table.type === 'sql')" :label="$t('dataset.update_info')" name="updateInfo">
<update-info :table="table" />
</el-tab-pane>
</el-tabs>
</el-row>
2021-03-03 15:06:52 +08:00
</template>
<script>
2021-04-29 15:43:15 +08:00
import { getTable, post } from '@/api/dataset/dataset'
2021-03-03 15:06:52 +08:00
import TabDataPreview from './TabDataPreview'
import UpdateInfo from './UpdateInfo'
import DatasetChartDetail from '../common/DatasetChartDetail'
import UnionView from './UnionView'
2021-03-03 15:06:52 +08:00
export default {
name: 'ViewTable',
components: { UnionView, DatasetChartDetail, UpdateInfo, TabDataPreview },
props: {
param: {
type: String,
required: true
}
},
2021-03-03 15:06:52 +08:00
data() {
return {
table: {
name: ''
},
fields: [],
data: [],
page: {
page: 1,
pageSize: 100,
show: 1000
},
2021-03-03 15:06:52 +08:00
tabActive: 'dataPreview',
tableViewRowForm: {
row: 1000
},
2021-04-29 15:43:15 +08:00
tabStatus: false
2021-03-03 15:06:52 +08:00
}
},
watch: {
'param': function() {
this.initTable(this.param)
2021-03-03 15:06:52 +08:00
}
},
mounted() {
this.initTable(this.param)
2021-03-03 15:06:52 +08:00
},
methods: {
initTable(id) {
2021-04-12 17:32:20 +08:00
this.tabActive = 'dataPreview'
this.tableViewRowForm.row = 1000
2021-03-03 15:06:52 +08:00
if (id !== null) {
this.fields = []
this.data = []
getTable(id).then(response => {
2021-03-03 15:06:52 +08:00
this.table = response.data
this.initPreviewData(this.page)
2021-03-03 15:06:52 +08:00
})
}
},
initPreviewData(page) {
2021-03-03 15:06:52 +08:00
if (this.table.id) {
this.table.row = this.tableViewRowForm.row
post('/dataset/table/getPreviewData/' + page.page + '/' + page.pageSize, this.table).then(response => {
2021-03-03 15:06:52 +08:00
this.fields = response.data.fields
this.data = response.data.data
this.page = response.data.page
2021-05-25 17:48:29 +08:00
if(response.data.status === 'warnning'){
this.$warning(response.data.msg, 3000);
}
if(response.data.status === 'error'){
this.$error(response.data.msg, 3000);
}
2021-03-03 15:06:52 +08:00
})
}
},
edit() {
2021-04-29 15:43:15 +08:00
this.$emit('switchComponent', { name: 'FieldEdit', param: { table: this.table }})
},
editSql() {
this.$emit('switchComponent', { name: 'AddSQL', param: { id: this.table.sceneId, tableId: this.table.id }})
},
2021-05-12 14:45:13 +08:00
editCustom() {
this.$emit('switchComponent', { name: 'AddCustom', param: { id: this.table.sceneId, tableId: this.table.id }})
},
reSearch(val) {
this.tableViewRowForm = val.form
this.initPreviewData(val.page)
},
showTab() {
this.tabStatus = true
},
hideTab() {
this.tabStatus = false
2021-03-03 15:06:52 +08:00
}
}
}
</script>
<style scoped>
.el-divider--horizontal {
margin: 12px 0;
}
.form-item {
margin-bottom: 6px;
}
</style>