Detail.vue 17 KB

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