Detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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.getWindPowerStationNameToSessionStorage();
  210. this.windPowerStationId=uni.getStorageSync('windPowerStationId');
  211. this.getWeatherData();
  212. this.windowWidth=uni.getSystemInfoSync().windowWidth;
  213. this.windowHeight=uni.getSystemInfoSync().windowHeight;
  214. if(this.windowWidth>=768){
  215. this.timeFontSize="22px";
  216. this.titleFontSize="22px";
  217. this.hourFontSize="22px";
  218. this.xAxisFontSize=18;
  219. this.seriesTextSize=18;
  220. }else{
  221. this.timeFontSize="15px";
  222. this.titleFontSize="15px";
  223. this.hourFontSize="15px";
  224. this.xAxisFontSize=12;
  225. this.seriesTextSize=12;
  226. }
  227. },
  228. onShow() {
  229. this.address = this.getWindPowerStationNameToSessionStorage();
  230. this.windPowerStationId=uni.getStorageSync('windPowerStationId');
  231. this.getWeatherData();
  232. },
  233. computed: {
  234. backStageIp: function() {
  235. return this.$store.state.wholeSituationBackStageIp;
  236. },
  237. backStagePort: function() {
  238. return this.$store.state.wholeSituationBackStagePort;
  239. },
  240. windpowerstationNameToId: function() {
  241. return this.$store.state.windpowerstationNameToId;
  242. }
  243. },
  244. methods:{
  245. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  246. uni.setStorageSync('windpowerstationName',windpowerstationName);
  247. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  248. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  249. //this.common.goback('/pages/index/Index');
  250. },
  251. getWindPowerStationNameToSessionStorage() {
  252. uni.getStorageSync('windpowerstationName');
  253. return uni.getStorageSync('windpowerstationName');
  254. },
  255. getWeatherData: function() {
  256. let _this = this;
  257. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  258. this.socketTask = uni.connectSocket({
  259. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  260. url: 'ws://' + this.backStageIp + ':' + this.backStagePort + '/websocket/pageNumber_3/functionNumber_2',
  261. success(data) {
  262. console.log("websocket连接成功");
  263. },
  264. });
  265. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  266. this.socketTask.onOpen((res) => {
  267. console.log("WebSocket连接正常打开中...!");
  268. this.is_open_socket = true;
  269. // 注:只有连接正常打开中 ,才能正常收到消息
  270. this.socketTask.onMessage((res) => {
  271. //console.log("收到服务器内容:" + res.data);
  272. //debugger
  273. _this.weatherProphetDataAll_17Hour =res.data;
  274. _this.weatherProphetDataAll_17Hour=JSON.parse(res.data);
  275. _this.weatherProphetData_17Hour = [];
  276. //判断风场id 40天
  277. for(let i = 0; i < _this.weatherProphetDataAll_17Hour.length; i++) {
  278. if(_this.weatherProphetDataAll_17Hour[i].windpowerstationid == _this.windPowerStationId) {
  279. _this.weatherProphetData_17Hour.push(_this.weatherProphetDataAll_17Hour[i]);
  280. }
  281. }
  282. //console.log(_this.weatherProphetData_17Hour);
  283. let startMonth = new Date(_this.weatherProphetData_17Hour[0].date).getMonth() + 1;
  284. let startDay = new Date(_this.weatherProphetData_17Hour[0].date).getDate() ;
  285. let startHour = new Date(_this.weatherProphetData_17Hour[0].date).getHours() ;
  286. _this.startDate = startMonth + "月" + startDay+"日" + startHour+"时";
  287. let endMonth = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getMonth() + 1;
  288. let endDay = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getDate() ;
  289. let endHour = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getHours() ;
  290. _this.endDate = endMonth + "月" + endDay+"日" + endHour+"时";
  291. _this.hours=[];
  292. for(let i=0;i<_this.weatherProphetData_17Hour.length;i++){
  293. _this.hours.push(new Date(_this.weatherProphetData_17Hour[i].date).getHours());
  294. }
  295. _this.getServerData();
  296. });
  297. })
  298. // 这里仅是事件监听【如果socket关闭了会执行】
  299. this.socketTask.onClose(() => {
  300. console.log("已经被关闭了")
  301. })
  302. // let _this = this;
  303. // if(typeof(WebSocket) == "undefined") {
  304. // console.log("您的浏览器不支持WebSocket");
  305. // } else {
  306. // console.log("您的浏览器支持WebSocket");
  307. // //实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
  308. // this.socket = new WebSocket("ws://49.4.78.143:8081/websocket/pageNumber_3/functionNumber_2");
  309. // this.openSocket();
  310. // //获得消息事件
  311. // this.socket.onmessage = function onMessage(message) {
  312. // _this.weatherProphetDataAll_17Hour = eval(message.data);
  313. // _this.weatherProphetData_17Hour = [];
  314. // //判断风场id
  315. // for(let i = 0; i < _this.weatherProphetDataAll_17Hour.length; i++) {
  316. // if(_this.weatherProphetDataAll_17Hour[i].windpowerstationid == _this.windPowerStationId) {
  317. // _this.weatherProphetData_17Hour.push(_this.weatherProphetDataAll_17Hour[i]);
  318. // }
  319. // }
  320. // console.log(_this.weatherProphetData_17Hour);
  321. // let startMonth = new Date(_this.weatherProphetData_17Hour[0].date).getMonth() + 1;
  322. // let startDay = new Date(_this.weatherProphetData_17Hour[0].date).getDate() ;
  323. // let startHour = new Date(_this.weatherProphetData_17Hour[0].date).getHours() ;
  324. // _this.startDate = startMonth + "月" + startDay+"日" + startHour+"时";
  325. // let endMonth = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getMonth() + 1;
  326. // let endDay = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getDate() ;
  327. // let endHour = new Date(_this.weatherProphetData_17Hour[_this.weatherProphetData_17Hour.length-1].date).getHours() ;
  328. // _this.endDate = endMonth + "月" + endDay+"日" + endHour+"时";
  329. // _this.hours=[];
  330. // for(let i=0;i<_this.weatherProphetData_17Hour.length;i++){
  331. // _this.hours.push(new Date(_this.weatherProphetData_17Hour[i].date).getHours());
  332. // }
  333. // _this.getServerData();
  334. // }
  335. // }
  336. },
  337. getServerData(){
  338. //柱状图
  339. let Column={
  340. "categories": ["2012", "2013", "2014", "2015", "2016", "2017"],
  341. "series": [{
  342. "name": "成交量1",
  343. "data": [15, {"value": 20,"color": "#f04864"}, 45, 37, 43, 34],
  344. "color": '#f04864',
  345. "textColor":"#FFFFFF",
  346. "textSize":this.seriesTextSize,
  347. format:(val)=>{return val+'℃ㅤ'}
  348. }
  349. /*, {
  350. "name": "成交量2",
  351. "data": [30, {"value": 40,"color": "#facc14"}, 25, 14, 34, 18],
  352. "color": '#facc14',
  353. "textColor":"#FFFFFF",
  354. "textSize":this.seriesTextSize,
  355. format:(val)=>{return ' '+val+'℃'}
  356. }*/
  357. ]
  358. };
  359. Column.categories=[];
  360. Column.series[0].data=[];
  361. //Column.series[1].data=[];
  362. for(let i=0;i<this.weatherProphetData_17Hour.length;i++){
  363. let xAxisHours = new Date(this.weatherProphetData_17Hour[i].date).getHours();
  364. Column.categories.push(xAxisHours+"时");
  365. Column.series[0].data.push(this.weatherProphetData_17Hour[i].temperature);
  366. // Column.series[1].data.push(this.weatherProphetData_17Hour[i].realfeel);
  367. }
  368. this.showColumn("canvasColumn",Column);
  369. //折线图
  370. let LineA={
  371. categories: ['2012', '2013', '2014', '2015', '2016', '2017'],
  372. series: [{
  373. name: '风速',
  374. data: [35, 20, 25, 37, 4, 20],
  375. color: '#FFFFFF',
  376. textColor:"#FFFFFF",
  377. textSize:this.seriesTextSize,
  378. format:(val)=>{return val+'km/h'}
  379. }]
  380. };
  381. LineA.categories=[];
  382. LineA.series[0].data=[];
  383. for(let i=0;i<this.weatherProphetData_17Hour.length;i++){
  384. LineA.categories.push(this.weatherProphetData_17Hour[i].winddirection );
  385. LineA.series[0].data.push(this.weatherProphetData_17Hour[i].speed);
  386. }
  387. this.showLineA("canvasLineA",LineA);
  388. },
  389. showColumn(canvasId,chartData){
  390. var _self = this;
  391. var canvaColumn=new uCharts({
  392. $this:_self,
  393. canvasId: canvasId,
  394. type: 'column',
  395. legend:{show:false},
  396. fontSize:11,
  397. background:'#FFFFFF',
  398. pixelRatio:_self.pixelRatioColumn,
  399. animation: true,
  400. categories: chartData.categories,
  401. series: chartData.series,
  402. xAxis: {
  403. disableGrid:true,
  404. fontColor:"#FFFFFF",
  405. fontSize:_self.xAxisFontSize,
  406. },
  407. yAxis: {
  408. disabled:true,
  409. disableGrid:true,
  410. min:-40,
  411. max:50,
  412. },
  413. dataLabel: true,
  414. width: _self.cWidthColumn*_self.pixelRatioColumn,
  415. height: _self.cHeightColumn*_self.pixelRatioColumn,
  416. padding:[0,10,15,10],//画布填充边距,顺序为上右下左,同css,但必须4位
  417. extra: {
  418. column: {
  419. type:'group',
  420. width: '10'
  421. }
  422. }
  423. });
  424. },
  425. showLineA(canvasId,chartData){
  426. var _self = this;
  427. var canvaLineA=new uCharts({
  428. $this:_self,
  429. canvasId: canvasId,
  430. type: 'line',
  431. fontSize:11,
  432. legend:{show:false},//图例
  433. dataLabel:true,//数据点标签
  434. dataPointShape:true,
  435. background:'#FFFFFF',
  436. pixelRatio:_self.pixelRatioLineA,
  437. categories: chartData.categories,
  438. series: chartData.series,
  439. animation: true,
  440. xAxis: {
  441. type:'grid',
  442. gridColor:'#CCCCCC',
  443. gridType:'dash',
  444. dashLength:8,
  445. disableGrid:true,//网格线
  446. axisLine:true,//x轴轴线
  447. fontColor:"#FFFFFF",
  448. fontSize:_self.xAxisFontSize
  449. },
  450. yAxis: {
  451. data:{
  452. disabled:false//y轴轴线
  453. },
  454. disableGrid:true,//网格线
  455. gridType:'dash',
  456. gridColor:'#CCCCCC',
  457. dashLength:8,
  458. splitNumber:5,
  459. min:-40,
  460. max:40,
  461. format:(val)=>{return val.toFixed(0)+'元'}
  462. },
  463. width: _self.cWidthLineA*_self.pixelRatioLineA,
  464. height: _self.cHeightLineA*_self.pixelRatioLineA,
  465. padding:[0,0,15,-25],//画布填充边距,顺序为上右下左,同css,但必须4位
  466. extra: {
  467. line:{
  468. type: 'curve'//曲线
  469. }
  470. }
  471. });
  472. },
  473. closeSocket: function() {
  474. this.socket.onclose;
  475. },
  476. openSocket: function() {
  477. this.socket.onOpen;
  478. }
  479. },
  480. onLoad(option) {
  481. this.cWidthColumn=uni.upx2px(840);
  482. this.cHeightColumn=uni.upx2px(350);
  483. this.cWidthLineA=uni.upx2px(840);
  484. this.cHeightLineA=uni.upx2px(300);
  485. //this.getServerData();
  486. this.address = this.getWindPowerStationNameToSessionStorage();;
  487. }
  488. }
  489. </script>
  490. <style>
  491. page {
  492. background-color: #1f1f1f;
  493. font-family: '方正兰亭细黑_GBK';
  494. overflow-x: hidden;
  495. }
  496. .cu-card{
  497. width: 90%;
  498. height: 450upx;
  499. margin: 15px auto;
  500. }
  501. .cardContenter{
  502. border-radius: 20px;
  503. /* margin: 20px auto; */
  504. width: 100%;
  505. height: 450upx;
  506. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024F93), color-stop(1.5, #cccccc), to(#437193));
  507. background: rgba(0, 0, 0, 0.1);
  508. }
  509. .timeAndTitle{
  510. width: 90%;
  511. margin-left: 20px;
  512. height: 100upx;
  513. font-family: "microsoft yahei";
  514. font-size: 15px;
  515. color: white;
  516. }
  517. .time{
  518. float: left;
  519. height: 100upx;
  520. line-height: 100upx;
  521. }
  522. .title{
  523. float: right;
  524. text-align: right;
  525. height: 100upx;
  526. line-height: 100upx;
  527. }
  528. .hours{
  529. width: 800upx;
  530. height: 50upx;
  531. margin-left: -4%;
  532. color: white;
  533. }
  534. .hour{
  535. width: 50upx;
  536. float: left;
  537. margin-left: 13.5%;
  538. }
  539. .scrollUcharts{
  540. white-space: nowrap;
  541. }
  542. .qiun-charts-lineA {
  543. width: 840upx;
  544. height: 300upx;
  545. }
  546. .charts-lineA {
  547. width: 840upx;
  548. height: 300upx;
  549. }
  550. .qiun-padding{
  551. padding:2%;
  552. width:96%;
  553. }
  554. .qiun-wrap{
  555. display:flex;
  556. flex-wrap:wrap;
  557. }
  558. .qiun-rows{
  559. display:flex;
  560. flex-direction:row !important;
  561. }
  562. .qiun-columns{
  563. display:flex;
  564. flex-direction:column !important;
  565. }
  566. .qiun-common-mt{
  567. margin-top:10upx;
  568. }
  569. .qiun-bg-white{
  570. background:#FFFFFF;
  571. }
  572. .qiun-title-bar{
  573. width:96%;
  574. padding:10upx 2%;
  575. flex-wrap:nowrap;
  576. }
  577. .qiun-title-dot-light{
  578. border-left: 10upx solid #0ea391;
  579. padding-left: 10upx;
  580. font-size: 32upx;
  581. color: #000000
  582. }
  583. .qiun-charts-column{
  584. width: 840upx;
  585. height:350upx;
  586. /* background-color: #FFFFFF; */
  587. }
  588. .charts-column{
  589. width: 840upx;
  590. height:350upx;
  591. /* background-color: #FFFFFF; */
  592. }
  593. </style>