dataease/frontend/src/views/dataset/common/DatasetTableData.vue

128 lines
2.9 KiB
Vue
Raw Normal View History

2021-03-03 15:06:52 +08:00
<template>
2022-09-19 17:51:06 +08:00
<el-col
ref="container"
v-loading="dataLoading"
style="width: 100%; height: 100%"
>
2021-03-03 17:38:41 +08:00
<span>{{ table.name }}</span>
<ux-grid
id="dsData"
ref="plxTable"
2021-03-03 17:38:41 +08:00
size="mini"
2022-09-19 17:51:06 +08:00
style="width: 100%"
:height="height"
2022-09-19 17:51:06 +08:00
:checkbox-config="{ highlight: true }"
2021-03-16 11:55:22 +08:00
:width-resize="true"
2021-03-03 17:38:41 +08:00
>
<ux-table-column
2021-03-03 17:38:41 +08:00
v-for="field in fields"
2021-05-11 12:40:12 +08:00
:key="field.dataeaseName"
2021-03-03 17:38:41 +08:00
min-width="200px"
2021-05-11 12:40:12 +08:00
:field="field.dataeaseName"
:resizable="true"
>
<template slot="header">
2022-09-19 17:51:06 +08:00
<svg-icon
v-if="field.deType === 0"
icon-class="field_text"
class="field-icon-text"
/>
<svg-icon
v-if="field.deType === 1"
icon-class="field_time"
class="field-icon-time"
/>
<svg-icon
v-if="field.deType === 2 || field.deType === 3"
icon-class="field_value"
class="field-icon-value"
/>
<svg-icon
v-if="field.deType === 5"
icon-class="field_location"
class="field-icon-location"
/>
<span>{{ field.name }}</span>
</template>
</ux-table-column>
</ux-grid>
2022-09-19 17:51:06 +08:00
<span v-if="table.name" style="font-size: 12px">{{
$t('chart.preview_100_data')
}}</span>
2021-03-03 17:38:41 +08:00
</el-col>
2021-03-03 15:06:52 +08:00
</template>
<script>
import { post } from '@/api/dataset/dataset'
2021-03-03 15:06:52 +08:00
export default {
2021-03-03 17:38:41 +08:00
name: 'DatasetTableData',
2021-03-03 15:06:52 +08:00
props: {
table: {
type: Object,
required: true
}
2021-03-03 15:06:52 +08:00
},
data() {
return {
fields: [],
data: [],
height: 'auto',
dataLoading: false
2021-03-03 15:06:52 +08:00
}
},
2021-03-03 17:38:41 +08:00
watch: {
table() {
this.initData()
}
},
2021-03-03 15:06:52 +08:00
mounted() {
2021-05-26 11:00:41 +08:00
// window.onresize = () => {
// return (() => {
// this.height = window.innerHeight / 3
// })()
// }
// this.height = window.innerHeight / 3
this.$nextTick(() => {
2022-09-19 17:51:06 +08:00
this.height =
document.getElementById('dsData').parentNode.offsetHeight - 16 - 14 - 5
this.initData()
})
2021-03-03 15:06:52 +08:00
},
methods: {
initData() {
2021-03-03 17:38:41 +08:00
this.resetData()
2021-03-03 15:06:52 +08:00
if (this.table.id) {
this.dataLoading = true
this.table.row = 100
2022-09-19 17:51:06 +08:00
post('/dataset/table/getPreviewData/1/100', this.table, false, 30000)
.then((response) => {
this.fields = response.data.fields
this.data = response.data.data
const datas = this.data
if (response.data.status === 'warnning') {
this.$warning(response.data.msg, 3000)
}
if (response.data.status === 'error') {
this.$error(response.data.msg, 3000)
}
this.$refs.plxTable.reloadData(datas)
this.dataLoading = false
})
.catch((res) => {
this.dataLoading = false
})
2021-03-03 15:06:52 +08:00
}
},
resetData() {
2021-03-03 17:38:41 +08:00
this.fields = []
this.data = []
2021-03-03 15:06:52 +08:00
}
}
}
</script>
<style scoped>
</style>