Detail.vue 18 KB

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