Detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <template>
  2. <view class="contentike">
  3. <view class="fixed" style="color: #FFFDEF;">
  4. <cu-custom bgColor="bg-gradual-sisBlack" :isBack="true">
  5. <block slot="backText"><view style="height: 80rpx;line-height: 80rpx;color: silver;">返回</view></block>
  6. <block slot="content">
  7. <view style="color: silver;">{{ address }}</view>
  8. </block>
  9. </cu-custom>
  10. </view>
  11. <view class="threeTarget" v-show="targetdetail_visable.targetdetail_target">
  12. <view class="target">
  13. <view class="target_zi">指标</view>
  14. <view class="target_dianLiang">日发电量</view>
  15. </view>
  16. <view class="target">
  17. <view style="font-size: 16px;margin-top: -7px;">数值</view>
  18. <view class="target_count">{{ targetdetail.targetdetail_target }}</view>
  19. </view>
  20. <view class="target">
  21. <view style="font-size: 16px;margin-top: -7px;">单位</view>
  22. <view class="target_danWei">kw/h</view>
  23. </view>
  24. </view>
  25. <view class="qiun-charts">
  26. <view class="speedPowerDiagram">24小时指标曲线图</view>
  27. <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchstart="touchLineA"></canvas>
  28. </view>
  29. <view class="qiun-columnCharts">
  30. <view class="sevenDayColunm">7天指标柱状图</view>
  31. <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts" @touchstart="touchColumn"></canvas>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import uCharts from '../../components/tools/u-charts/u-charts.js';
  37. import res from '../../common/data.json';
  38. var _self;
  39. var canvaLineA;
  40. var canvaColumn = null;
  41. export default {
  42. data() {
  43. let data = {
  44. targetdetail_visable: { targetdetail_target: true, targetdetail_curve: true, targetdetail_histogram: true},
  45. targetdetail: { targetdetail_target: '', targetdetail_curve: '', targetdetail_histogram: ''},
  46. socketTask_targetdetail_target:"",
  47. socketTask_targetdetail_curve:"",
  48. socketTask_targetdetail_histogram:"",
  49. cWidth: '',
  50. cHeight: '',
  51. pixelRatio: 1,
  52. serverData: '',
  53. address: '',
  54. }
  55. return data;
  56. },
  57. created: function() {
  58. this.address = this.getWindPowerStationNameToSessionStorage();
  59. this.windPowerStationId = uni.getStorageSync('windPowerStationId');
  60. this.targetdetail_target();
  61. this.targetdetail_curve();
  62. this.targetdetail_histogram();
  63. },
  64. onShow() {
  65. this.windPowerStationId = uni.getStorageSync('windPowerStationId');
  66. this.address = this.getWindPowerStationNameToSessionStorage();
  67. this.hideModals();
  68. },
  69. onLoad() {
  70. _self = this;
  71. this.cWidth = uni.upx2px(750);
  72. this.cHeight = uni.upx2px(400);
  73. this.getColumnServerData();
  74. this.getLineServerData();
  75. },
  76. onReady() {},
  77. methods: {
  78. targetdetail_target() {
  79. let _this = this;
  80. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  81. this.socketTask_targetdetail_target = uni.connectSocket({
  82. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  83. url: 'ws://192.168.1.104:8082/websocket/pageNumber_8/functionNumber_1',
  84. success(data) {
  85. console.log('websocket连接成功');
  86. }
  87. });
  88. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  89. this.socketTask_targetdetail_target.onOpen(res => {
  90. console.log('WebSocket连接正常打开中...!');
  91. this.is_open_socket = true;
  92. // 注:只有连接正常打开中 ,才能正常收到消息
  93. this.socketTask_targetdetail_target.onMessage(res => {
  94. //console.log("收到服务器内容:" + res.data);
  95. _this.targetdetail.targetdetail_target = res.data;
  96. console.log(_this.targetdetail.targetdetail_target);
  97. });
  98. });
  99. // 这里仅是事件监听【如果socket关闭了会执行】
  100. /* this.socketTask.onClose(() => {
  101. console.log("已经被关闭了")
  102. }) */
  103. },
  104. targetdetail_curve() {
  105. let _this = this;
  106. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  107. this.socketTask_targetdetail_curve = uni.connectSocket({
  108. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  109. url: 'ws://192.168.1.104:8082/websocket/pageNumber_8/functionNumber_2',
  110. success(data) {
  111. console.log('websocket连接成功');
  112. }
  113. });
  114. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  115. this.socketTask_targetdetail_curve.onOpen(res => {
  116. console.log('WebSocket连接正常打开中...!');
  117. this.is_open_socket = true;
  118. // 注:只有连接正常打开中 ,才能正常收到消息
  119. this.socketTask_targetdetail_curve.onMessage(res => {
  120. //console.log("收到服务器内容:" + res.data);
  121. _this.targetdetail.targetdetail_curve = eval(res.data);
  122. });
  123. });
  124. // 这里仅是事件监听【如果socket关闭了会执行】
  125. /* this.socketTask.onClose(() => {
  126. console.log("已经被关闭了")
  127. }) */
  128. },
  129. targetdetail_histogram() {
  130. Date.prototype.Format = function(fmt) {
  131. var o = {
  132. "M+": this.getMonth() + 1, //月份
  133. "d+": this.getDate(), //日
  134. "h+": this.getHours(), //小时
  135. "m+": this.getMinutes(), //分
  136. "s+": this.getSeconds(), //秒
  137. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  138. "S": this.getMilliseconds() //毫秒
  139. };
  140. if(/(y+)/.test(fmt))
  141. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  142. for(var k in o)
  143. if(new RegExp("(" + k + ")").test(fmt))
  144. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  145. return fmt;
  146. };
  147. let _this = this;
  148. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  149. this.socketTask_targetdetail_histogram = uni.connectSocket({
  150. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  151. url: 'ws://192.168.1.104:8082/websocket/pageNumber_8/functionNumber_3',
  152. success(data) {
  153. console.log('websocket连接成功');
  154. }
  155. });
  156. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  157. this.socketTask_targetdetail_histogram.onOpen(res => {
  158. console.log('WebSocket连接正常打开中...!');
  159. this.is_open_socket = true;
  160. // 注:只有连接正常打开中 ,才能正常收到消息
  161. this.socketTask_targetdetail_histogram.onMessage(res => {
  162. //console.log("收到服务器内容:" + res.data);
  163. _this.targetdetail.targetdetail_histogram = eval(res.data);
  164. let Column = {
  165. "categories": ["04/11","04/12", "04/13", "04/14", "04/15", "04/16", "04/17"],
  166. "series": [{
  167. "name": "发电量",
  168. "data": [],
  169. "color": "#29C35A"
  170. }]
  171. };
  172. Column.categories=[];
  173. Column.series[0].data=[];
  174. for(var i=0;i<_this.targetdetail.targetdetail_histogram.length;i++){
  175. _this.targetdetail.targetdetail_histogram[i].pointTime = new Date(_this.targetdetail.targetdetail_histogram[i].pointTime*1000).Format("MM/dd");
  176. Column.categories.push(_this.targetdetail.targetdetail_histogram[i].pointTime);
  177. Column.series[0].data.push(_this.targetdetail.targetdetail_histogram[i].pointValueInDouble);
  178. }
  179. //这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
  180. _self.showColumn('canvasColumn', Column);
  181. });
  182. });
  183. // 这里仅是事件监听【如果socket关闭了会执行】
  184. /* this.socketTask.onClose(() => {
  185. console.log("已经被关闭了")
  186. }) */
  187. },
  188. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  189. uni.setStorageSync('windpowerstationName', windpowerstationName);
  190. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  191. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  192. //this.common.goback('/pages/index/Index');
  193. },
  194. getWindPowerStationNameToSessionStorage() {
  195. uni.getStorageSync('windpowerstationName');
  196. return uni.getStorageSync('windpowerstationName');
  197. },
  198. getLineServerData() {
  199. // 折线图
  200. let LineA = {
  201. categories: [
  202. '17:26',
  203. '18:56',
  204. '19:56',
  205. '20:56',
  206. '21:56',
  207. '22:56',
  208. '23:56',
  209. '00:56',
  210. '01:56',
  211. '02:56',
  212. '03:56',
  213. '04:56',
  214. '05:56',
  215. '06:56',
  216. '07:56',
  217. '08:56',
  218. '09:56',
  219. '10:56',
  220. '11:56',
  221. '12:56',
  222. '13:56',
  223. '14:56',
  224. '15:56',
  225. '16:56',
  226. '17:56 '
  227. ],
  228. series: [
  229. {
  230. name: '功率',
  231. data: [17, 21, 19, 22, 20.2, 19.1, 22.4, 23.8, 21.5, 22.9, 19.2, 22.4, 18.7, 22.1, 21.4, 22.7, 18.4, 18.4, 21.8, 22.5, 22.9, 19.8, 22.7, 23, 22.8],
  232. color: '#4A80B1',
  233. textColor: '#FFFFFF',
  234. textSize: this.seriesTextSize,
  235. format: val => {
  236. return val + 'kwh';
  237. },
  238. index: 0,
  239. legendShape: 'circle'
  240. }
  241. ]
  242. };
  243. this.showLineA('canvasLineA', LineA);
  244. },
  245. showLineA(canvasId, chartData) {
  246. canvaLineA = new uCharts({
  247. $this: _self,
  248. canvasId: canvasId,
  249. type: 'line',
  250. fontSize: 11,
  251. legend: {
  252. show: true,
  253. position: 'top',
  254. float: 'right',
  255. fontColor: 'silver',
  256. itemGap: '4'
  257. },
  258. dataLabel: false,
  259. dataPointShape: false,
  260. background: '#FFFFFF',
  261. pixelRatio: _self.pixelRatio,
  262. categories: chartData.categories,
  263. series: chartData.series,
  264. animation: true,
  265. xAxis: {
  266. type: 'grid',
  267. gridColor: 'silver',
  268. fontColor: 'silver',
  269. gridType: 'solid',
  270. gridColor: '#2E2E2E',
  271. axisLineColor: '#2E2E2E',
  272. labelCount: '3'
  273. // itemCount:"3"
  274. },
  275. yAxis: {
  276. data: [
  277. {
  278. type: 'value',
  279. fontColor: 'silver',
  280. disabled: false, //y轴轴线
  281. min: 0,
  282. max: 40,
  283. position: 'left',
  284. axisLineColor: '#2E2E2E',
  285. title: ' 功率:(kw/h)',
  286. titleFontColor: 'silver'
  287. },
  288. {
  289. fontColor: 'silver',
  290. disabled: false, //y轴轴线
  291. min: 0,
  292. max: 40,
  293. position: 'right',
  294. axisLineColor: '#2E2E2E',
  295. title: '功率:(kwh)',
  296. titleFontColor: 'silver'
  297. }
  298. ],
  299. gridColor: '#2E2E2E',
  300. splitNumber: 4,
  301. gridType: 'solid',
  302. dashLength: 8,
  303. showTitle: 'true',
  304. format: val => {
  305. return val.toFixed(0) + '元';
  306. }
  307. },
  308. width: _self.cWidth * _self.pixelRatio,
  309. height: _self.cHeight * _self.pixelRatio,
  310. extra: {
  311. line: {
  312. type: 'line',
  313. width: '1'
  314. }
  315. }
  316. });
  317. },
  318. touchLineA(e) {
  319. canvaLineA.showToolTip(e, {
  320. format: function(item, category) {
  321. return category + ' ' + item.name + ':' + item.data;
  322. }
  323. });
  324. },
  325. moveLineA(e) {
  326. canvaLineA.scroll(e);
  327. },
  328. getColumnServerData() {
  329. let Column = {
  330. "categories": ["04/11","04/12", "04/13", "04/14", "04/15", "04/16", "04/17"],
  331. "series": [{
  332. "name": "发电量",
  333. "data": [10, 20,30, 40, 30, 20, 10,20],
  334. "color": "#29C35A"
  335. }]
  336. };
  337. //这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
  338. _self.showColumn('canvasColumn', Column);
  339. },
  340. showColumn(canvasId, chartData) {
  341. canvaColumn = new uCharts({
  342. $this: _self,
  343. canvasId: canvasId,
  344. type: 'column',
  345. legend: {
  346. show: true,
  347. fontSize: 12,
  348. padding: 5,
  349. fontColor: 'silver',
  350. itemGap: '4',
  351. // margin:0,
  352. position: 'top',
  353. float: 'right'
  354. },
  355. fontSize: 11,
  356. background: '#242424',
  357. pixelRatio: _self.pixelRatio,
  358. animation: true,
  359. categories: chartData.categories,
  360. series: chartData.series,
  361. xAxis: {
  362. // disabled:true,
  363. rotateLabel: true,
  364. disableGrid: true,
  365. axisLineColor: '#2D2D2D',
  366. fontColor: '#ffffff'
  367. // gridColor:'#2D2D2D',
  368. },
  369. yAxis: {
  370. showTitle: true,
  371. // disableGrid:true,
  372. gridType: 'solid',
  373. dashLength: 8,
  374. gridColor: '#2D2D2D',
  375. splitNumber: 5,
  376. min: 0,
  377. max: 40,
  378. data: [
  379. {
  380. min: 0,
  381. max: 40,
  382. position: 'left',
  383. axisLine: false,
  384. fontColor: 'silver',
  385. // title: '7天功率柱状图',
  386. title: ' 功率:(kw/h)',
  387. titleFontColor: 'silver',
  388. // title: '功率(kw/h)',
  389. // titleFontColor: '#FFFFFF',
  390. titleFontSize: 11,
  391. format: val => {
  392. return val.toFixed(0) + '';
  393. }
  394. }
  395. ]
  396. },
  397. dataLabel: true,
  398. width: _self.cWidth * _self.pixelRatio,
  399. height: _self.cHeight * _self.pixelRatio,
  400. extra: {
  401. column: {
  402. type: 'group',
  403. // width: _self.cWidth * _self.pixelRatio * 0.45 / chartData.categories.length
  404. width: 12,
  405. lineStyle: {
  406. width: 5
  407. }
  408. }
  409. }
  410. });
  411. },
  412. goToIndex() {
  413. uni.switchTab({
  414. url: '/pages/index/Index'
  415. });
  416. },
  417. touchColumn(e) {
  418. canvaColumn.showToolTip(e, {
  419. format: function(item, category) {
  420. if (typeof item.data === 'object') {
  421. return category + ' ' + item.name + ':' + item.data.value;
  422. } else {
  423. return category + ' ' + item.name + ':' + item.data;
  424. }
  425. }
  426. });
  427. }
  428. }
  429. };
  430. </script>
  431. <style>
  432. @font-face {
  433. font-family: '方正兰亭细黑_GBK';
  434. src: url(../../static/方正兰亭细黑_GBK.TTF);
  435. }
  436. page {
  437. /* background-color: #FFFFFF; */
  438. font-family: '方正兰亭细黑_GBK';
  439. background-color: #1f1f1f;
  440. color: silver;
  441. font-size: 14px;
  442. }
  443. body {
  444. background: #1f1f1f;
  445. font-family: '方正兰亭细黑_GBK';
  446. font-size: 14px;
  447. color: silver;
  448. }
  449. .addressName {
  450. /* width: 100%; */
  451. /* background-color: white; */
  452. /* width: 126px; */
  453. height: 80rpx;
  454. line-height: 80rpx;
  455. margin-left: 40%;
  456. color: silver;
  457. font-size: 18px;
  458. }
  459. .target_dianLiang {
  460. margin-top: 15px;
  461. font-size: 16px;
  462. font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', STHeiti, 'Microsoft Yahei', Tahoma, Simsun, sans-serif;
  463. }
  464. .target_count {
  465. margin-top: 15px;
  466. font-size: 16px;
  467. font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', STHeiti, 'Microsoft Yahei', Tahoma, Simsun, sans-serif;
  468. }
  469. .target_danWei {
  470. margin-top: 15px;
  471. font-size: 16px;
  472. font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', STHeiti, 'Microsoft Yahei', Tahoma, Simsun, sans-serif;
  473. }
  474. .threeTarget {
  475. width: 100%;
  476. height: 120px;
  477. background-color: #242424;
  478. display: -webkit-flex;
  479. display: flex;
  480. justify-content: space-around;
  481. float: left;
  482. }
  483. .target {
  484. width: 28%;
  485. height: 78px;
  486. background: -webkit-linear-gradient(top, rgba(159, 131, 111, 0.1) 0%, rgba(193, 94, 21, 0.2) 100%);
  487. border-radius: 5px;
  488. float: left;
  489. margin-top: 20px;
  490. text-align: center;
  491. color: silver;
  492. padding-top: 20px;
  493. font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', STHeiti, 'Microsoft Yahei', Tahoma, Simsun, sans-serif;
  494. }
  495. .target_zi {
  496. font-size: 16px;
  497. text-align: center;
  498. margin-top: -7px;
  499. }
  500. .speedPowerDiagram {
  501. width: 100px;
  502. height: 30px;
  503. user-select: text;
  504. -webkit-user-select: text;
  505. -moz-user-select: text;
  506. -ms-user-select: text;
  507. color: silver;
  508. float: left;
  509. margin-top: 18px;
  510. margin-left: 9px;
  511. font-size: 11px;
  512. }
  513. .qiun-charts {
  514. width: 750upx;
  515. height: 400upx;
  516. margin-top: 140px;
  517. background-color: #242424;
  518. }
  519. .charts {
  520. width: 750upx;
  521. height: 400upx;
  522. }
  523. .qiun-columnCharts {
  524. width: 750upx;
  525. height: 400upx;
  526. margin-top: 20px;
  527. background-color: #242424;
  528. }
  529. .sevenDayColunm {
  530. width: 100px;
  531. height: 30px;
  532. user-select: text;
  533. -webkit-user-select: text;
  534. -moz-user-select: text;
  535. -ms-user-select: text;
  536. color: silver;
  537. float: left;
  538. margin-top: 18px;
  539. margin-left: 10px;
  540. font-size: 11px;
  541. }
  542. </style>