Detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <view class="content">
  3. <!-- <image class="logo" src="/static/logo.png"></image> -->
  4. <!--导航栏-->
  5. <view>
  6. <cu-custom bgColor="bg-blacks" :isBack="true">
  7. <block slot="backText">
  8. <view style="height: 80rpx;line-height: 80rpx;">返回</view>
  9. </block>
  10. <block slot="content">{{address}}</block>
  11. </cu-custom>
  12. </view>
  13. <!-- 卡片 -->
  14. <view class="cu-card case" :class="isCard?'no-card':''">
  15. <view class="cardContenter">
  16. <view class="timeAndTitle">
  17. <view class="time" :style="{'font-size':timeFontSize}">
  18. {{startDate}}~{{endDate}}
  19. </view>
  20. <view class="title" :style="{'font-size':titleFontSize}">
  21. 温度
  22. </view>
  23. </view>
  24. <!-- uCharts柱状图 -->
  25. <scroll-view scroll-x="true" class="scrollUcharts">
  26. <view class="qiun-charts-column" >
  27. <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts-column"></canvas>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. <!-- 卡片 -->
  33. <view class="cu-card case" :class="isCard?'no-card':''">
  34. <view class="cardContenter">
  35. <view class="timeAndTitle">
  36. <view class="time" :style="{'font-size':timeFontSize}">
  37. {{startDate}}~{{endDate}}
  38. </view>
  39. <view class="title" :style="{'font-size':titleFontSize}">
  40. 风速/风向
  41. </view>
  42. </view>
  43. <!-- uCharts折线图 -->
  44. <scroll-view scroll-x="true" class="scrollUcharts">
  45. <view class="hours">
  46. <view class="hour" :style="{'font-size':hourFontSize}" v-for="(item,index) in hours" :key="index">
  47. {{item}}时
  48. </view>
  49. </view>
  50. <view class="qiun-charts-lineA">
  51. <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts-lineA"></canvas>
  52. </view>
  53. </scroll-view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import uCharts from '../../tools/u-charts/u-charts.js';
  60. export default {
  61. data() {
  62. return {
  63. address: '',
  64. option: '',
  65. isCard: false,
  66. cWidthLineA:'',
  67. cHeightLineA:'',
  68. pixelRatioLineA:1,
  69. cWidthColumn:'',
  70. cHeightColumn:'',
  71. pixelRatioColumn:1,
  72. weatherProphetData_17Hour:[
  73. {
  74. 'data': '2020/02/25 00:00:00',
  75. 'temperature': '15',
  76. 'realfeel': '8',
  77. 'winddirection': '东北',
  78. 'speed': '3',
  79. },
  80. {
  81. 'data': '2020/02/25 01:00:00',
  82. 'temperature': '15',
  83. 'realfeel': '10',
  84. 'winddirection': '东北',
  85. 'speed': '4',
  86. },
  87. {
  88. 'data': '2020/02/25 02:00:00',
  89. 'temperature': '15',
  90. 'realfeel': '15',
  91. 'winddirection': '东北',
  92. 'speed': '5',
  93. },
  94. {
  95. 'data': '2020/02/25 03:00:00',
  96. 'temperature': '15',
  97. 'realfeel': '9',
  98. 'winddirection': '东北',
  99. 'speed': '4',
  100. },
  101. {
  102. 'data': '2020/02/25 04:00:00',
  103. 'temperature': '15',
  104. 'realfeel': '15',
  105. 'winddirection': '东北',
  106. 'speed': '3',
  107. },
  108. {
  109. 'data': '2020/02/25 05:00:00',
  110. 'temperature': '15',
  111. 'realfeel': '15',
  112. 'winddirection': '东北',
  113. 'speed': '4',
  114. },
  115. {
  116. 'data': '2020/02/25 06:00:00',
  117. 'temperature': '15',
  118. 'realfeel': '13',
  119. 'winddirection': '东北',
  120. 'speed': '5',
  121. },
  122. {
  123. 'data': '2020/02/25 07:00:00',
  124. 'temperature': '15',
  125. 'realfeel': '15',
  126. 'winddirection': '东北',
  127. 'speed': '4',
  128. },
  129. {
  130. 'data': '2020/02/25 08:00:00',
  131. 'temperature': '15',
  132. 'realfeel': '15',
  133. 'winddirection': '东北',
  134. 'speed': '3',
  135. },
  136. {
  137. 'data': '2020/02/25 09:00:00',
  138. 'temperature': '15',
  139. 'realfeel': '15',
  140. 'winddirection': '东北',
  141. 'speed': '4',
  142. },
  143. {
  144. 'data': '2020/02/25 10:00:00',
  145. 'temperature': '15',
  146. 'realfeel': '15',
  147. 'winddirection': '东北',
  148. 'speed': '5',
  149. },
  150. {
  151. 'data': '2020/02/25 11:00:00',
  152. 'temperature': '15',
  153. 'realfeel': '15',
  154. 'winddirection': '东北',
  155. 'speed': '4',
  156. },
  157. {
  158. 'data': '2020/02/25 12:00:00',
  159. 'temperature': '15',
  160. 'realfeel': '15',
  161. 'winddirection': '东北',
  162. 'speed': '3',
  163. },
  164. {
  165. 'data': '2020/02/25 13:00:00',
  166. 'temperature': '15',
  167. 'realfeel': '15',
  168. 'winddirection': '东北',
  169. 'speed': '4',
  170. },
  171. {
  172. 'data': '2020/02/25 14:00:00',
  173. 'temperature': '15',
  174. 'realfeel': '15',
  175. 'winddirection': '东北',
  176. 'speed': '5',
  177. },
  178. {
  179. 'data': '2020/02/25 15:00:00',
  180. 'temperature': '15',
  181. 'realfeel': '15',
  182. 'winddirection': '西南偏西',
  183. 'speed': '4',
  184. },
  185. {
  186. 'data': '2020/02/25 16:00:00',
  187. 'temperature': '15',
  188. 'realfeel': '15',
  189. 'winddirection': '西南偏西',
  190. 'speed': '3',
  191. }
  192. ],
  193. startDate:"",
  194. endDate:"",
  195. hours:[],
  196. weatherProphetDataAll_17Hour:[],
  197. windPowerStationId:"MHS_FDC",
  198. windowWidth:"",
  199. windowHeight:"",
  200. timeFontSize:"",
  201. titleFontSize:"",
  202. hourFontSize:"",
  203. xAxisFontSize:"",
  204. seriesTextSize:""
  205. };
  206. },
  207. created: function() {
  208. //this.pushWindPowerStationNameToSessionStorage("麻黄山");
  209. this.address = this.dataprocessing.getWindPowerStationName();
  210. this.FDC=this.dataprocessing.getWindPowerStationId();
  211. this.windPowerStationId =this.dataprocessing.getWindPowerStationId();
  212. this.getWeatherData();
  213. this.windowWidth=uni.getSystemInfoSync().windowWidth;
  214. this.windowHeight=uni.getSystemInfoSync().windowHeight;
  215. if(this.windowWidth>=768){
  216. this.timeFontSize="22px";
  217. this.titleFontSize="22px";
  218. this.hourFontSize="22px";
  219. this.xAxisFontSize=18;
  220. this.seriesTextSize=18;
  221. }else{
  222. this.timeFontSize="15px";
  223. this.titleFontSize="15px";
  224. this.hourFontSize="15px";
  225. this.xAxisFontSize=12;
  226. this.seriesTextSize=12;
  227. }
  228. },
  229. onShow() {
  230. this.address = this.getWindPowerStationNameToSessionStorage();
  231. this.windPowerStationId=uni.getStorageSync('windPowerStationId');
  232. this.getWeatherData();
  233. },
  234. computed: {
  235. backStageIp: function() {
  236. return this.$store.state.wholeSituationBackStageIp;
  237. },
  238. backStagePort: function() {
  239. return this.$store.state.wholeSituationBackStagePort;
  240. },
  241. windpowerstationNameToId: function() {
  242. return this.$store.state.windpowerstationNameToId;
  243. }
  244. },
  245. methods:{
  246. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  247. uni.setStorageSync('windpowerstationName',windpowerstationName);
  248. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  249. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  250. //this.common.goback('/pages/index/Index');
  251. },
  252. getWindPowerStationNameToSessionStorage() {
  253. uni.getStorageSync('windpowerstationName');
  254. return uni.getStorageSync('windpowerstationName');
  255. },
  256. getWeatherData: function() {
  257. let _this = this;
  258. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  259. this.socketTask = uni.connectSocket({
  260. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  261. url: 'ws://' + this.backStageIp + ':' + this.backStagePort + '/websocket/pageNumber_3/functionNumber_2',
  262. success(data) {
  263. console.log("websocket连接成功");
  264. },
  265. });
  266. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  267. this.socketTask.onOpen((res) => {
  268. console.log("WebSocket连接正常打开中...!");
  269. this.is_open_socket = true;
  270. // 注:只有连接正常打开中 ,才能正常收到消息
  271. this.socketTask.onMessage((res) => {
  272. //console.log("收到服务器内容:" + res.data);
  273. //debugger
  274. _this.weatherProphetDataAll_17Hour =res.data;
  275. _this.weatherProphetDataAll_17Hour=JSON.parse(res.data);
  276. _this.weatherProphetData_17Hour = [];
  277. //判断风场id 40天
  278. for(let i = 0; i < _this.weatherProphetDataAll_17Hour.length; i++) {
  279. if(_this.weatherProphetDataAll_17Hour[i].windpowerstationid == _this.windPowerStationId) {
  280. _this.weatherProphetData_17Hour.push(_this.weatherProphetDataAll_17Hour[i]);
  281. }
  282. }
  283. //console.log(_this.weatherProphetData_17Hour);
  284. let startMonth = new Date(_this.weatherProphetData_17Hour[0].date).getMonth() + 1;
  285. let startDay = new Date(_this.weatherProphetData_17Hour[0].date).getDate() ;
  286. let startHour = new Date(_this.weatherProphetData_17Hour[0].date).getHours() ;
  287. _this.startDate = startMonth + "月" + startDay+"日" + startHour+"时";
  288. let endMonth = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getMonth() + 1;
  289. let endDay = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getDate() ;
  290. let endHour = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getHours() ;
  291. _this.endDate = endMonth + "月" + endDay+"日" + endHour+"时";
  292. _this.hours=[];
  293. for(let i=0;i<_this.weatherProphetData_17Hour.length;i++){
  294. _this.hours.push(new Date(_this.weatherProphetData_17Hour[i].date).getHours());
  295. }
  296. _this.getServerData();
  297. });
  298. })
  299. // 这里仅是事件监听【如果socket关闭了会执行】
  300. this.socketTask.onClose(() => {
  301. console.log("已经被关闭了")
  302. })
  303. // let _this = this;
  304. // if(typeof(WebSocket) == "undefined") {
  305. // console.log("您的浏览器不支持WebSocket");
  306. // } else {
  307. // console.log("您的浏览器支持WebSocket");
  308. // //实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
  309. // this.socket = new WebSocket("ws://49.4.78.143:8081/websocket/pageNumber_3/functionNumber_2");
  310. // this.openSocket();
  311. // //获得消息事件
  312. // this.socket.onmessage = function onMessage(message) {
  313. // _this.weatherProphetDataAll_17Hour = eval(message.data);
  314. // _this.weatherProphetData_17Hour = [];
  315. // //判断风场id
  316. // for(let i = 0; i < _this.weatherProphetDataAll_17Hour.length; i++) {
  317. // if(_this.weatherProphetDataAll_17Hour[i].windpowerstationid == _this.windPowerStationId) {
  318. // _this.weatherProphetData_17Hour.push(_this.weatherProphetDataAll_17Hour[i]);
  319. // }
  320. // }
  321. // console.log(_this.weatherProphetData_17Hour);
  322. // let startMonth = new Date(_this.weatherProphetData_17Hour[0].date).getMonth() + 1;
  323. // let startDay = new Date(_this.weatherProphetData_17Hour[0].date).getDate() ;
  324. // let startHour = new Date(_this.weatherProphetData_17Hour[0].date).getHours() ;
  325. // _this.startDate = startMonth + "月" + startDay+"日" + startHour+"时";
  326. // let endMonth = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getMonth() + 1;
  327. // let endDay = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getDate() ;
  328. // let endHour = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getHours() ;
  329. // _this.endDate = endMonth + "月" + endDay+"日" + endHour+"时";
  330. // _this.hours=[];
  331. // for(let i=0;i<_this.weatherProphetData_17Hour.length;i++){
  332. // _this.hours.push(new Date(_this.weatherProphetData_17Hour[i].date).getHours());
  333. // }
  334. // _this.getServerData();
  335. // }
  336. // }
  337. },
  338. getServerData(){
  339. //柱状图
  340. let Column={
  341. "categories": ["2012", "2013", "2014", "2015", "2016", "2017"],
  342. "series": [{
  343. "name": "成交量1",
  344. "data": [15, {"value": 20,"color": "#f04864"}, 45, 37, 43, 34],
  345. "color": '#f04864',
  346. "textColor":"#FFFFFF",
  347. "textSize":this.seriesTextSize,
  348. format:(val)=>{return val+'℃ㅤ'}
  349. }
  350. /*, {
  351. "name": "成交量2",
  352. "data": [30, {"value": 40,"color": "#facc14"}, 25, 14, 34, 18],
  353. "color": '#facc14',
  354. "textColor":"#FFFFFF",
  355. "textSize":this.seriesTextSize,
  356. format:(val)=>{return ' '+val+'℃'}
  357. }*/
  358. ]
  359. };
  360. Column.categories=[];
  361. Column.series[0].data=[];
  362. //Column.series[1].data=[];
  363. for(let i=0;i<this.weatherProphetData_17Hour.length;i++){
  364. let xAxisHours = new Date(this.weatherProphetData_17Hour[i].date).getHours();
  365. Column.categories.push(xAxisHours+"时");
  366. Column.series[0].data.push(this.weatherProphetData_17Hour[i].temperature);
  367. // Column.series[1].data.push(this.weatherProphetData_17Hour[i].realfeel);
  368. }
  369. this.showColumn("canvasColumn",Column);
  370. //折线图
  371. let LineA={
  372. categories: ['2012', '2013', '2014', '2015', '2016', '2017'],
  373. series: [{
  374. name: '风速',
  375. data: [35, 20, 25, 37, 4, 20],
  376. color: '#FFFFFF',
  377. textColor:"#FFFFFF",
  378. textSize:this.seriesTextSize,
  379. format:(val)=>{return val+'km/h'}
  380. }]
  381. };
  382. LineA.categories=[];
  383. LineA.series[0].data=[];
  384. for(let i=0;i<this.weatherProphetData_17Hour.length;i++){
  385. LineA.categories.push(this.weatherProphetData_17Hour[i].winddirection );
  386. LineA.series[0].data.push(this.weatherProphetData_17Hour[i].speed);
  387. }
  388. this.showLineA("canvasLineA",LineA);
  389. },
  390. showColumn(canvasId,chartData){
  391. var _self = this;
  392. var canvaColumn=new uCharts({
  393. $this:_self,
  394. canvasId: canvasId,
  395. type: 'column',
  396. legend:{show:false},
  397. fontSize:11,
  398. background:'#FFFFFF',
  399. pixelRatio:_self.pixelRatioColumn,
  400. animation: true,
  401. categories: chartData.categories,
  402. series: chartData.series,
  403. xAxis: {
  404. disableGrid:true,
  405. fontColor:"#FFFFFF",
  406. fontSize:_self.xAxisFontSize,
  407. },
  408. yAxis: {
  409. disabled:true,
  410. disableGrid:true,
  411. min:-40,
  412. max:50,
  413. },
  414. dataLabel: true,
  415. width: _self.cWidthColumn*_self.pixelRatioColumn,
  416. height: _self.cHeightColumn*_self.pixelRatioColumn,
  417. padding:[0,10,15,10],//画布填充边距,顺序为上右下左,同css,但必须4位
  418. extra: {
  419. column: {
  420. type:'group',
  421. width: '10'
  422. }
  423. }
  424. });
  425. },
  426. showLineA(canvasId,chartData){
  427. var _self = this;
  428. var canvaLineA=new uCharts({
  429. $this:_self,
  430. canvasId: canvasId,
  431. type: 'line',
  432. fontSize:11,
  433. legend:{show:false},//图例
  434. dataLabel:true,//数据点标签
  435. dataPointShape:true,
  436. background:'#FFFFFF',
  437. pixelRatio:_self.pixelRatioLineA,
  438. categories: chartData.categories,
  439. series: chartData.series,
  440. animation: true,
  441. xAxis: {
  442. type:'grid',
  443. gridColor:'#CCCCCC',
  444. gridType:'dash',
  445. dashLength:8,
  446. disableGrid:true,//网格线
  447. axisLine:true,//x轴轴线
  448. fontColor:"#FFFFFF",
  449. fontSize:_self.xAxisFontSize
  450. },
  451. yAxis: {
  452. data:{
  453. disabled:false//y轴轴线
  454. },
  455. disableGrid:true,//网格线
  456. gridType:'dash',
  457. gridColor:'#CCCCCC',
  458. dashLength:8,
  459. splitNumber:5,
  460. min:-40,
  461. max:40,
  462. format:(val)=>{return val.toFixed(0)+'元'}
  463. },
  464. width: _self.cWidthLineA*_self.pixelRatioLineA,
  465. height: _self.cHeightLineA*_self.pixelRatioLineA,
  466. padding:[0,0,15,-25],//画布填充边距,顺序为上右下左,同css,但必须4位
  467. extra: {
  468. line:{
  469. type: 'curve'//曲线
  470. }
  471. }
  472. });
  473. },
  474. closeSocket: function() {
  475. this.socket.onclose;
  476. },
  477. openSocket: function() {
  478. this.socket.onOpen;
  479. }
  480. },
  481. onLoad(option) {
  482. this.cWidthColumn=uni.upx2px(840);
  483. this.cHeightColumn=uni.upx2px(350);
  484. this.cWidthLineA=uni.upx2px(840);
  485. this.cHeightLineA=uni.upx2px(300);
  486. //this.getServerData();
  487. this.address = this.getWindPowerStationNameToSessionStorage();;
  488. }
  489. }
  490. </script>
  491. <style>
  492. page {
  493. background-color: #1f1f1f;
  494. font-family: '方正兰亭细黑_GBK';
  495. overflow-x: hidden;
  496. }
  497. .cu-card{
  498. width: 90%;
  499. height: 450upx;
  500. margin: 15px auto;
  501. }
  502. .cardContenter{
  503. border-radius: 20px;
  504. /* margin: 20px auto; */
  505. width: 100%;
  506. height: 450upx;
  507. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024F93), color-stop(1.5, #cccccc), to(#437193));
  508. background: rgba(0, 0, 0, 0.1);
  509. }
  510. .timeAndTitle{
  511. width: 90%;
  512. margin-left: 20px;
  513. height: 100upx;
  514. font-family: "microsoft yahei";
  515. font-size: 15px;
  516. color: white;
  517. }
  518. .time{
  519. float: left;
  520. height: 100upx;
  521. line-height: 100upx;
  522. }
  523. .title{
  524. float: right;
  525. text-align: right;
  526. height: 100upx;
  527. line-height: 100upx;
  528. }
  529. .hours{
  530. width: 800upx;
  531. height: 50upx;
  532. margin-left: -4%;
  533. color: white;
  534. }
  535. .hour{
  536. width: 50upx;
  537. float: left;
  538. margin-left: 13.5%;
  539. }
  540. .scrollUcharts{
  541. white-space: nowrap;
  542. }
  543. .qiun-charts-lineA {
  544. width: 840upx;
  545. height: 300upx;
  546. }
  547. .charts-lineA {
  548. width: 840upx;
  549. height: 300upx;
  550. }
  551. .qiun-padding{
  552. padding:2%;
  553. width:96%;
  554. }
  555. .qiun-wrap{
  556. display:flex;
  557. flex-wrap:wrap;
  558. }
  559. .qiun-rows{
  560. display:flex;
  561. flex-direction:row !important;
  562. }
  563. .qiun-columns{
  564. display:flex;
  565. flex-direction:column !important;
  566. }
  567. .qiun-common-mt{
  568. margin-top:10upx;
  569. }
  570. .qiun-bg-white{
  571. background:#FFFFFF;
  572. }
  573. .qiun-title-bar{
  574. width:96%;
  575. padding:10upx 2%;
  576. flex-wrap:nowrap;
  577. }
  578. .qiun-title-dot-light{
  579. border-left: 10upx solid #0ea391;
  580. padding-left: 10upx;
  581. font-size: 32upx;
  582. color: #000000
  583. }
  584. .qiun-charts-column{
  585. width: 840upx;
  586. height:350upx;
  587. /* background-color: #FFFFFF; */
  588. }
  589. .charts-column{
  590. width: 840upx;
  591. height:350upx;
  592. /* background-color: #FFFFFF; */
  593. }
  594. </style>