Detail.vue 17 KB

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