index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="system-dic-container">
  3. <el-card shadow="hover">
  4. <div class="system-user-search mb15">
  5. <el-form :model="state.param" ref="queryRef" :inline="true" label-width="120px">
  6. <!-- <el-form-item label="环路名称" prop="plotId">
  7. <el-select v-model="searchParams.plotId" placeholder="选择环路名称" filterable clearable size="default">
  8. <el-option
  9. v-for="item in []"
  10. :key="item.id"
  11. :label="item.name"
  12. :value="item.id">
  13. </el-option>
  14. </el-select>
  15. </el-form-item> -->
  16. <el-form-item label="所属换热站" prop="stationId">
  17. <el-tree-select
  18. v-model="state.param.stationId"
  19. :data="state.heatList"
  20. :props="{
  21. label: 'name',
  22. children: 'children'
  23. }"
  24. node-key="id"
  25. :clearable="true"
  26. check-strictly
  27. size="default"
  28. style="width: 100%;"
  29. placeholder="请选择"
  30. :render-after-expand="true"
  31. />
  32. </el-form-item>
  33. <el-form-item label="负责人" prop="principal">
  34. <el-select v-model="state.param.principal" placeholder="选择负责人" filterable clearable size="default">
  35. <el-option
  36. v-for="item in []"
  37. :key="item.id"
  38. :label="item.name"
  39. :value="item.id">
  40. </el-option>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="时间间隔(秒)" prop="interval">
  44. <el-input-number v-model="state.param.interval"></el-input-number>
  45. </el-form-item>
  46. <el-form-item label="流量限值" prop="flow">
  47. <el-input-number v-model="state.param.flow"></el-input-number>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button size="default" type="primary" class="ml10" @click="initPage">
  51. <el-icon>
  52. <ele-Search />
  53. </el-icon>
  54. 查询
  55. </el-button>
  56. <!-- <el-button size="default" @click="resetQuery(queryRef)">
  57. <el-icon>
  58. <ele-Refresh />
  59. </el-icon>
  60. 重置
  61. </el-button> -->
  62. </el-form-item>
  63. </el-form>
  64. </div>
  65. <div style="height: 300px" ref="barChartRef"></div>
  66. <div style="height: 300px" ref="lineChartRef"></div>
  67. </el-card>
  68. </div>
  69. </template>
  70. <script lang="ts" setup>
  71. import { toRefs, reactive, onMounted, ref, watch, nextTick } from 'vue';
  72. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  73. import * as echarts from 'echarts';
  74. import { useStore } from '/@/store/index';
  75. import api from '/@/api/energyAnalysis';
  76. import heatApi from '/@/api/heatStation';
  77. let global: any = {
  78. barChart: null,
  79. lineChart: null,
  80. dispose: [null, '', undefined],
  81. };
  82. const queryRef = ref();
  83. const barChartRef = ref();
  84. const lineChartRef = ref();
  85. const store = useStore();
  86. const state = reactive({
  87. myCharts: [],
  88. charts: {
  89. theme: '',
  90. bgColor: '',
  91. color: '#303133',
  92. },
  93. param: {
  94. stationId: '',
  95. principal: '',
  96. interval: '',
  97. flow: ''
  98. },
  99. heatList: []
  100. });
  101. const queryTree = () => {
  102. heatApi.heatStation.getList({
  103. name: '',
  104. code: '',
  105. status: -1
  106. })
  107. .then((res: any) => {
  108. state.heatList = res || [];
  109. });
  110. };
  111. const queryLineChart = () => {
  112. api.getEnergyWaterLossLineChart(state.param).then((res: any) => {
  113. console.log(res);
  114. });
  115. };
  116. const queryChart = () => {
  117. api.getEnergyWaterLossList(state.param).then((res: any) => {
  118. console.log(res);
  119. });
  120. };
  121. // 页面加载时
  122. onMounted(() => {
  123. queryTree()
  124. // queryLineChart()
  125. });
  126. /** 重置按钮操作 */
  127. const resetQuery = (formEl: FormInstance | undefined) => {
  128. if (!formEl) return;
  129. formEl.resetFields();
  130. // queryList();
  131. };
  132. const initPage = () => {
  133. if (!state.param.stationId) {
  134. ElMessage.warning('请选择换热站')
  135. return
  136. }
  137. queryChart()
  138. // queryLineChart()
  139. }
  140. // 初始化图表
  141. const initBarChart = () => {
  142. if (!global.dispose.some((b: any) => b === global.barChart)) global.barChart.dispose();
  143. global.barChart = <any>echarts.init(barChartRef.value, state.charts.theme);
  144. const option = {
  145. tooltip: {
  146. trigger: 'axis',
  147. axisPointer: {
  148. type: 'shadow'
  149. }
  150. },
  151. legend: {},
  152. grid: {
  153. left: '3%',
  154. right: '4%',
  155. bottom: '3%',
  156. containLabel: true
  157. },
  158. xAxis: [
  159. {
  160. type: 'category',
  161. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  162. }
  163. ],
  164. yAxis: [
  165. {
  166. type: 'value'
  167. }
  168. ],
  169. series: [
  170. {
  171. name: '供水流量',
  172. type: 'bar',
  173. emphasis: {
  174. focus: 'series'
  175. },
  176. data: [320, 332, 301, 334, 390, 330, 320]
  177. },
  178. {
  179. name: '回水流量',
  180. type: 'bar',
  181. stack: 'Ad',
  182. emphasis: {
  183. focus: 'series'
  184. },
  185. data: [120, 132, 101, 134, 90, 230, 210]
  186. }
  187. ]
  188. };
  189. (<any>global.barChart).setOption(option);
  190. (<any>state.myCharts).push(global.barChart);
  191. }
  192. // 初始化图标
  193. const initLineChart = () => {
  194. if (!global.dispose.some((b: any) => b === global.lineChart)) global.lineChart.dispose();
  195. global.lineChart = <any>echarts.init(lineChartRef.value, state.charts.theme);
  196. const option = {
  197. backgroundColor: state.charts.bgColor,
  198. grid: { top: 70, right: 20, bottom: 30, left: 30 },
  199. tooltip: { trigger: 'axis' },
  200. legend: { data: ['一网回水压力', '一网供水压力'] },
  201. xAxis: {
  202. data: ['环路1', '环路2', '环路3', '环路4', '环路5'],
  203. },
  204. yAxis: [
  205. {
  206. type: 'value',
  207. name: '条数',
  208. splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } },
  209. },
  210. ],
  211. series: [
  212. {
  213. name: '一网回水压力',
  214. type: 'line',
  215. symbolSize: 6,
  216. symbol: 'circle',
  217. smooth: true,
  218. data: [41.1, 30.4, 65.1, 53.3, 53.3],
  219. lineStyle: { color: '#fe9a8b' },
  220. itemStyle: { color: '#fe9a8b', borderColor: '#fe9a8b' }
  221. },
  222. {
  223. name: '一网供水压力',
  224. type: 'line',
  225. symbolSize: 6,
  226. symbol: 'circle',
  227. smooth: true,
  228. data: [24.1, 7.2, 15.5, 42.4, 42.4],
  229. lineStyle: { color: '#9E87FF' },
  230. itemStyle: { color: '#9E87FF', borderColor: '#9E87FF' }
  231. }
  232. ]
  233. };
  234. (<any>global.lineChart).setOption(option);
  235. (<any>state.myCharts).push(global.lineChart);
  236. }
  237. // 批量设置 echarts resize
  238. const initEchartsResizeFun = () => {
  239. nextTick(() => {
  240. for (let i = 0; i < state.myCharts.length; i++) {
  241. setTimeout(() => {
  242. (<any>state.myCharts[i]).resize();
  243. }, i * 1000);
  244. }
  245. });
  246. };
  247. // 批量设置 echarts resize
  248. const initEchartsResize = () => {
  249. window.addEventListener('resize', initEchartsResizeFun);
  250. };
  251. // 页面加载时
  252. onMounted(() => {
  253. initEchartsResize();
  254. });
  255. // 监听 vuex 中是否开启深色主题
  256. watch(
  257. () => store.state.themeConfig.themeConfig.isIsDark,
  258. (isIsDark) => {
  259. nextTick(() => {
  260. state.charts.theme = isIsDark ? 'transparent' : '';
  261. state.charts.bgColor = isIsDark ? 'transparent' : '';
  262. state.charts.color = isIsDark ? '#dadada' : '#303133';
  263. // setTimeout(() => {
  264. // initBarChart();
  265. // initLineChart();
  266. // }, 500)
  267. });
  268. },
  269. {
  270. deep: true,
  271. immediate: true,
  272. }
  273. );
  274. </script>