2021-03-25 19:16:32 +08:00
|
|
|
|
<template>
|
2021-05-06 23:40:34 +08:00
|
|
|
|
<div v-loading="requestStatus==='waiting'" class="rect-shape">
|
2021-06-07 11:01:21 +08:00
|
|
|
|
<div v-if="requestStatus==='error'" class="chart-error-class">
|
|
|
|
|
<div style="font-size: 12px; color: #9ea6b2;height: 100%;display: flex;align-items: center;justify-content: center;">
|
|
|
|
|
{{ message.response.data.message }},{{ $t('chart.chart_show_error') }}
|
|
|
|
|
<br>
|
|
|
|
|
{{ $t('chart.chart_error_tips') }}
|
2021-05-05 23:48:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-05-18 16:38:24 +08:00
|
|
|
|
<chart-component v-if="requestStatus==='success'&&chart.type && !chart.type.includes('table') && !chart.type.includes('text')" :ref="element.propValue.id" class="chart-class" :chart="chart" />
|
|
|
|
|
<table-normal v-if="requestStatus==='success'&&chart.type && chart.type.includes('table')" :ref="element.propValue.id" :chart="chart" class="table-class" />
|
|
|
|
|
<label-normal v-if="requestStatus==='success'&&chart.type && chart.type.includes('text')" :ref="element.propValue.id" :chart="chart" class="table-class" />
|
2021-03-25 19:16:32 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
2021-05-06 23:40:34 +08:00
|
|
|
|
import { viewData } from '@/api/panel/panel'
|
2021-03-25 19:16:32 +08:00
|
|
|
|
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-18 16:38:24 +08:00
|
|
|
|
import LabelNormal from '../../../views/chart/components/normal/LabelNormal'
|
2021-05-26 16:15:54 +08:00
|
|
|
|
import { uuid } from 'vue-uuid'
|
2021-05-05 23:48:05 +08:00
|
|
|
|
|
2021-05-05 22:14:23 +08:00
|
|
|
|
import { mapState } from 'vuex'
|
2021-06-08 16:03:49 +08:00
|
|
|
|
import { isChange } from '@/utils/conditionUtil'
|
2021-05-05 22:14:23 +08:00
|
|
|
|
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-18 16:38:24 +08:00
|
|
|
|
components: { ChartComponent, TableNormal, LabelNormal },
|
2021-03-25 19:16:32 +08:00
|
|
|
|
props: {
|
|
|
|
|
element: {
|
2021-06-07 17:08:57 +08:00
|
|
|
|
type: Object,
|
|
|
|
|
default: null
|
2021-04-19 18:20:15 +08:00
|
|
|
|
},
|
2021-06-08 16:03:49 +08:00
|
|
|
|
// filters: {
|
|
|
|
|
// type: Array,
|
|
|
|
|
// required: false,
|
|
|
|
|
// default: null
|
|
|
|
|
// },
|
2021-05-26 16:15:54 +08:00
|
|
|
|
outStyle: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: false,
|
|
|
|
|
default: function() {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
2021-04-19 18:20:15 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-03-25 19:16:32 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
2021-05-26 16:15:54 +08:00
|
|
|
|
refId: null,
|
2021-05-05 22:14:23 +08:00
|
|
|
|
chart: {
|
2021-05-06 23:40:34 +08:00
|
|
|
|
stylePriority: 'panel',
|
|
|
|
|
xaxis: '[]',
|
|
|
|
|
yaxis: '[]',
|
2021-05-05 22:14:23 +08:00
|
|
|
|
show: true,
|
|
|
|
|
type: 'panel',
|
|
|
|
|
title: '',
|
2021-05-06 23:40:34 +08:00
|
|
|
|
customAttr: JSON.stringify({
|
2021-05-05 22:14:23 +08:00
|
|
|
|
color: DEFAULT_COLOR_CASE,
|
|
|
|
|
size: DEFAULT_SIZE,
|
|
|
|
|
label: DEFAULT_LABEL,
|
|
|
|
|
tooltip: DEFAULT_TOOLTIP
|
2021-05-06 23:40:34 +08:00
|
|
|
|
}),
|
|
|
|
|
customStyle: JSON.stringify({
|
2021-05-05 22:14:23 +08:00
|
|
|
|
text: DEFAULT_TITLE_STYLE,
|
|
|
|
|
legend: DEFAULT_LEGEND_STYLE,
|
|
|
|
|
xAxis: DEFAULT_XAXIS_STYLE,
|
|
|
|
|
yAxis: DEFAULT_YAXIS_STYLE,
|
|
|
|
|
background: DEFAULT_BACKGROUND_COLOR
|
2021-05-06 23:40:34 +08:00
|
|
|
|
}),
|
|
|
|
|
customFilter: '[]'
|
2021-05-05 23:48:05 +08:00
|
|
|
|
},
|
|
|
|
|
requestStatus: 'waiting',
|
|
|
|
|
message: null
|
2021-03-25 19:16:32 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-06-08 16:03:49 +08:00
|
|
|
|
computed: {
|
|
|
|
|
filter() {
|
|
|
|
|
const filter = {}
|
|
|
|
|
filter.filter = this.element.filters
|
|
|
|
|
return filter
|
|
|
|
|
},
|
|
|
|
|
filters() {
|
|
|
|
|
// 必要 勿删勿该 watch数组,哪怕发生变化 oldValue等于newValue ,深拷贝解决
|
2021-06-08 18:33:28 +08:00
|
|
|
|
if (!this.element.filters) return []
|
2021-06-08 16:03:49 +08:00
|
|
|
|
return JSON.parse(JSON.stringify(this.element.filters))
|
|
|
|
|
},
|
|
|
|
|
...mapState([
|
|
|
|
|
'canvasStyleData'
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
|
2021-06-07 17:08:57 +08:00
|
|
|
|
watch: {
|
2021-06-08 16:03:49 +08:00
|
|
|
|
'filters': function(val1, val2) {
|
|
|
|
|
// this.getData(this.element.propValue.viewId)
|
|
|
|
|
isChange(val1, val2) && this.getData(this.element.propValue.viewId)
|
2021-06-07 17:08:57 +08:00
|
|
|
|
},
|
|
|
|
|
// deep监听panel 如果改变 提交到 store
|
|
|
|
|
canvasStyleData: {
|
|
|
|
|
handler(newVal, oldVla) {
|
|
|
|
|
// this.chart.stylePriority == panel 优先使用仪表板样式
|
|
|
|
|
this.mergeStyle()
|
|
|
|
|
},
|
|
|
|
|
deep: true
|
|
|
|
|
},
|
|
|
|
|
// 监听外部的样式变化
|
|
|
|
|
outStyle: {
|
|
|
|
|
handler(newVal, oldVla) {
|
|
|
|
|
if (this.$refs[this.element.propValue.id]) {
|
|
|
|
|
this.$refs[this.element.propValue.id].chartResize()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deep: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2021-03-25 19:16:32 +08:00
|
|
|
|
created() {
|
2021-06-07 17:08:57 +08:00
|
|
|
|
this.refId = uuid.v1
|
|
|
|
|
// this.filter.filter = this.$store.getters.conditions
|
2021-04-01 11:38:30 +08:00
|
|
|
|
this.getData(this.element.propValue.viewId)
|
2021-03-25 19:16:32 +08:00
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2021-05-06 23:40:34 +08:00
|
|
|
|
mergeStyle() {
|
2021-05-28 11:21:54 +08:00
|
|
|
|
// this.chart.stylePriority == panel 优先使用仪表板样式
|
2021-05-06 23:40:34 +08:00
|
|
|
|
if ((this.requestStatus === 'success' || this.requestStatus === 'merging') && this.chart.stylePriority === 'panel' && this.canvasStyleData.chart) {
|
|
|
|
|
const customAttrChart = JSON.parse(this.chart.customAttr)
|
|
|
|
|
const customStyleChart = JSON.parse(this.chart.customStyle)
|
|
|
|
|
|
|
|
|
|
const customAttrPanel = JSON.parse(this.canvasStyleData.chart.customAttr)
|
|
|
|
|
const customStylePanel = JSON.parse(this.canvasStyleData.chart.customStyle)
|
|
|
|
|
|
2021-06-11 12:09:11 +08:00
|
|
|
|
// 组件样式-标题设置 - 标题修改为组件自己控制
|
|
|
|
|
// customStyleChart.text = customStylePanel.text
|
2021-05-06 23:40:34 +08:00
|
|
|
|
// 组件样式-背景设置
|
2021-05-07 19:20:47 +08:00
|
|
|
|
customStyleChart.background = customStylePanel.background
|
2021-05-06 23:40:34 +08:00
|
|
|
|
// 图形属性-颜色设置
|
2021-05-07 19:20:47 +08:00
|
|
|
|
customAttrChart.color = customAttrPanel.color
|
2021-05-06 23:40:34 +08:00
|
|
|
|
|
|
|
|
|
this.chart = {
|
|
|
|
|
...this.chart,
|
|
|
|
|
customAttr: JSON.stringify(customAttrChart),
|
2021-05-07 19:20:47 +08:00
|
|
|
|
customStyle: JSON.stringify(customStyleChart)
|
2021-05-06 23:40:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-03-25 19:16:32 +08:00
|
|
|
|
getData(id) {
|
|
|
|
|
if (id) {
|
2021-05-05 23:48:05 +08:00
|
|
|
|
this.requestStatus = 'waiting'
|
|
|
|
|
this.message = null
|
2021-05-06 23:40:34 +08:00
|
|
|
|
viewData(id, this.filter).then(response => {
|
2021-03-25 19:16:32 +08:00
|
|
|
|
// 将视图传入echart组件
|
2021-05-05 23:48:05 +08:00
|
|
|
|
if (response.success) {
|
|
|
|
|
this.chart = response.data
|
2021-05-06 23:40:34 +08:00
|
|
|
|
this.requestStatus = 'merging'
|
|
|
|
|
this.mergeStyle()
|
2021-05-05 23:48:05 +08:00
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
}
|
2021-06-08 16:03:49 +08:00
|
|
|
|
},
|
|
|
|
|
viewIdMatch(viewIds, viewId) {
|
|
|
|
|
return !viewIds || viewIds.length === 0 || viewIds.includes(viewId)
|
2021-03-25 19:16:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.rect-shape {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2021-05-19 16:29:19 +08:00
|
|
|
|
overflow: hidden;
|
2021-03-25 19:16:32 +08:00
|
|
|
|
}
|
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-06-07 11:01:21 +08:00
|
|
|
|
.chart-error-class{
|
|
|
|
|
text-align: center;
|
|
|
|
|
height: calc(100% - 84px);
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
background-color: #ece7e7;
|
|
|
|
|
}
|
2021-03-25 19:16:32 +08:00
|
|
|
|
</style>
|