thxyhisdata.vue 17 KB

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