index.vue
4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!--
* 功能:折线图
* 作者:闫李壮
* 日期:2024-06-04
-->
<template>
<div class="chart-container">
<a-tooltip content="下载" position="bottom" v-if="isDownload">
<img class="download-icon"
:style="{ right: '50px', top: '4px' }"
src="@/assets/bi/technology/icon-download.png" alt="" @click="download">
</a-tooltip>
<!-- 额外操作栏,只有当configType为1时显示 -->
<div class="time-search" v-if="configType === 1">
<time-bar @change="timeBarChange" isCurrentDateDisabled/>
</div>
<!-- 加载动画,加载完成后显示图表 -->
<a-spin :loading="loading" class="chart-view" :tip="$t('global.loading')">
<template v-if="chartInfo.echartsOption?.series?.length>0">
<div class="echart-wapper">
<CutomChart ref="chartRef" v-if="!loading" :options="chartInfo.echartsOption"/>
</div>
<div class="total-wapper" v-if="chartInfo.singleRightList?.length">
<category-total class="category-total" :data="chartInfo.singleRightList" :type="totalType"/>
</div>
</template>
<a-empty v-else/>
</a-spin>
</div>
</template>
<script setup lang="ts">
import {onMounted, ref} from 'vue';
import useLoading from '@/hooks/loading';
import {getChartInfo} from '@/api/dashboard/api';
import {useIntervalFn} from '@vueuse/core';
import {getTimeObject, handlePreConfigChart} from '@/utils/charts';
import CategoryTotal from "@/views/bi/template/technology/components/category-total.vue";
// 定义图表信息的接口
interface IChartInfo {
cardName: string;
echartsOption: any;
singleInfo: null | any;
singleRightList: Array<any>;
}
// 定义组件接收的属性
const props = defineProps({
public: {
type: Object,
default: () => ({}),
},
configType: {
type: Number,
default: 1,
},
// 设备编号
deviceSn: {
type: String,
default: ''
},
totalType: {
type: Number,
default: 2,
},
pageTemplate: {
type: [String,Number],
default: '1',
},
isDownload: {
type: Boolean,
default: false,
}
});
// 状态管理
const {loading, setLoading} = useLoading(false);
const chartInfo = ref<IChartInfo>({
cardName: '',
echartsOption: {
series: []
},
singleInfo: null,
singleRightList: [],
});
const timeOptions = ref<any>({});
// 时间变化处理函数
const timeBarChange = async (timer: any) => {
timeOptions.value = timer;
await fetchData();
};
// 数据获取函数
const fetchData = async () => {
if(!props.public.cardKey || !props.public.dashboardConfigId){
return;
}
try {
setLoading(true);
const params = {
configId: props.public.dashboardConfigId,
cardKey: props.public.cardKey,
deviceSn: props.deviceSn,
...getTimeObject(timeOptions.value),
};
const res = await getChartInfo(params);
if (res.code === 200 && res.data) {
chartInfo.value = {
...res.data,
echartsOption: handlePreConfigChart(res.data.echartsOption, '', res.data.chartType),
};
} else {
chartInfo.value = {
cardName: '',
echartsOption: {},
singleInfo: null,
};
}
} catch (error) {
console.error('获取图表数据时出错:', error);
} finally {
setLoading(false);
}
};
const chartRef = ref<any>(null)
const download = () => {
chartRef.value.downloadEchartsImg(chartInfo.value.cardName)
}
// 每5分钟轮询一次数据
useIntervalFn(fetchData, 300000);
onMounted(() => {
if(props.configType !== 1){
fetchData();
}
});
defineExpose({
handleTime: (val: any) => {
timeBarChange(val);
},
});
</script>
<style scoped lang="less">
.chart-container {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
.download-icon {
position: absolute;
color: #FFFFFF;
cursor: pointer;
z-index: 999999;
}
.time-search {
width: 100%;
display: flex;
justify-content: flex-end;
z-index: 11;
}
.chart-view {
width: 100%;
flex: 1;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: nowrap;
padding: 0 10px;
box-sizing: border-box;
.echart-wapper {
flex: 1;
height: 100%;
}
.total-wapper {
width: 30%;
height: 100%;
}
}
.arco-empty {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
}
</style>