dataease-dm/frontend/src/components/canvas/custom-component/UserView.vue

150 lines
3.6 KiB
Vue
Raw Normal View History

2021-03-25 19:16:32 +08:00
<template>
2021-05-05 23:48:05 +08:00
<div v-loading="$store.getters.loadingMap[$store.getters.currentPath]" class="rect-shape">
<div v-if="requestStatus==='error'" style=";width: 100%;height: 100%;background-color: #ece7e7; text-align: center">
<div style="font-size: 12px; color: #9ea6b2;">
获取数据出错 请联系管理员<br>
{{ message }}
</div>
</div>
<chart-component v-if="requestStatus==='success'&&chart.type && !chart.type.includes('table')" :ref="element.propValue.id" class="chart-class" :chart="chart" />
<table-normal v-if="requestStatus==='success'&&chart.type && chart.type.includes('table')" :chart="chart" class="table-class" />
2021-03-25 19:16:32 +08:00
</div>
</template>
<script>
import { post } from '@/api/panel/panel'
import ChartComponent from '@/views/chart/components/ChartComponent.vue'
2021-05-05 23:48:05 +08:00
import TableNormal from '@/views/chart/components/table/TableNormal'
2021-05-05 22:14:23 +08:00
import { mapState } from 'vuex'
import { deepCopy } from '@/components/canvas/utils/utils'
import {
DEFAULT_COLOR_CASE,
DEFAULT_SIZE,
DEFAULT_TITLE_STYLE,
DEFAULT_LEGEND_STYLE,
DEFAULT_LABEL,
DEFAULT_TOOLTIP,
DEFAULT_XAXIS_STYLE,
DEFAULT_YAXIS_STYLE,
DEFAULT_BACKGROUND_COLOR
} from '@/views/chart/chart/chart'
2021-04-01 11:38:30 +08:00
2021-03-25 19:16:32 +08:00
export default {
name: 'UserView',
2021-05-05 23:48:05 +08:00
components: { ChartComponent, TableNormal },
2021-03-25 19:16:32 +08:00
props: {
element: {
type: Object
2021-04-19 18:20:15 +08:00
},
filter: {
type: Object,
required: false,
default: function() {
return {
filter: []
}
}
}
},
watch: {
filter(val) {
this.getData(this.element.propValue.viewId)
2021-05-05 22:14:23 +08:00
},
// deep监听panel 如果改变 提交到 store
canvasStyleData: {
handler(newVal, oldVla) {
debugger
// this.chart.viewFirst == false 优先使用仪表盘样式
if (!this.chart.viewFirst) {
this.chart = {
...this.chart,
customAttr: this.canvasStyleData.chart.customAttr,
customStyle: this.canvasStyleData.chart.customStyle
}
}
},
deep: true
2021-03-25 19:16:32 +08:00
}
},
2021-05-05 22:14:23 +08:00
computed: mapState([
'canvasStyleData'
]),
2021-03-25 19:16:32 +08:00
data() {
return {
2021-05-05 22:14:23 +08:00
chart: {
viewFirst: false,
xaxis: [],
yaxis: [],
show: true,
type: 'panel',
title: '',
customAttr: {
color: DEFAULT_COLOR_CASE,
size: DEFAULT_SIZE,
label: DEFAULT_LABEL,
tooltip: DEFAULT_TOOLTIP
},
customStyle: {
text: DEFAULT_TITLE_STYLE,
legend: DEFAULT_LEGEND_STYLE,
xAxis: DEFAULT_XAXIS_STYLE,
yAxis: DEFAULT_YAXIS_STYLE,
background: DEFAULT_BACKGROUND_COLOR
},
customFilter: []
2021-05-05 23:48:05 +08:00
},
requestStatus: 'waiting',
message: null
2021-03-25 19:16:32 +08:00
}
},
created() {
2021-04-01 11:38:30 +08:00
this.getData(this.element.propValue.viewId)
2021-03-25 19:16:32 +08:00
},
mounted() {
},
methods: {
getData(id) {
if (id) {
2021-05-05 23:48:05 +08:00
this.requestStatus = 'waiting'
this.message = null
2021-04-19 18:20:15 +08:00
post('/chart/view/getData/' + id, this.filter).then(response => {
2021-03-25 19:16:32 +08:00
// 将视图传入echart组件
2021-05-05 23:48:05 +08:00
debugger
if (response.success) {
this.chart = response.data
this.requestStatus = 'success'
} else {
this.requestStatus = 'error'
this.message = response.massage
}
return true
}).catch(err => {
this.requestStatus = 'error'
this.message = err
return true
2021-03-25 19:16:32 +08:00
})
}
}
}
}
</script>
<style lang="scss" scoped>
.rect-shape {
width: 100%;
height: 100%;
overflow: auto;
}
2021-03-26 12:26:48 +08:00
.chart-class{
height: 100%;
}
2021-05-05 23:48:05 +08:00
.table-class{
height: 100%;
}
2021-03-25 19:16:32 +08:00
</style>