elementdata.vue 18 KB

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