historydatas.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="timeandtype">
  5. <view class="timebox">
  6. <view class="firsttime" @click="timeshow = true">
  7. <view class="" v-if="start_time != ''">
  8. {{
  9. ((start_time == '' ? '请选择开始时间' : start_time) / 1000)
  10. | timeFormat()
  11. }}
  12. </view>
  13. <view class="" v-else>
  14. {{ start_time == '' ? '请选择开始时间' : start_time }}
  15. </view>
  16. </view>
  17. <view class="jiange"> - </view>
  18. <view class="endtime" @click="timeshow = true">
  19. <view class="" v-if="end_time != ''">
  20. {{
  21. ((end_time == '' ? '请选择结束时间' : end_time) / 1000)
  22. | timeFormat()
  23. }}
  24. </view>
  25. <view class="" v-else>
  26. {{ end_time == '' ? '请选择结束时间' : end_time }}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="shuju_one">
  32. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  33. 暂无数据
  34. </view>
  35. <view class="canvastishi" v-if="dataloadingtf">
  36. <p class="dataloading">加载中</p>
  37. </view>
  38. <canvas
  39. v-if="canvastishiTF"
  40. canvas-id="canvasColumnA"
  41. id="canvasColumnA"
  42. class="charts"
  43. @touchstart="touchLineA($event)"
  44. @touchmove="moveLineA($event)"
  45. @touchend="touchEndLineA($event)"
  46. disable-scroll="true"
  47. :style="{
  48. width: cWidth * pixelRatio + 'px',
  49. height: cHeight * pixelRatio + 'px',
  50. transform: 'scale(' + 1 / pixelRatio + ')',
  51. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  52. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  53. }"
  54. ></canvas>
  55. </view>
  56. <view class="refresh" @click="refresh"> 刷 新 </view>
  57. <view class="condition">
  58. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  59. <table class="table" v-if="$QueryPermission(266)">
  60. <tr class="tr">
  61. <th class="th" v-for="(item, index) in thdata" :key="'a' + index">
  62. {{ item }}
  63. </th>
  64. </tr>
  65. <tr
  66. class="tr"
  67. v-for="(items, indexs) in historylistdata"
  68. :key="'b' + indexs"
  69. v-if="!forbidden"
  70. >
  71. <td class="td">{{ items.xy_addtime | timeFormat() }}</td>
  72. <td class="td">{{ items.at == '' ? '0' : items.at }}</td>
  73. <td class="td">{{ items.ah == '' ? '0' : items.ah }}</td>
  74. <!-- <td class="td">{{items.warn==""?"0":items.warn}}</td> -->
  75. <td class="td">{{ items.b_V == '' ? '0' : items.b_V }}</td>
  76. <td class="td">{{ items.b_c == '' ? '0' : items.b_c }}</td>
  77. <td class="td">{{ items.p_v == '' ? '0' : items.p_v }}</td>
  78. <td class="td">{{ items.p_c == '' ? '0' : items.p_c }}</td>
  79. </tr>
  80. <tr class="tr" v-if="forbidden">
  81. <td class="td" v-for="item in 8">暂无数据</td>
  82. </tr>
  83. </table>
  84. <table class="thdata2" v-else>
  85. <tr class="tr">
  86. <th
  87. class="th"
  88. v-for="(item, index) in thdata2"
  89. :key="'a' + index"
  90. >
  91. {{ item }}
  92. </th>
  93. </tr>
  94. <tr
  95. class="tr"
  96. v-for="(items, indexs) in historylistdata"
  97. :key="'b' + indexs"
  98. v-if="!forbidden"
  99. >
  100. <td class="td">{{ items.xy_addtime | timeFormat() }}</td>
  101. <td class="td">{{ items.at == '' ? '0' : items.at }}</td>
  102. <td class="td">{{ items.ah == '' ? '0' : items.ah }}</td>
  103. <!-- <td class="td">{{items.warn==""?"--":items.warn}}</td> -->
  104. </tr>
  105. <tr class="tr" v-if="forbidden">
  106. <td class="td" v-for="item in 4">暂无数据</td>
  107. </tr>
  108. </table>
  109. </scroll-view>
  110. <view class="pagenumber">
  111. <button @click="prev">上一页</button>
  112. <view class="pagenumber_page"> 第 {{ page }} 页 </view>
  113. <view class="pagenumber_page"> 共 {{ pagesum }} 页 </view>
  114. <button @click="next" :disabled="forbidden">下一页</button>
  115. </view>
  116. </view>
  117. </view>
  118. <u-calendar
  119. v-model="timeshow"
  120. :mode="mode"
  121. @change="timechange"
  122. ></u-calendar>
  123. </view>
  124. </template>
  125. <script>
  126. import uCharts from '../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  127. var canvaColumnA = null;
  128. export default {
  129. data() {
  130. return {
  131. styles: {
  132. // width: "650rpx",
  133. height: '400rpx',
  134. },
  135. d_id: '',
  136. start_time: '',
  137. end_time: '',
  138. historydatas: [],
  139. titletext: ['24小时', '近一个月', '近半年', '近一年'],
  140. titleidnex: 0,
  141. device_id: '',
  142. page: 1,
  143. historylistdata: [],
  144. thdata: [
  145. '上报时间',
  146. '环境温度(°C)',
  147. '环境湿度(%)',
  148. '电池电压',
  149. '电池电流',
  150. '太阳能板电压',
  151. '太阳能板电流',
  152. ],
  153. thdata2: ['上报时间', '环境温度(°C)', '环境湿度(%)'],
  154. forbidden: false,
  155. cWidth: '400',
  156. cHeight: '400',
  157. pixelRatio: 1,
  158. canvastishiTF: false, //暂无数据提示
  159. dataloadingtf: true, //加载中提示
  160. pagesum: 1,
  161. worms: [],
  162. timeshow: false,
  163. mode: 'range',
  164. device_code: 0,
  165. };
  166. },
  167. methods: {
  168. async Chistory() {
  169. //历史数据列表折线图
  170. this.dataloadingtf = true;
  171. const res = await this.$myRequest({
  172. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  173. data: {
  174. device_id: this.device_id,
  175. start_time: parseInt(this.start_time / 1000),
  176. end_time: parseInt(this.end_time / 1000),
  177. status: 'pest',
  178. device_code: this.device_code,
  179. },
  180. });
  181. this.dataloadingtf = false;
  182. this.worms = res;
  183. console.log(this.worms);
  184. if (this.worms.data.length == 0) {
  185. this.canvastishiTF = false;
  186. } else {
  187. this.canvastishiTF = true;
  188. var arr3 = [];
  189. var xtitle = [];
  190. for (var i = 0; i < res.data.length; i++) {
  191. xtitle.push(res.data[i].xy_addtime);
  192. }
  193. for (var j = 0; j < this.worms.data.length; j++) {
  194. arr3.push(
  195. this.worms.data[j].pest_num == ''
  196. ? '0'
  197. : this.worms.data[j].pest_num
  198. );
  199. }
  200. console.log(arr3);
  201. this.$nextTick(() => {
  202. var obj = [
  203. {
  204. name: '诱虫次数',
  205. data: arr3,
  206. color: '#ff0000',
  207. },
  208. ];
  209. this.showColumn('canvasColumnA', xtitle, obj);
  210. });
  211. }
  212. },
  213. //forecast.worm_lamp.device_history_data历史数据列表
  214. async historylist() {
  215. //历史数据列表
  216. const res = await this.$myRequest({
  217. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_history',
  218. data: {
  219. device_id: this.device_id,
  220. start_time: parseInt(this.start_time / 1000),
  221. end_time: parseInt(this.end_time / 1000),
  222. page: this.page,
  223. device_code: this.device_code,
  224. },
  225. });
  226. this.historylistdata = res.data;
  227. console.log(res.data);
  228. this.pagesum = Math.ceil(res.nums / 10) || 1;
  229. if (res.data.length == 0) {
  230. this.forbidden = true;
  231. } else {
  232. this.forbidden = false;
  233. }
  234. console.log(this.historylistdata);
  235. },
  236. // forecast.send_control.get_device_config 获取当前时间的数据
  237. async newdata() {
  238. const res = await this.$myRequest({
  239. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_mqtt',
  240. data: {
  241. d_id: this.d_id,
  242. },
  243. });
  244. if (res) {
  245. uni.showToast({
  246. title: '刷新成功',
  247. duration: 2000,
  248. icon: 'none',
  249. });
  250. } else {
  251. uni.showToast({
  252. title: '刷新失败',
  253. duration: 2000,
  254. icon: 'none',
  255. });
  256. }
  257. },
  258. refresh() {
  259. //获取当前时间的数据
  260. this.newdata();
  261. },
  262. prev() {
  263. //上一页
  264. if (this.page > 1) {
  265. this.page--;
  266. this.historylist();
  267. }
  268. },
  269. next() {
  270. //下一页
  271. if (this.page < this.pagesum) {
  272. this.page++;
  273. this.historylist();
  274. }
  275. },
  276. clickLeft() {
  277. uni.navigateBack({
  278. delta: 1,
  279. });
  280. },
  281. showColumn(id, xtitle, xinfo) {
  282. var _self = this;
  283. const ctx = uni.createCanvasContext(id, this);
  284. canvaColumnA = new uCharts({
  285. context: ctx,
  286. type: 'line',
  287. legend: {
  288. position: 'top',
  289. },
  290. fontSize: 10,
  291. background: '#FFFFFF',
  292. pixelRatio: 1,
  293. animation: true,
  294. dataLabel: false,
  295. categories: xtitle,
  296. series: xinfo,
  297. enableScroll: true, //开启图表拖拽功能
  298. xAxis: {
  299. disableGrid: true,
  300. type: 'grid',
  301. gridType: 'dash',
  302. itemCount: 3, //x轴单屏显示数据的数量,默认为5个
  303. scrollShow: true, //新增是否显示滚动条,默认false
  304. // scrollAlign: 'left', //滚动条初始位置
  305. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  306. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  307. },
  308. yAxis: {
  309. gridType: 'dash',
  310. gridColor: '#CCCCCC',
  311. dashLength: 8,
  312. splitNumber: 5,
  313. format: (val) => {
  314. return val.toFixed(1);
  315. },
  316. },
  317. width: _self.cWidth * 1,
  318. height: _self.cHeight * 1,
  319. extra: {
  320. line: {
  321. type: 'curve',
  322. },
  323. },
  324. });
  325. },
  326. touchLineA(e) {
  327. console.log(e);
  328. canvaColumnA.scrollStart(e);
  329. },
  330. moveLineA(e) {
  331. canvaColumnA.scroll(e);
  332. },
  333. touchEndLineA(e) {
  334. canvaColumnA.scrollEnd(e);
  335. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  336. canvaColumnA.showToolTip(e, {
  337. format: function (item, category) {
  338. return category + ' ' + item.name + ':' + item.data;
  339. },
  340. });
  341. },
  342. closetime() {
  343. this.start_time = '';
  344. this.end_time = '';
  345. this.listpage = 1;
  346. this.Chistory();
  347. this.historylist();
  348. },
  349. timechange(e) {
  350. console.log(e);
  351. this.start_time = +new Date(e.startDate);
  352. this.end_time = +new Date(e.endDate);
  353. this.listpage = 1;
  354. this.Chistory();
  355. this.historylist();
  356. },
  357. },
  358. onLoad(option) {
  359. console.log(option);
  360. this.d_id = option.d_id;
  361. this.device_id = option.device_id;
  362. this.device_code = option.device_code;
  363. this.cWidth = uni.upx2px(650);
  364. this.cHeight = uni.upx2px(500);
  365. },
  366. onShow() {
  367. this.end_time = +new Date() + 1000;
  368. this.start_time = this.end_time - 24 * 60 * 60 * 1000 * 30;
  369. console.log(new Date(this.end_time), new Date(this.start_time));
  370. // this.history()
  371. this.Chistory();
  372. this.historylist();
  373. },
  374. onPullDownRefresh() {
  375. console.log('refresh');
  376. this.Chistory();
  377. this.historylist();
  378. setTimeout(function () {
  379. uni.stopPullDownRefresh();
  380. }, 1000);
  381. },
  382. };
  383. </script>
  384. <style lang="less">
  385. .timeandtype {
  386. // background-color: #F6F6FB;
  387. // padding: 20rpx;
  388. box-sizing: border-box;
  389. width: 90%;
  390. margin: 40rpx auto 0;
  391. .timebox {
  392. box-shadow: 0 0 10rpx #bcb9ca;
  393. display: flex;
  394. background-color: #fff;
  395. padding: 10px;
  396. border-top-right-radius: 5px;
  397. border-top-left-radius: 5px;
  398. .jiange {
  399. width: 5%;
  400. text-align: center;
  401. }
  402. .firsttime,
  403. .endtime {
  404. width: 45%;
  405. text-align: center;
  406. }
  407. }
  408. .warntypebox {
  409. display: flex;
  410. justify-content: space-between;
  411. background-color: #fff;
  412. padding: 10px;
  413. border-top: 1px solid #f6f6fb;
  414. border-bottom-right-radius: 5px;
  415. border-bottom-left-radius: 5px;
  416. }
  417. }
  418. .shuju_one,
  419. .shuju_two {
  420. // position: absolute;
  421. // top: 100px;
  422. // width: 90%;
  423. // left: 5%;
  424. width: 90%;
  425. margin: 40rpx auto;
  426. box-shadow: 0 0 10rpx #bcb9ca;
  427. padding-top: 20rpx;
  428. height: 550rpx;
  429. .canvastishi {
  430. font-size: 32rpx;
  431. position: absolute;
  432. top: 50%;
  433. left: 50%;
  434. margin-left: -64rpx;
  435. margin-top: -21rpx;
  436. .dataloading:after {
  437. overflow: hidden;
  438. display: inline-block;
  439. vertical-align: bottom;
  440. animation: ellipsis 2s infinite;
  441. content: '\2026';
  442. }
  443. @keyframes ellipsis {
  444. from {
  445. width: 2px;
  446. }
  447. to {
  448. width: 15px;
  449. }
  450. }
  451. }
  452. .shuju_one_title {
  453. width: 70%;
  454. margin: 0 auto;
  455. display: flex;
  456. .tltle_text {
  457. width: 25%;
  458. border: 2rpx solid #b2b2b2;
  459. color: #57c878;
  460. text-align: center;
  461. font-size: 24rpx;
  462. height: 50rpx;
  463. line-height: 50rpx;
  464. }
  465. .title_text_color {
  466. width: 25%;
  467. border: 2rpx solid #57c878;
  468. background-color: #57c878;
  469. color: #fff;
  470. text-align: center;
  471. font-size: 24rpx;
  472. height: 50rpx;
  473. line-height: 50rpx;
  474. }
  475. }
  476. }
  477. .refresh {
  478. width: 90%;
  479. // margin: 40rpx auto;
  480. margin-left: 5%;
  481. width: 160rpx;
  482. height: 50rpx;
  483. background-color: #57c878;
  484. color: #ffffff;
  485. line-height: 50rpx;
  486. text-align: center;
  487. }
  488. .condition {
  489. width: 90%;
  490. margin: 40rpx auto;
  491. display: flex;
  492. flex-wrap: wrap;
  493. width: 90%;
  494. box-shadow: 0 0 10rpx #bcb9ca;
  495. margin-bottom: 30rpx;
  496. .scroll-X {
  497. width: 95%;
  498. margin: 20rpx auto;
  499. .table {
  500. width: 1042px;
  501. }
  502. .tr {
  503. display: flex;
  504. overflow: hidden;
  505. .th,
  506. .td {
  507. display: inline-block;
  508. padding: 5rpx;
  509. width: 240rpx;
  510. text-align: center;
  511. height: 52rpx;
  512. line-height: 52rpx;
  513. }
  514. .th:first-child,
  515. .td:first-child {
  516. width: 300rpx;
  517. }
  518. }
  519. .tr:nth-child(2n-1) {
  520. background-color: #f5fff8;
  521. }
  522. .tr:first-child {
  523. background-color: #57c878;
  524. color: #fff;
  525. }
  526. }
  527. .pagenumber {
  528. display: flex;
  529. margin: 20rpx auto;
  530. button {
  531. width: 150rpx;
  532. height: 50rpx;
  533. line-height: 50rpx;
  534. font-size: 26rpx;
  535. text-align: center;
  536. background-color: #57c878;
  537. color: #ffffff;
  538. }
  539. .pagenumber_page {
  540. width: 100rpx;
  541. height: 50rpx;
  542. line-height: 50rpx;
  543. font-size: 26rpx;
  544. text-align: center;
  545. }
  546. }
  547. }
  548. ::v-deep .u-calendar__action {
  549. display: flex;
  550. justify-content: space-around;
  551. .u-calendar__action__text {
  552. line-height: 25px;
  553. }
  554. }
  555. </style>