Detail.vue 16 KB

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