Detail.vue 17 KB

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