Detail.vue 18 KB

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