thxyhisdata.vue 17 KB

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