index.vue
2.53 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
<!--
* 功能:能源流向
* 作者:曹晓桐
* 日期:2023-11-18
-->
<template>
<div>
<a-card class="general-card" :title="$t('power.energy.flow.title')">
<template #extra>
<time-bar :pick-type="1" @change="timerChange" />
</template>
<a-spin :loading="loading" style="width: 100%;height: auto;" :tip="$t('global.loading')">
<Chart v-if="!loading" :options="chartOption" autoResize height="600px" />
</a-spin>
</a-card>
</div>
</template>
<script setup lang="ts">
import { PowerModuleEunm, getEnergySteamDate } from "@/api/system/home-power";
import useChartOption from "@/hooks/chart-option";
import useLoading from "@/hooks/loading";
import { ref } from "vue";
//加载中
const { loading, setLoading } = useLoading(false);
const chartData = ref<any>([]);
const chartLinks = ref<any>([]);
//图表数据
const { chartOption } = useChartOption((isDark) => {
return {
series: {
type: 'sankey',
data: chartData.value,
links: chartLinks.value,
emphasis: {
focus: 'adjacency'
},
lineStyle: {
color: 'gradient',
curveness: 0.5
}
},
tooltip: {
trigger: "item",
triggerOn: 'mousemove',
axisPointer: { type: "shadow" },
valueFormatter: (value) => {
return value;
}
},
};
});
/**
* 时间改变
*/
const timerChange = async (options: any) => {
await fetchData({ pageValue: PowerModuleEunm.energy_steam_flow, "beginTime": options.timer[0], "endTime": options.timer[1] });
}
/**
* 获取日期数据
* @param param 时间参数
*/
const fetchData = async (param: any) => {
setLoading(true);
try {
let res = await getEnergySteamDate(param);
if (res.code == 200) {
const { data, links } = generateSankeyDataAndLinks(res.data);
chartData.value = data;
chartLinks.value = links
}
} catch (ex) {
console.error("能源流向出错", ex)
} finally {
setLoading(false);
}
}
function generateSankeyDataAndLinks(treeData: any) {
const data: any = [];
const links: any = [];
function traverseTree(node: any, parentName: any) {
if (parentName) {
links.push({
source: parentName,
target: node.key,
value: node.value,
});
}
data.push({
name: node.key,
});
if (node.children) {
node.children.forEach((child: any) => {
traverseTree(child, node.key);
});
}
}
treeData.forEach((node: any) => {
traverseTree(node, null);
});
return { data, links };
}
</script>