index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <el-card class="box-card">
  3. <div class="seachBox">
  4. <div class="conditionOne">
  5. <span>测风塔:</span>
  6. <el-select v-model="cftId" placeholder="请选择" @change="changeCft">
  7. <el-option
  8. v-for="item in startDateAndEndDate"
  9. :key="item.value"
  10. :label="item.label"
  11. :value="item.value">
  12. <span style="float: left;">{{ item.label }}</span>
  13. <span style="float: right; color: #8492a6; font-size: 13px">{{ item.date }}</span>
  14. </el-option>
  15. </el-select>
  16. </div>
  17. <div class="conditionTwo">
  18. <span>时间:</span>
  19. <el-date-picker
  20. v-model="dataTime"
  21. type="daterange"
  22. range-separator="至"
  23. start-placeholder="开始日期"
  24. end-placeholder="结束日期">
  25. </el-date-picker>
  26. </div>
  27. <div class="conditionThree">
  28. <span>层高:</span>
  29. <el-select v-model="height" placeholder="请选择">
  30. <el-option
  31. v-for="item in options"
  32. :key="item.value"
  33. :label="item.label"
  34. :value="item.value">
  35. </el-option>
  36. </el-select>
  37. </div>
  38. <el-button class="seachBtu" type="primary" plain icon="el-icon-search" size="small" @click="getData" :loading="btuLoading">搜索
  39. </el-button>
  40. </div>
  41. <div class="mainBox">
  42. <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
  43. <el-tab-pane label="对比图" name="first">
  44. <div class="chartBox">
  45. 形状参数K: <span class="chartText">{{ K }}</span>&nbsp;,&nbsp;
  46. 参数A: <span class="chartText">{{ A }}</span>&nbsp;m/s,&nbsp;
  47. 平均风速:<span class="chartText">{{ avgWs }}</span> &nbsp;m/s
  48. </div>
  49. <div id="frequeryChart"/>
  50. </el-tab-pane>
  51. </el-tabs>
  52. </div>
  53. </el-card>
  54. </template>
  55. <script>
  56. import {listAllInfo, listEquipmentIdAndDataTime} from "@/api/biz/dataQuery/windTowerStatusInfo";
  57. import {getWeibull} from "@/api/biz/dataQuery/RealTimeDisplay";
  58. import defaultOption from "@/api/biz/dataQuery/defaultOption";
  59. import {startTimeAndEndTime} from "@/api/biz/dataQuery/RealTimeDisplay";
  60. export default {
  61. name: "index",
  62. data() {
  63. return {
  64. btuLoading:true,
  65. frequeryChart: null,
  66. dataTime: [new Date(new Date().toLocaleDateString()).getTime() - 168 * 60 * 60 * 1000, new Date(new Date().toLocaleDateString()).getTime()],
  67. height: "10",
  68. options: [],
  69. allOptions: [],
  70. cftId: '',
  71. startDateAndEndDate: [],
  72. activeName: 'first',
  73. A: '',//威布尔参数A
  74. K: '',//威布尔参数K
  75. avgWs: ''//平均风速
  76. }
  77. },
  78. mounted() {
  79. this.allOptions = defaultOption.allHeightOptions
  80. this.getTimeFrame()
  81. },
  82. destroyed() {
  83. if (!this.frequeryChart) {
  84. return
  85. }
  86. this.frequeryChart.dispose()
  87. this.frequeryChart = null
  88. },
  89. methods: {
  90. /*获取所有的测风塔*/
  91. getlistEquipmentIdAndDataTime() {
  92. listEquipmentIdAndDataTime().then(res => {
  93. this.startDateAndEndDate = res.data
  94. this.cftId = res.data[0].value
  95. this.changeHeight(res.data[0])
  96. this.getDataTime(this.cftId)
  97. this.getData()
  98. })
  99. },
  100. /*切换测风塔找到它对应的层高*/
  101. changeCft() {
  102. let data = this.startDateAndEndDate.find(w => w.value == this.cftId)
  103. this.getDataTime(this.cftId)
  104. this.changeHeight(data)
  105. },
  106. /*切换测风塔时改变层高option*/
  107. changeHeight(data) {
  108. if (data.heights != null) {
  109. var option = []
  110. let str = data.heights.split(',')
  111. this.height = str[0]
  112. for (let i = 0; i < str.length; i++) {
  113. let filter = this.allOptions.find(w => w.value == str[i])
  114. option.push(filter)
  115. }
  116. this.options = option
  117. } else {
  118. this.height = "10"
  119. this.options = this.allOptions
  120. }
  121. },
  122. /*获取默认的时间段*/
  123. getTimeFrame() {
  124. startTimeAndEndTime().then(res => {
  125. this.defaultTimeData = res.data
  126. this.getlistEquipmentIdAndDataTime()
  127. }).catch(err => {
  128. this.getlistEquipmentIdAndDataTime()
  129. this.$message.error('获取时间范围异常')
  130. console.log('获取时间范围异常:' + err)
  131. })
  132. },
  133. /*设置时间范围默认值*/
  134. getDataTime(cftId) {
  135. this.dataTime = [new Date(new Date().toLocaleDateString()).getTime() - 168 * 60 * 60 * 1000, new Date(new Date().toLocaleDateString()).getTime()]
  136. if (cftId != null || cftId != undefined) {
  137. if (this.defaultTimeData.length > 0) {
  138. let filterData = this.defaultTimeData.find(w => w.equipmentId == cftId)
  139. if (JSON.stringify(filterData) != '{}') {
  140. this.dataTime = [filterData.startTime, filterData.endTime]
  141. }
  142. }
  143. }
  144. },
  145. getData() {
  146. this.btuLoading = true
  147. var param = {
  148. startTime: new Date(this.dataTime[0]).getTime(),
  149. endTime: new Date(this.dataTime[1]).getTime() - 1,
  150. equipmentId: this.cftId,
  151. height: this.height
  152. }
  153. //添加loading
  154. if (!this.frequeryChart) {
  155. this.frequeryChart = this.$echarts.init(document.getElementById('frequeryChart'))
  156. }
  157. // 调用showLoading方法
  158. this.frequeryChart.showLoading({
  159. text: 'loading',
  160. color: '#c23531',
  161. textColor: '#000',
  162. maskColor: 'rgba(255, 255, 255, 0.2)',
  163. zlevel: 0,
  164. });
  165. getWeibull(param).then(res => {
  166. if (res.rows.length > 0) {
  167. this.A = res.rows[2].A.toFixed(4)
  168. this.K = res.rows[2].K.toFixed(4)
  169. this.avgWs = res.rows[2].avgWs
  170. let data = res.rows[0]
  171. let wsFreData = res.rows[1]
  172. let parameter = []
  173. let wsFrequery = []
  174. for (let i = 0; i < data.length; i++) {
  175. parameter.push([data[i].ws, data[i].Weibull])
  176. }
  177. for (let j = 0; j < wsFreData.length; j++) {
  178. wsFrequery.push([wsFreData[j].ws, wsFreData[j].cont])
  179. }
  180. this.drawFrequeryChart(parameter, wsFrequery)
  181. this.btuLoading = false
  182. } else {
  183. this.btuLoading = false
  184. this.$message.warning('此时间段测风塔没有数据')
  185. this.frequeryChart.hideLoading();
  186. }
  187. }).catch(err => {
  188. this.frequeryChart.hideLoading();
  189. if (err == 'Error: 98') {
  190. this.$message.warning('此时间段的测风塔风速为同一个值,不可计算威布尔')
  191. } else {
  192. this.$message.error('查询威布尔异常:' + err)
  193. }
  194. console.log('查询威布尔异常:' + err)
  195. })
  196. },
  197. drawFrequeryChart(param, ws) {
  198. if (!this.frequeryChart) {
  199. this.frequeryChart = this.$echarts.init(document.getElementById('frequeryChart'))
  200. }
  201. var option = {
  202. title: {
  203. text: '风速频率与威布尔',
  204. },
  205. legend: {
  206. data: ['风速频率(%)']
  207. },
  208. grid: {
  209. left: '2%',
  210. right: '4%',
  211. containLabel: true
  212. },
  213. tooltip: {
  214. trigger: 'axis',
  215. formatter(params) {
  216. let str = '';
  217. let qj = ''
  218. if (params[0].name == 0) {
  219. qj = '<0.5'
  220. } else {
  221. qj = (params[0].name - 0.5) + " - " + (parseInt(params[0].name) + 0.5)
  222. }
  223. str += `<div>` + qj + `</div>`;
  224. for (let i = 0; i < params.length; i += 1) {
  225. str += `${params[i].marker} <span>${params[i].seriesName}</span> : <span>${params[i].value[1]}</br>`;
  226. }
  227. return str;
  228. },
  229. },
  230. // color: ['#00FF00', '#3b5bde', '#fbdfa2'],
  231. xAxis: {
  232. name: '风速区间 [x-0.5,x+0.5)',
  233. type: 'category',
  234. axisLabel: {
  235. // interval: 1
  236. },
  237. // axisTick: {alignWithLabel: true},
  238. nameLocation: 'center',
  239. nameGap: 25,
  240. data: [0, 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]
  241. },
  242. yAxis: [{
  243. type: 'value',
  244. name: '频率(%)',
  245. min: 0,
  246. // interval: 5,
  247. alignTicks: true,
  248. axisLine: {
  249. show:true
  250. },
  251. axisLabel: {
  252. formatter: '{value}'
  253. },
  254. }, {
  255. show: false,
  256. type: 'value',
  257. alignTicks: true,
  258. axisLine: {
  259. show:true
  260. },
  261. name: '参数',
  262. min: 0,
  263. }],
  264. series: [{
  265. name: '风速频率(%)',
  266. type: 'bar',
  267. // barWidth: '98%',
  268. smooth: false,
  269. symbol: 'none', // 这句就是去掉点的
  270. data: ws
  271. },
  272. {
  273. name: '威布尔曲线值',
  274. type: 'line',
  275. smooth: 0.45,
  276. symbol: 'none', // 这句就是去掉点的
  277. yAxisIndex: 1, //在单个图表实例中存在多个y轴的时候有用
  278. data: param,
  279. }
  280. ]
  281. }
  282. this.frequeryChart.setOption(option, true)
  283. this.frequeryChart.hideLoading();
  284. window.addEventListener('resize', () => {
  285. if (this.frequeryChart) {
  286. this.frequeryChart.resize()
  287. }
  288. })
  289. },
  290. handleClick(tab, event) {
  291. if (this.activeName == 'first') {
  292. this.frequeryChart = null
  293. this.frequeryChart.resize()
  294. }
  295. },
  296. }
  297. }
  298. </script>
  299. <style scoped>
  300. .seachBox {
  301. display: flex;
  302. margin: .5%;
  303. }
  304. .conditionOne, .conditionTwo, .conditionThree, .seachBtu {
  305. display: inline-block;
  306. }
  307. .conditionTwo, .conditionThree, .seachBtu {
  308. margin-left: .5%;
  309. }
  310. #frequeryChart {
  311. width: 95%;
  312. height: calc(71vh);
  313. }
  314. .chartBox {
  315. font-weight: bold;
  316. margin-left: .5%;
  317. margin-bottom: .3%;
  318. }
  319. .chartText {
  320. font-weight: bold;
  321. color: #1ab394;
  322. }
  323. </style>