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

230 lines
6.7 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%;">
2021-07-06 19:26:15 +08:00
<!-- <span v-show="false">{{ tableRefresh }}</span>-->
<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" />
2021-10-08 17:22:21 +08:00
<span slot="reference" class="title-text" style="line-height: 26px;cursor: pointer;">
{{ table.name }}
</span>
</el-popover>
2021-07-06 19:26:15 +08:00
<el-row v-if="hasDataPermission('manage',param.privileges)" style="float: right">
2021-06-08 12:30:26 +08:00
<el-dropdown v-if="table.type ==='excel'" style="margin-right: 10px;" size="small" trigger="click" @command="clickEditExcel">
<el-button size="mini">
2021-06-08 11:12:40 +08:00
{{ $t('dataset.edit_excel') }}
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="beforeEditExcel('0')">
{{ $t('dataset.excel_replace') }}
</el-dropdown-item>
<el-dropdown-item :command="beforeEditExcel('1')">
{{ $t('dataset.excel_add') }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
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">-->
<!-- {{ $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" @tab-click="tabClick">
<el-tab-pane :label="$t('dataset.data_preview')" name="dataPreview">
2021-07-06 19:26:15 +08:00
<tab-data-preview :param="param" :table="table" :fields="fields" :data="data" :page="page" :form="tableViewRowForm" @reSearch="reSearch" />
</el-tab-pane>
<el-tab-pane :label="$t('dataset.field_manage')" name="fieldEdit">
<field-edit :param="param" />
</el-tab-pane>
<el-tab-pane v-if="table.type !== 'custom'" :label="$t('dataset.join_view')" name="joinView">
2021-07-06 19:26:15 +08:00
<union-view :param="param" :table="table" />
</el-tab-pane>
2021-07-23 18:35:37 +08:00
<el-tab-pane v-if="table.mode === 1 && (table.type === 'excel' || table.type === 'db' || table.type === 'sql')" :label="$t('dataset.update_info')" name="updateInfo">
2021-07-06 19:26:15 +08:00
<update-info :param="param" :table="table" />
</el-tab-pane>
</el-tabs>
</el-row>
2021-03-03 15:06:52 +08:00
</template>
<script>
import { 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'
import FieldEdit from './FieldEdit'
2021-03-03 15:06:52 +08:00
export default {
name: 'ViewTable',
components: { FieldEdit, UnionView, DatasetChartDetail, UpdateInfo, TabDataPreview },
props: {
param: {
2021-07-06 19:26:15 +08:00
type: Object,
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
}
},
computed: {
// tableRefresh() {
// this.initTable(this.param)
// return this.$store.state.dataset.table
// }
},
watch: {
'param': function() {
this.tabActive = 'dataPreview'
2021-07-06 19:26:15 +08:00
this.initTable(this.param.id)
2021-03-03 15:06:52 +08:00
}
},
created() {
2021-03-03 15:06:52 +08:00
},
mounted() {
2021-07-06 19:26:15 +08:00
this.initTable(this.param.id)
2021-03-03 15:06:52 +08:00
},
methods: {
initTable(id) {
this.resetPage()
this.tableViewRowForm.row = 1000
2021-03-03 15:06:52 +08:00
if (id !== null) {
this.fields = []
this.data = []
2021-07-27 19:13:22 +08:00
post('/dataset/table/getWithPermission/' + id, null).then(response => {
2021-03-03 15:06:52 +08:00
this.table = response.data
this.initPreviewData(this.page)
}).catch(res => {
this.$emit('switchComponent', { name: '' })
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, true, 30000).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-06-08 11:12:40 +08:00
if (response.data.status === 'warnning') {
2021-05-25 17:51:35 +08:00
this.$warning(response.data.msg, 3000)
2021-05-25 17:48:29 +08:00
}
2021-06-08 11:12:40 +08:00
if (response.data.status === 'error') {
2021-05-25 17:51:35 +08:00
this.$error(response.data.msg, 3000)
}
2021-05-25 17:41:23 +08:00
}).catch(response => {
this.fields = []
this.data = []
this.page = {
page: 1,
pageSize: 100,
show: 0
2021-05-25 17:48:29 +08:00
}
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, table: this.table }})
},
2021-05-12 14:45:13 +08:00
editCustom() {
this.$emit('switchComponent', { name: 'AddCustom', param: { id: this.table.sceneId, tableId: this.table.id, table: this.table }})
2021-05-12 14:45:13 +08:00
},
reSearch(val) {
this.tableViewRowForm = val.form
this.initPreviewData(val.page)
},
showTab() {
this.tabStatus = true
},
hideTab() {
this.tabStatus = false
2021-06-08 11:12:40 +08:00
},
clickEditExcel(param) {
// console.log(param);
switch (param.type) {
case '0':
2021-06-08 11:30:26 +08:00
this.$emit('switchComponent', { name: 'AddExcel', param: { id: this.table.sceneId, tableId: this.table.id, editType: 0, table: this.table }})
2021-06-08 11:12:40 +08:00
break
case '1':
2021-06-08 11:30:26 +08:00
this.$emit('switchComponent', { name: 'AddExcel', param: { id: this.table.sceneId, tableId: this.table.id, editType: 1, table: this.table }})
2021-06-08 11:12:40 +08:00
break
}
},
beforeEditExcel(type) {
return {
'type': type
}
},
msg2Current(sourceParam) {
this.tabActive = 'updateInfo'
this.table.msgTaskId = sourceParam.taskId
},
resetPage() {
this.page = {
page: 1,
pageSize: 100,
show: 1000
}
},
tabClick() {
if (this.tabActive === 'dataPreview') {
this.initTable(this.param.id)
}
2021-03-03 15:06:52 +08:00
}
}
}
</script>
<style scoped>
.el-divider--horizontal {
margin: 12px 0;
}
.form-item {
margin-bottom: 6px;
}
</style>