thxyhisdata.vue 17 KB

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