thxyhisdata.vue 17 KB

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