Detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. "name": "成交量2",
  350. "data": [30, {"value": 40,"color": "#facc14"}, 25, 14, 34, 18],
  351. "color": '#facc14',
  352. "textColor":"#FFFFFF",
  353. "textSize":this.seriesTextSize,
  354. format:(val)=>{return 'ㅤ'+val+'℃'}
  355. }]
  356. };
  357. Column.categories=[];
  358. Column.series[0].data=[];
  359. Column.series[1].data=[];
  360. for(let i=0;i<this.weatherProphetData_17Hour.length;i++){
  361. let xAxisHours = new Date(this.weatherProphetData_17Hour[i].date).getHours();
  362. Column.categories.push(xAxisHours+"时");
  363. Column.series[0].data.push(this.weatherProphetData_17Hour[i].temperature);
  364. Column.series[1].data.push(this.weatherProphetData_17Hour[i].realfeel);
  365. }
  366. this.showColumn("canvasColumn",Column);
  367. //折线图
  368. let LineA={
  369. categories: ['2012', '2013', '2014', '2015', '2016', '2017'],
  370. series: [{
  371. name: '风速',
  372. data: [35, 20, 25, 37, 4, 20],
  373. color: '#FFFFFF',
  374. textColor:"#FFFFFF",
  375. textSize:this.seriesTextSize,
  376. format:(val)=>{return val+'km/h'}
  377. }]
  378. };
  379. LineA.categories=[];
  380. LineA.series[0].data=[];
  381. for(let i=0;i<this.weatherProphetData_17Hour.length;i++){
  382. LineA.categories.push(this.weatherProphetData_17Hour[i].winddirection );
  383. LineA.series[0].data.push(this.weatherProphetData_17Hour[i].speed);
  384. }
  385. this.showLineA("canvasLineA",LineA);
  386. },
  387. showColumn(canvasId,chartData){
  388. var _self = this;
  389. var canvaColumn=new uCharts({
  390. $this:_self,
  391. canvasId: canvasId,
  392. type: 'column',
  393. legend:{show:false},
  394. fontSize:11,
  395. background:'#FFFFFF',
  396. pixelRatio:_self.pixelRatioColumn,
  397. animation: true,
  398. categories: chartData.categories,
  399. series: chartData.series,
  400. xAxis: {
  401. disableGrid:true,
  402. fontColor:"#FFFFFF",
  403. fontSize:_self.xAxisFontSize,
  404. },
  405. yAxis: {
  406. disabled:true,
  407. disableGrid:true,
  408. min:-40,
  409. max:50,
  410. },
  411. dataLabel: true,
  412. width: _self.cWidthColumn*_self.pixelRatioColumn,
  413. height: _self.cHeightColumn*_self.pixelRatioColumn,
  414. padding:[0,10,15,10],//画布填充边距,顺序为上右下左,同css,但必须4位
  415. extra: {
  416. column: {
  417. type:'group',
  418. width: '10'
  419. }
  420. }
  421. });
  422. },
  423. showLineA(canvasId,chartData){
  424. var _self = this;
  425. var canvaLineA=new uCharts({
  426. $this:_self,
  427. canvasId: canvasId,
  428. type: 'line',
  429. fontSize:11,
  430. legend:{show:false},//图例
  431. dataLabel:true,//数据点标签
  432. dataPointShape:true,
  433. background:'#FFFFFF',
  434. pixelRatio:_self.pixelRatioLineA,
  435. categories: chartData.categories,
  436. series: chartData.series,
  437. animation: true,
  438. xAxis: {
  439. type:'grid',
  440. gridColor:'#CCCCCC',
  441. gridType:'dash',
  442. dashLength:8,
  443. disableGrid:true,//网格线
  444. axisLine:true,//x轴轴线
  445. fontColor:"#FFFFFF",
  446. fontSize:_self.xAxisFontSize
  447. },
  448. yAxis: {
  449. data:{
  450. disabled:false//y轴轴线
  451. },
  452. disableGrid:true,//网格线
  453. gridType:'dash',
  454. gridColor:'#CCCCCC',
  455. dashLength:8,
  456. splitNumber:5,
  457. min:-40,
  458. max:40,
  459. format:(val)=>{return val.toFixed(0)+'元'}
  460. },
  461. width: _self.cWidthLineA*_self.pixelRatioLineA,
  462. height: _self.cHeightLineA*_self.pixelRatioLineA,
  463. padding:[0,0,15,-25],//画布填充边距,顺序为上右下左,同css,但必须4位
  464. extra: {
  465. line:{
  466. type: 'curve'//曲线
  467. }
  468. }
  469. });
  470. },
  471. closeSocket: function() {
  472. this.socket.onclose;
  473. },
  474. openSocket: function() {
  475. this.socket.onOpen;
  476. }
  477. },
  478. onLoad(option) {
  479. this.cWidthColumn=uni.upx2px(840);
  480. this.cHeightColumn=uni.upx2px(350);
  481. this.cWidthLineA=uni.upx2px(840);
  482. this.cHeightLineA=uni.upx2px(300);
  483. //this.getServerData();
  484. this.address = this.getWindPowerStationNameToSessionStorage();;
  485. }
  486. }
  487. </script>
  488. <style>
  489. page {
  490. background-color: #1f1f1f;
  491. font-family: '方正兰亭细黑_GBK';
  492. overflow-x: hidden;
  493. }
  494. .cu-card{
  495. width: 90%;
  496. height: 450upx;
  497. margin: 15px auto;
  498. }
  499. .cardContenter{
  500. border-radius: 20px;
  501. /* margin: 20px auto; */
  502. width: 100%;
  503. height: 450upx;
  504. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024F93), color-stop(1.5, #cccccc), to(#437193));
  505. background: rgba(0, 0, 0, 0.1);
  506. }
  507. .timeAndTitle{
  508. width: 90%;
  509. margin-left: 20px;
  510. height: 100upx;
  511. font-family: "microsoft yahei";
  512. font-size: 15px;
  513. color: white;
  514. }
  515. .time{
  516. float: left;
  517. height: 100upx;
  518. line-height: 100upx;
  519. }
  520. .title{
  521. float: right;
  522. text-align: right;
  523. height: 100upx;
  524. line-height: 100upx;
  525. }
  526. .hours{
  527. width: 800upx;
  528. height: 50upx;
  529. margin-left: 27px;
  530. color: white;
  531. }
  532. .hour{
  533. width: 50upx;
  534. float: left;
  535. margin-right: 32px;
  536. }
  537. .scrollUcharts{
  538. white-space: nowrap;
  539. }
  540. .qiun-charts-lineA {
  541. width: 840upx;
  542. height: 300upx;
  543. }
  544. .charts-lineA {
  545. width: 840upx;
  546. height: 300upx;
  547. }
  548. .qiun-padding{
  549. padding:2%;
  550. width:96%;
  551. }
  552. .qiun-wrap{
  553. display:flex;
  554. flex-wrap:wrap;
  555. }
  556. .qiun-rows{
  557. display:flex;
  558. flex-direction:row !important;
  559. }
  560. .qiun-columns{
  561. display:flex;
  562. flex-direction:column !important;
  563. }
  564. .qiun-common-mt{
  565. margin-top:10upx;
  566. }
  567. .qiun-bg-white{
  568. background:#FFFFFF;
  569. }
  570. .qiun-title-bar{
  571. width:96%;
  572. padding:10upx 2%;
  573. flex-wrap:nowrap;
  574. }
  575. .qiun-title-dot-light{
  576. border-left: 10upx solid #0ea391;
  577. padding-left: 10upx;
  578. font-size: 32upx;
  579. color: #000000
  580. }
  581. .qiun-charts-column{
  582. width: 840upx;
  583. height:350upx;
  584. /* background-color: #FFFFFF; */
  585. }
  586. .charts-column{
  587. width: 840upx;
  588. height:350upx;
  589. /* background-color: #FFFFFF; */
  590. }
  591. </style>