index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div>
  3. <el-card class="box-card">
  4. <div class="seachBox">
  5. <div class="conditionOne">
  6. <span>测风塔:</span>
  7. <el-select v-model="cftId" filterable placeholder="请选择">
  8. <el-option
  9. v-for="item in startDateAndEndDate"
  10. :key="item.value"
  11. :label="item.label"
  12. :value="item.value">
  13. <span style="float: left;">{{ item.label }}</span>
  14. <span style="float: right; color: #8492a6; font-size: 13px">{{ item.date }}</span>
  15. </el-option>
  16. </el-select>
  17. </div>
  18. <div class="conditionTwo">
  19. <span>时间:</span>
  20. <el-date-picker
  21. v-model="dataTime"
  22. type="monthrange"
  23. range-separator="至"
  24. start-placeholder="开始日期"
  25. end-placeholder="结束日期"
  26. >
  27. </el-date-picker>
  28. </div>
  29. <div class="conditionTwo">
  30. <span>时间维度:</span>
  31. <el-select v-model="uid" placeholder="请选择">
  32. <el-option
  33. v-for="item in uidOption"
  34. :key="item.value"
  35. :label="item.label"
  36. :value="item.value">
  37. </el-option>
  38. </el-select>
  39. </div>
  40. <el-button class="seachBtu" type="primary" plain icon="el-icon-search" size="small" @click="getListAirDensity" :loading="btuLoading">
  41. 搜索
  42. </el-button>
  43. </div>
  44. <div class="mainBox">
  45. <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
  46. <el-tab-pane label="空气密度曲线图" name="first">
  47. <div class="avgTextDiv">
  48. <div v-html="avgAirText"/>
  49. </div>
  50. <div id="airChart"/>
  51. </el-tab-pane>
  52. </el-tabs>
  53. </div>
  54. </el-card>
  55. </div>
  56. </template>
  57. <script>
  58. import {listAllInfo, listEquipmentIdAndDataTime} from "@/api/biz/dataQuery/windTowerStatusInfo";
  59. import {listAirDensity} from "@/api/biz/dataQuery/statistics";
  60. import {startTimeAndEndTime} from "@/api/biz/dataQuery/RealTimeDisplay";
  61. export default {
  62. name: "index",
  63. data() {
  64. return {
  65. btuLoading:true,
  66. dataTime: [new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1).getTime(), new Date(new Date().getFullYear(), new Date().getMonth(), 1)],
  67. cftId: '',
  68. uid: '1',
  69. uidOption: [{value: '1', label: '月'}, {value: '2', label: '年'}],
  70. activeName: 'first',
  71. defaultTimeData: [],//默认时间范围集合
  72. avgAirText: '',//空气密度平均值
  73. startDateAndEndDate: [],
  74. }
  75. },
  76. mounted() {
  77. this.getlistEquipmentIdAndDataTime()
  78. this.getTimeFrame()
  79. },
  80. destroyed() {
  81. if (!this.turChart) {
  82. return
  83. }
  84. this.turChart.dispose()
  85. this.turChart = null
  86. },
  87. methods: {
  88. /*获取所有的测风塔*/
  89. getlistEquipmentIdAndDataTime() {
  90. listEquipmentIdAndDataTime().then(res => {
  91. this.startDateAndEndDate = res.data
  92. this.cftId = res.data[0].value
  93. this.getDataTime(this.cftId)
  94. this.getListAirDensity()
  95. })
  96. },
  97. /*获取默认的时间段*/
  98. getTimeFrame() {
  99. startTimeAndEndTime().then(res => {
  100. this.defaultTimeData = res.data
  101. this.getlistEquipmentIdAndDataTime()
  102. }).catch(err => {
  103. this.getlistEquipmentIdAndDataTime()
  104. this.$message.error('获取时间范围异常')
  105. console.log('获取时间范围异常:' + err)
  106. })
  107. },
  108. /*设置时间范围默认值*/
  109. getDataTime(cftId) {
  110. this.dataTime = [new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1).getTime(), new Date(new Date().getFullYear(), new Date().getMonth(), 1)]
  111. if (cftId != null || cftId != undefined) {
  112. if (this.defaultTimeData.length > 0) {
  113. let filterData = this.defaultTimeData.find(w => w.equipmentId == cftId)
  114. if (JSON.stringify(filterData) != '{}') {
  115. this.dataTime = [new Date(new Date(filterData.endTime).getFullYear(), new Date(filterData.endTime).getMonth() - 1, 1).getTime(), new Date(new Date(filterData.endTime).getFullYear(), new Date(filterData.endTime).getMonth() + 1, 1)] // this.dataTime = [filterData.startTime, filterData.endTime]
  116. }
  117. }
  118. }
  119. },
  120. async getListAirDensity() {
  121. this.btuLoading=true
  122. const param = {
  123. startTime: new Date(this.dataTime[0]).getTime(),
  124. endTime: new Date(this.dataTime[1]).getTime(),
  125. equipmentId: this.cftId,
  126. uid: this.uid
  127. }
  128. if (!this.airChart) {
  129. this.airChart = this.$echarts.init(document.getElementById('airChart'))
  130. }
  131. // 调用showLoading方法
  132. this.airChart.showLoading({
  133. text: 'loading',
  134. color: '#c23531',
  135. textColor: '#000',
  136. maskColor: 'rgba(255, 255, 255, 0.2)',
  137. zlevel: 0,
  138. });
  139. await listAirDensity(param).then(async res => {
  140. let data = res.rows[1]
  141. this.avgAirText = ""
  142. if (data.ave != null) {
  143. this.avgAirText += ' <span style="color: #1c84c6;font-weight: bold">平均值:</span>' + '<span style="color: #1ab394">' + data.ave + '</span>' + ','
  144. }
  145. if (this.avgAirText != '') {
  146. this.avgAirText = this.avgAirText.slice(0, this.avgAirText.length - 1)
  147. }
  148. this.airData = res.rows[0]
  149. this.drawAirDensityInChart(this.airData)
  150. this.btuLoading = false
  151. }).catch(err => {
  152. this.airChart.hideLoading();
  153. this.btuLoading = false
  154. this.$message.error('获取空气密度数据异常')
  155. console.log('获取空气密度数据异常:' + err)
  156. })
  157. },
  158. //曲线图
  159. drawAirDensityInChart(data) {
  160. this.airChart = this.$echarts.init(document.getElementById('airChart'))
  161. /*拼接曲线图的serise*/
  162. let serise = []
  163. let legend = []
  164. let seriseData = []
  165. for (let i = 0; i < data.length; i++) {
  166. seriseData.push([data[i].time, data[i].air])
  167. legend.push(data[i].height + 'm')
  168. }
  169. serise.push({
  170. name: '空气密度',
  171. type: 'line',
  172. smooth: false,
  173. symbol: 'none', // 这句就是去掉点的
  174. data: seriseData
  175. })
  176. var option = {
  177. title: {
  178. text: '空气密度统计折线图',
  179. },
  180. legend: {
  181. data: legend
  182. },
  183. grid: {
  184. left: '2%',
  185. right: '3%',
  186. // bottom: '8%',
  187. containLabel: true
  188. },
  189. tooltip: {
  190. trigger: 'axis',
  191. },
  192. // color: ['#1a9f00', '#2f4554', '#61a0a8','#d48265'],
  193. xAxis: {
  194. name: '时间',
  195. type: 'category',
  196. axisLine: {
  197. lineStyle: {
  198. color: '#666b8f',
  199. width: 4// 这里是为了突出显示加上的
  200. }
  201. },
  202. },
  203. dataZoom: [
  204. {
  205. startValue: ''
  206. },
  207. {
  208. type: 'inside'
  209. }
  210. ],
  211. yAxis: {
  212. type: 'value',
  213. name: '空气密度',
  214. min: 0,
  215. // interval: 5,
  216. axisLabel: {
  217. formatter: '{value}'
  218. },
  219. axisLine: {
  220. show: true,
  221. lineStyle: {
  222. color: '#666b8f',
  223. width: 4// 这里是为了突出显示加上的
  224. }
  225. },
  226. splitLine: {
  227. show: true,
  228. lineStyle: {
  229. color: ['#315070'],
  230. width: 2,
  231. type: 'dotted'
  232. }
  233. }
  234. },
  235. series: serise
  236. }
  237. this.airChart.setOption(option, true)
  238. this.airChart.hideLoading();
  239. window.addEventListener('resize', () => {
  240. if (this.airChart) {
  241. this.airChart.resize()
  242. }
  243. })
  244. },
  245. handleClick() {
  246. if (this.activeName == 'first') {
  247. this.airChart = null
  248. this.$nextTick(() => {
  249. this.drawAirDensityInChart(this.airData)
  250. this.airChart.resize()
  251. })
  252. }
  253. }
  254. }
  255. }
  256. </script>
  257. <style scoped>
  258. .box-card {
  259. height: calc(90vh);
  260. }
  261. .seachBox {
  262. display: flex;
  263. margin: .5%;
  264. }
  265. .conditionOne, .conditionTwo, .conditionThree, .seachBtu {
  266. display: inline-block;
  267. }
  268. .conditionTwo, .conditionThree, .seachBtu {
  269. margin-left: .5%;
  270. }
  271. #airChart {
  272. width: 100%;
  273. height: calc(72vh);
  274. }
  275. </style>