elementdata.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="selecttimes" @click="tiemshow = !tiemshow">
  5. <view class="timesbox">
  6. <image
  7. :src="
  8. $imageURL+ '/bigdata_app' +
  9. '/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'
  10. "
  11. mode=""
  12. ></image>
  13. <p>{{ timetab(oldtime) }}</p>
  14. <p class="or">~</p>
  15. <p>{{ timetab(newtime) }}</p>
  16. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  17. </view>
  18. <u-calendar
  19. v-model="tiemshow"
  20. mode="range"
  21. @change="tiemchange"
  22. ></u-calendar>
  23. </view>
  24. <view class="shuju_one">
  25. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  26. 暂无数据
  27. </view>
  28. <view class="canvastishi" v-if="dataloadingtf">
  29. <p class="dataloading">加载中</p>
  30. </view>
  31. <canvas
  32. v-if="canvastishiTF"
  33. canvas-id="canvasColumnA"
  34. id="canvasColumnA"
  35. class="charts"
  36. @touchstart="touchLineA($event)"
  37. @touchmove="moveLineA($event)"
  38. @touchend="touchEndLineA($event)"
  39. disable-scroll="true"
  40. :style="{
  41. width: cWidth * pixelRatio + 'px',
  42. height: cHeight * pixelRatio + 'px',
  43. transform: 'scale(' + 1 / pixelRatio + ')',
  44. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  45. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  46. }"
  47. ></canvas>
  48. </view>
  49. <view class="refresh" @click="refresh"> 刷 新 </view>
  50. <view class="condition">
  51. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  52. <table class="table">
  53. <tr class="tr">
  54. <th class="th" v-for="(item, index) in thdata" :key="'a' + index">
  55. {{ item }}
  56. </th>
  57. </tr>
  58. <tr
  59. class="tr"
  60. v-for="(items, indexs) in eqlistdata[0].length"
  61. :key="'b' + indexs"
  62. >
  63. <td
  64. class="td"
  65. v-for="(item, index) in eqlistdata"
  66. :key="'c' + index"
  67. >
  68. {{ item[indexs] }}
  69. </td>
  70. <!-- |timeFormat() -->
  71. </tr>
  72. <tr class="tr" v-if="!forbidden">
  73. <td class="td" v-for="item in 12">暂无数据</td>
  74. </tr>
  75. </table>
  76. </scroll-view>
  77. <view class="pagenumber">
  78. <button @click="prev">上一页</button>
  79. <view class="pagenumber_page"> 第{{ page }}页 </view>
  80. <view class="pagenumber_page"> 共 {{ pagesum }} 页 </view>
  81. <button @click="next" :disabled="!forbidden">下一页</button>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <style lang="scss"></style>
  88. <script>
  89. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  90. var canvaColumnA = null;
  91. var presenttime = null;
  92. // var oldpresenttime = presenttime - 24*60*60*1000
  93. export default {
  94. data() {
  95. return {
  96. thdata: ['上报时间'],
  97. eqlistdata: [[]],
  98. cWidth: '400',
  99. cHeight: '400',
  100. pixelRatio: 1,
  101. oldtime: '',
  102. newtime: '',
  103. page: 1,
  104. forbidden: false, //暂无数据
  105. times: {
  106. d_id: null,
  107. start_time: null,
  108. end_time: null,
  109. device_id: null,
  110. },
  111. canvastishiTF: false, //折线图暂无数据提示
  112. dataloadingtf: true, //加载中提示
  113. pagesum: 1,
  114. tiemshow: false, //日历选择器
  115. };
  116. },
  117. // 页面加载执行的函数
  118. onLoad(option) {
  119. this.times.device_id = option.device_id;
  120. // this.times.imei = option.imei
  121. this.cWidth = uni.upx2px(650);
  122. this.cHeight = uni.upx2px(500);
  123. presenttime = +new Date();
  124. this.oldtime = parseInt((presenttime - 30 * 24 * 60 * 60 * 1000) / 1000);
  125. this.newtime = parseInt(presenttime / 1000);
  126. setTimeout(() => {
  127. this.getServerData(
  128. parseInt(presenttime / 1000),
  129. parseInt((presenttime - 30 * 24 * 60 * 60 * 1000) / 1000)
  130. );
  131. this.historydata(
  132. parseInt(presenttime / 1000),
  133. parseInt((presenttime - 30 * 24 * 60 * 60 * 1000) / 1000)
  134. );
  135. }, 1000);
  136. },
  137. onShow() {},
  138. onPullDownRefresh() {
  139. console.log('refresh');
  140. this.getServerData(
  141. parseInt(presenttime / 1000),
  142. parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  143. );
  144. this.historydata(
  145. parseInt(presenttime / 1000),
  146. parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  147. );
  148. setTimeout(function () {
  149. uni.stopPullDownRefresh();
  150. }, 1000);
  151. },
  152. methods: {
  153. //
  154. //forecast.worm_lamp.device_polyline_data
  155. // 获取数据,发请求
  156. async getServerData(newtime, oldtimes) {
  157. //设备折线图
  158. this.dataloadingtf = true;
  159. const res = await this.$myRequest({
  160. url: '/api/api_gateway?method=weather.weather.sf_data_chart',
  161. data: {
  162. device_id: this.times.device_id,
  163. end: newtime,
  164. begin: oldtimes,
  165. },
  166. });
  167. this.dataloadingtf = false;
  168. if (res.length == 0) {
  169. this.canvastishiTF = false;
  170. } else {
  171. this.canvastishiTF = true;
  172. var dataarr = res.conf.eleName.split('/');
  173. var elearr = res.conf.eleNum.split('/');
  174. var xtitle = [];
  175. var arr = [];
  176. var color = ['#F97000', '#00E29D', '#FF3F3F', '#6CBBFF', '#00E29D'];
  177. for (var i = 0; i < dataarr.length; i++) {
  178. if (dataarr[i] != '-') {
  179. var valuearr = [];
  180. for (var j = 0; j < res.dat.length; j++) {
  181. var numarr = JSON.stringify(res.dat[j].device_status).slice(
  182. 2,
  183. -2
  184. );
  185. numarr = numarr.split(',');
  186. var numobj = {};
  187. for (var k = 0; k < numarr.length; k++) {
  188. numarr[k] = numarr[k].split(':');
  189. var index =
  190. numarr[k][0].indexOf('e') == -1
  191. ? numarr[k][0].indexOf('j')
  192. : numarr[k][0].indexOf('e');
  193. numobj[numarr[k][0].slice(index, -1)] = Number(numarr[k][1]);
  194. }
  195. valuearr.unshift(numobj['e' + (i + 1)]); // + elelist[elearr[i]].unit
  196. var times = new Date(res.dat[j].uptime * 1000);
  197. xtitle.unshift(
  198. times.getMonth() +
  199. 1 +
  200. '/' +
  201. times.getDate() +
  202. '-' +
  203. times.getHours() +
  204. ':' +
  205. times.getMinutes()
  206. );
  207. }
  208. var obj = {
  209. name: dataarr[i],
  210. data: valuearr,
  211. color: color[i],
  212. };
  213. arr.push(obj);
  214. }
  215. }
  216. console.log(arr);
  217. this.showColumn('canvasColumnA', xtitle, arr);
  218. }
  219. },
  220. async historydata(newtime, oldtimes) {
  221. //设备表格数据
  222. const res = await this.$myRequest({
  223. url: '/api/api_gateway?method=weather.weather.sf_data',
  224. data: {
  225. device_id: this.times.device_id,
  226. page: this.page,
  227. page_size: 10,
  228. begin: oldtimes,
  229. end: newtime,
  230. },
  231. });
  232. console.log(res);
  233. if (res.length == 0) {
  234. this.forbidden = false;
  235. } else {
  236. this.pagesum = Math.floor(res.nums / 10) + 1;
  237. this.forbidden = true;
  238. this.eqlistdata = [];
  239. var dataarr = res.conf.eleName.split('/');
  240. var elearr = res.conf.eleNum.split('/');
  241. this.thdata = ['上报时间'];
  242. var timearr = [];
  243. for (var i = 0; i < dataarr.length; i++) {
  244. if (dataarr[i] != '-') {
  245. this.thdata.push(dataarr[i]);
  246. var valuearr = [];
  247. for (var j = 0; j < res.dat.length; j++) {
  248. var numarr = JSON.stringify(res.dat[j].device_status).slice(
  249. 2,
  250. -2
  251. );
  252. numarr = numarr.split(',');
  253. var numobj = {};
  254. for (var k = 0; k < numarr.length; k++) {
  255. numarr[k] = numarr[k].split(':');
  256. var index = numarr[k][0].indexOf('e');
  257. numobj[numarr[k][0].slice(index, -1)] = Number(numarr[k][1]);
  258. }
  259. valuearr.push(numobj['e' + (i + 1)]); // + elelist[elearr[i]].unit
  260. }
  261. console.log(valuearr);
  262. this.eqlistdata.push(valuearr);
  263. // console.log(valuearr)
  264. }
  265. }
  266. for (var j = 0; j < res.dat.length; j++) {
  267. // valuearr.unshift(numobj['e' + (i + 1)]) // + elelist[elearr[i]].unit
  268. timearr.push(this.tiemtag(res.dat[j].uptime));
  269. }
  270. this.eqlistdata.unshift(timearr);
  271. console.log(this.eqlistdata);
  272. }
  273. },
  274. prev() {
  275. //上一页
  276. if (this.page != 1) {
  277. this.page--;
  278. this.historydata(this.newtime, this.oldtime);
  279. }
  280. },
  281. next() {
  282. //下一页
  283. if (this.page < this.pagesum) {
  284. this.page++;
  285. this.historydata(this.newtime, this.oldtime);
  286. }
  287. },
  288. tiemchange(e) {
  289. console.log(e);
  290. this.oldtime = +new Date(e.startDate) / 1000;
  291. this.newtime = +new Date(e.endDate) / 1000 + 16 * 60 * 60;
  292. this.getServerData(this.newtime, this.oldtime);
  293. this.historydata(this.newtime, this.oldtime);
  294. },
  295. timetab(e) {
  296. e = new Date(e * 1000);
  297. var year = e.getFullYear();
  298. var month =
  299. e.getMonth() + 1 < 10 ? '0' + (e.getMonth() + 1) : e.getMonth() + 1;
  300. var day = e.getDate() < 10 ? '0' + e.getDate() : e.getDate();
  301. var time = year + '/' + month + '/' + day;
  302. return time;
  303. },
  304. clickLeft() {
  305. uni.navigateBack({
  306. delta: 1,
  307. });
  308. },
  309. showColumn(id, xtitle, xinfo) {
  310. var _self = this;
  311. const ctx = uni.createCanvasContext(id, this);
  312. canvaColumnA = new uCharts({
  313. context: ctx,
  314. type: 'line',
  315. legend: {
  316. position: 'top',
  317. },
  318. fontSize: 11,
  319. background: '#FFFFFF',
  320. pixelRatio: 1,
  321. animation: true,
  322. dataLabel: false,
  323. categories: xtitle,
  324. series: xinfo,
  325. enableScroll: true, //开启图表拖拽功能
  326. xAxis: {
  327. disableGrid: true,
  328. type: 'grid',
  329. gridType: 'dash',
  330. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  331. scrollShow: true, //新增是否显示滚动条,默认false
  332. // scrollAlign: 'left', //滚动条初始位置
  333. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  334. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  335. },
  336. yAxis: {},
  337. width: _self.cWidth * 1,
  338. height: _self.cHeight * 1,
  339. extra: {
  340. line: {
  341. type: 'curve',
  342. },
  343. },
  344. });
  345. },
  346. showColumnb(id, xtitle, xinfo) {
  347. var _self = this;
  348. const ctx = uni.createCanvasContext(id, this);
  349. canvaColumnB = new uCharts({
  350. context: ctx,
  351. type: 'line',
  352. legend: {
  353. position: 'top',
  354. },
  355. fontSize: 11,
  356. background: '#FFFFFF',
  357. pixelRatio: 1,
  358. animation: true,
  359. dataLabel: false,
  360. categories: xtitle,
  361. series: xinfo,
  362. enableScroll: true, //开启图表拖拽功能
  363. xAxis: {
  364. disableGrid: true,
  365. type: 'grid',
  366. gridType: 'dash',
  367. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  368. scrollShow: true, //新增是否显示滚动条,默认false
  369. // scrollAlign: 'left', //滚动条初始位置
  370. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  371. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  372. },
  373. yAxis: {},
  374. width: _self.cWidth * 1,
  375. height: _self.cHeight * 1,
  376. extra: {
  377. line: {
  378. type: 'curve',
  379. },
  380. },
  381. });
  382. },
  383. touchLineA(e) {
  384. console.log(e);
  385. canvaColumnA.scrollStart(e);
  386. },
  387. moveLineA(e) {
  388. canvaColumnA.scroll(e);
  389. },
  390. touchEndLineA(e) {
  391. canvaColumnA.scrollEnd(e);
  392. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  393. canvaColumnA.showToolTip(e, {
  394. format: function (item, category) {
  395. return (
  396. category + ' ' + item.name + ':' + Number(item.data).toFixed(3)
  397. );
  398. },
  399. });
  400. },
  401. touchLineBb(e) {
  402. console.log(e);
  403. canvaColumnB.scrollStart(e);
  404. },
  405. moveLineBb(e) {
  406. canvaColumnB.scroll(e);
  407. },
  408. touchEndLineBb(e) {
  409. canvaColumnB.scrollEnd(e);
  410. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  411. canvaColumnB.showToolTip(e, {
  412. format: function (item, category) {
  413. return category + ' ' + item.name + ':' + item.data;
  414. },
  415. });
  416. },
  417. async newdata() {
  418. const res = await this.$myRequest({
  419. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  420. data: {
  421. device_type_id: 2,
  422. d_id: this.times.d_id,
  423. control_type: 'data',
  424. },
  425. });
  426. if (res) {
  427. uni.showToast({
  428. title: '刷新成功',
  429. duration: 2000,
  430. icon: 'none',
  431. });
  432. } else {
  433. uni.showToast({
  434. title: '刷新失败',
  435. duration: 2000,
  436. icon: 'none',
  437. });
  438. }
  439. },
  440. refresh() {
  441. //获取当前时间的数据
  442. this.newdata();
  443. },
  444. tiemtag(time) {
  445. var date = new Date(time * 1000);
  446. var year = date.getFullYear();
  447. var month =
  448. date.getMonth() + 1 < 10
  449. ? '0' + (date.getMonth() + 1)
  450. : date.getMonth() + 1;
  451. var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  452. var hours =
  453. date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  454. var minutes =
  455. date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  456. var seconds =
  457. date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  458. return (
  459. year +
  460. '-' +
  461. month +
  462. '-' +
  463. day +
  464. ' ' +
  465. hours +
  466. ':' +
  467. minutes +
  468. ':' +
  469. seconds
  470. );
  471. },
  472. },
  473. };
  474. </script>
  475. <style lang="scss">
  476. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  477. .shuju_one {
  478. position: relative;
  479. width: 90%;
  480. box-shadow: 0 0 10rpx #bcb9ca;
  481. padding-top: 20rpx;
  482. height: 550rpx;
  483. margin: 30rpx auto;
  484. .canvastishi {
  485. font-size: 32rpx;
  486. position: absolute;
  487. top: 50%;
  488. left: 50%;
  489. margin-left: -64rpx;
  490. margin-top: -21rpx;
  491. .dataloading:after {
  492. overflow: hidden;
  493. display: inline-block;
  494. vertical-align: bottom;
  495. animation: ellipsis 2s infinite;
  496. content: '\2026';
  497. }
  498. @keyframes ellipsis {
  499. from {
  500. width: 2px;
  501. }
  502. to {
  503. width: 15px;
  504. }
  505. }
  506. }
  507. .shuju_one_title {
  508. width: 70%;
  509. margin: 0 auto;
  510. display: flex;
  511. .tltle_text {
  512. width: 25%;
  513. border: 2rpx solid #b2b2b2;
  514. color: #57c878;
  515. text-align: center;
  516. font-size: 24rpx;
  517. height: 50rpx;
  518. line-height: 50rpx;
  519. }
  520. .title_text_color {
  521. width: 25%;
  522. border: 2rpx solid #57c878;
  523. background-color: #57c878;
  524. color: #fff;
  525. text-align: center;
  526. font-size: 24rpx;
  527. height: 50rpx;
  528. line-height: 50rpx;
  529. }
  530. }
  531. .qiun-columns {
  532. .qiun-charts {
  533. width: 650upx;
  534. height: 400upx;
  535. background-color: #ffffff;
  536. }
  537. .charts {
  538. width: 650upx;
  539. height: 400upx;
  540. background-color: #ffffff;
  541. }
  542. }
  543. }
  544. .shuju_two {
  545. top: 790rpx;
  546. }
  547. .selecttimes {
  548. width: 90%;
  549. box-shadow: 0 0 10rpx #bcb9ca;
  550. padding: 10rpx 20rpx;
  551. box-sizing: border-box;
  552. margin: 30rpx auto;
  553. .timesbox {
  554. display: flex;
  555. justify-content: space-around;
  556. image {
  557. width: 30rpx;
  558. height: 30rpx;
  559. margin-top: 6rpx;
  560. }
  561. .icon {
  562. color: #949494;
  563. text-align: right;
  564. margin-left: 30rpx;
  565. }
  566. }
  567. }
  568. .refresh {
  569. width: 160rpx;
  570. height: 50rpx;
  571. background-color: #57c878;
  572. color: #ffffff;
  573. line-height: 50rpx;
  574. text-align: center;
  575. box-shadow: 0 0 10rpx #bcb9ca;
  576. margin: 30rpx 5%;
  577. }
  578. .condition {
  579. display: flex;
  580. flex-wrap: wrap;
  581. width: 90%;
  582. box-shadow: 0 0 10rpx #bcb9ca;
  583. margin-bottom: 30rpx;
  584. margin: 30rpx auto;
  585. .scroll-X {
  586. width: 95%;
  587. margin: 20rpx auto;
  588. .tr {
  589. display: flex;
  590. overflow: hidden;
  591. .th,
  592. .td {
  593. display: inline-block;
  594. padding: 5rpx;
  595. width: 140rpx;
  596. text-align: center;
  597. height: 52rpx;
  598. line-height: 52rpx;
  599. // border: 2rpx solid #F1F1F1;
  600. }
  601. .th:first-child,
  602. .td:first-child {
  603. width: 300rpx;
  604. }
  605. .th:nth-last-child(1),
  606. .th:nth-last-child(2),
  607. .td:nth-last-child(1),
  608. .td:nth-last-child(2) {
  609. width: 200rpx;
  610. }
  611. }
  612. .tr:nth-child(2n-1) {
  613. background-color: #f5fff8;
  614. }
  615. .tr:first-child {
  616. background-color: #57c878;
  617. color: #fff;
  618. }
  619. }
  620. .pagenumber {
  621. display: flex;
  622. margin: 20rpx auto;
  623. button {
  624. width: 150rpx;
  625. height: 50rpx;
  626. line-height: 50rpx;
  627. font-size: 26rpx;
  628. text-align: center;
  629. background-color: #57c878;
  630. color: #ffffff;
  631. }
  632. .pagenumber_page {
  633. width: 150rpx;
  634. height: 50rpx;
  635. line-height: 50rpx;
  636. font-size: 26rpx;
  637. text-align: center;
  638. }
  639. }
  640. }
  641. ::v-deep .u-calendar__action {
  642. display: flex;
  643. justify-content: space-around;
  644. .u-calendar__action__text {
  645. line-height: 25px;
  646. }
  647. }
  648. </style>