bzyhistoryile.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="历史数据"></uni-nav-bar>
  7. </view>
  8. <view class="shuju_one">
  9. <view class="shuju_one_title">
  10. <view :class="titleidnex==index?'title_text_color':'tltle_text'" v-for="(item,index) in titletext"
  11. :key="index" @click="changeindex(index)">
  12. {{item}}
  13. </view>
  14. </view>
  15. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  16. 暂无数据
  17. </view>
  18. <view class="canvastishi" v-if="dataloadingtf">
  19. <p class="dataloading">加载中</p>
  20. </view>
  21. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  22. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  23. disable-scroll=true
  24. :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  25. </view>
  26. <view class="refresh" @click="refresh">
  27. 刷 新
  28. </view>
  29. <view class="condition">
  30. <scroll-view scroll-x="true" class="scroll-X" scroll-top="0">
  31. <table class="table" v-if="$QueryPermission(265) ||$QueryPermission(304) ||$QueryPermission(313)">
  32. <tr class="tr">
  33. <th class="th" v-for="(item,index) in thdata" :key="index" v-if="(!isShowBwc && item.indexOf('保温仓') < 0) || isShowBwc">{{item}}</th>
  34. </tr>
  35. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="indexs" v-if="!forbidden">
  36. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  37. <td class="td">{{items.d_h_t.ds==0?"关":"开"}}</td>
  38. <td class="td">{{items.d_h_t.at}}</td>
  39. <td class="td">{{items.d_h_t.ah}}</td>
  40. <td class="td" v-if="isShowBwc">{{items.d_h_t.set_temp}}</td>
  41. <td class="td" v-if="isShowBwc">{{items.d_h_t.pre_temp}}</td>
  42. <td class="td">{{items.d_h_t.batStatus==0?"正常":"欠压"}}</td>
  43. <td class="td">{{items.d_h_t.rps==0?"正常":"雨控"}}</td>
  44. <td class="td">{{Circulation.work_sta.value[items.d_h_t.work_sta]}}</td>
  45. <td class="td">{{items.d_h_t.csq}}</td>
  46. <td class="td">{{items.d_h_t.current}}</td>
  47. <td class="td">{{items.d_h_t.vbat}}</td>
  48. <td class="td">{{items.d_h_t.dver}}</td>
  49. </tr>
  50. <tr class="tr" v-if="forbidden">
  51. <td class="td" v-for="item in 13" :key="item">暂无数据</td>
  52. </tr>
  53. </table>
  54. <table class="table" v-else>
  55. <tr class="tr">
  56. <th class="th" v-for="(item,index) in thdata2" :key="index" v-if="(!isShowBwc && item.indexOf('保温仓') < 0) || isShowBwc">{{item}}</th>
  57. </tr>
  58. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="indexs" v-if="!forbidden">
  59. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  60. <td class="td">{{items.d_h_t.ds==0?"关":"开"}}</td>
  61. <td class="td">{{items.d_h_t.at}}</td>
  62. <td class="td">{{items.d_h_t.ah}}</td>
  63. <td class="td" v-if="isShowBwc">{{items.d_h_t.set_temp}}</td>
  64. <td class="td" v-if="isShowBwc">{{items.d_h_t.pre_temp}}</td>
  65. <td class="td">{{items.d_h_t.batStatus==0?"正常":"欠压"}}</td>
  66. <td class="td">{{items.d_h_t.rps==0?"正常":"雨控"}}</td>
  67. <td class="td">{{Circulation.work_sta.value[items.d_h_t.work_sta]}}</td>
  68. <td class="td">{{items.d_h_t.dver}}</td>
  69. </tr>
  70. <tr class="tr" v-if="forbidden">
  71. <td class="td" v-for="item in 10" :key="item">暂无数据</td>
  72. </tr>
  73. </table>
  74. </scroll-view>
  75. <view class="pagenumber">
  76. <button @click="prev">上一页</button>
  77. <view class="pagenumber_page">
  78. 第 {{page}} 页
  79. </view>
  80. <view class="pagenumber_page">
  81. 共 {{pagesum}} 页
  82. </view>
  83. <button @click="next" :disabled="forbidden">下一页</button>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  91. import Circulation from "../../../../static/js/equipState_dict.json"
  92. var canvaColumnA = null;
  93. export default {
  94. data() {
  95. return {
  96. isShowBwc: false,
  97. styles: {
  98. // width: "650rpx",
  99. height: "400rpx"
  100. },
  101. d_id: '',
  102. start_time: "",
  103. end_time: "",
  104. historydatas: [],
  105. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  106. titleidnex: 0,
  107. device_id: '',
  108. page: 1,
  109. pagesum: 1,
  110. historylistdata: [],
  111. thdata: ["上报时间", "设备开关", "环境温度(°C)", "环境湿度(%)", "保温仓设定温度(°C)", "保温仓当前温度(°C)", "电池状态", "雨控状态", "工作状态",
  112. "信号强度", "电流(mA)", "电压(V)", "设备版本"
  113. ],
  114. thdata2: ["上报时间", "设备开关", "环境温度(°C)", "环境湿度(%)", "保温仓设定温度(°C)", "保温仓当前温度(°C)", "电池状态", "雨控状态", "工作状态",
  115. "设备版本"
  116. ],
  117. forbidden: false,
  118. canvastishiTF: false, //暂无数据提示
  119. dataloadingtf: true, //加载中提示
  120. cWidth: '400',
  121. cHeight: '400',
  122. pixelRatio: 1,
  123. Circulation:Circulation
  124. }
  125. },
  126. methods: {
  127. //forecast.worm_lamp.device_polyline_data 历史数据折线图
  128. // device_type_id 必传(string) 设备类型 3虫情测报灯 7孢子仪 4智能性诱 2杀虫灯 9糖醋测报灯 10测报灯rtu
  129. // d_id 必传 设备id
  130. // start_time 非必传(string 时间戳) 开始时间 (用于时间搜索)
  131. // end_time
  132. async history() {
  133. this.dataloadingtf = true
  134. const res = await this.$myRequest({
  135. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  136. data: {
  137. device_type_id: 7,
  138. d_id: this.d_id,
  139. start_time: parseInt(this.start_time / 1000),
  140. end_time: parseInt(this.end_time / 1000)
  141. }
  142. })
  143. this.dataloadingtf = false
  144. console.log(res)
  145. this.historydatas = res
  146. console.log(this.historydatas)
  147. if (this.historydatas.length == 0) {
  148. this.canvastishiTF = false
  149. } else {
  150. this.canvastishiTF = true
  151. var arr1 = []
  152. var arr2 = []
  153. var arr3 = []
  154. var xtitle = []
  155. for (var i = 0; i < res.length; i++) {
  156. var times = new Date(res[i].addtime * 1000)
  157. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" +
  158. times.getMinutes())
  159. arr1.push(res[i].temperature == "" ? "0" : res[i].temperature)
  160. arr2.push(res[i].humidity == "" ? "0" : res[i].humidity)
  161. if(res[i].others) {
  162. arr3.push(res[i].others)
  163. } else {
  164. if(res[i].others == "") {
  165. arr3.push(0)
  166. }
  167. }
  168. }
  169. var obj = [{
  170. name: '温度',
  171. data: arr1,
  172. color: '#00E29D'
  173. }, {
  174. name: '湿度',
  175. data: arr2,
  176. color: '#6CBBFF'
  177. }]
  178. if(arr3.length > 0) {
  179. obj.push({
  180. name: '保温仓温度',
  181. data: arr3,
  182. color: '#FF3F3F'
  183. })
  184. }
  185. this.showColumn("canvasColumnA", xtitle, obj)
  186. }
  187. },
  188. //forecast.worm_lamp.device_history_data历史数据列表
  189. async historylist() {
  190. const res = await this.$myRequest({
  191. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  192. data: {
  193. device_type_id: 7,
  194. device_id: this.device_id,
  195. start_time: parseInt(this.start_time / 1000),
  196. end_time: parseInt(this.end_time / 1000),
  197. page: this.page
  198. }
  199. })
  200. this.historylistdata = res.data
  201. this.pagesum = Math.ceil(res.counts / 10) || 1
  202. if (res.data.length == 0) {
  203. this.forbidden = true
  204. console.log(res.data.length)
  205. } else {
  206. if(res.data[0].d_h_t.set_temp) {
  207. this.isShowBwc = true
  208. } else {
  209. this.isShowBwc = false;
  210. }
  211. this.forbidden = false
  212. console.log(res.data.length)
  213. }
  214. },
  215. changeindex(index) {
  216. this.titleidnex = index
  217. var now = new Date()
  218. this.$forceUpdate()
  219. if (index == 0) {
  220. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  221. this.history()
  222. this.historylist()
  223. } else if (index == 1) {
  224. var oldtime = now.setMonth(now.getMonth() - 1)
  225. this.start_time = parseInt(oldtime)
  226. this.history()
  227. this.historylist()
  228. } else if (index == 2) {
  229. var oldtime = now.setMonth(now.getMonth() - 6)
  230. this.start_time = parseInt(oldtime)
  231. this.history()
  232. this.historylist()
  233. } else if (index == 3) {
  234. var oldtime = now.setFullYear(now.getFullYear() - 1)
  235. this.start_time = parseInt(oldtime)
  236. this.history()
  237. this.historylist()
  238. }
  239. },
  240. prev() { //上一页
  241. if (this.page > 1) {
  242. this.page--
  243. this.historylist()
  244. }
  245. },
  246. next() { //下一页
  247. if (this.page < this.pagesum) {
  248. this.page++
  249. this.historylist()
  250. }
  251. },
  252. clickLeft() {
  253. uni.navigateBack({
  254. delta: 1
  255. })
  256. },
  257. showColumn(id, xtitle, xinfo) {
  258. var _self = this
  259. canvaColumnA = new uCharts({
  260. canvasId: id,
  261. type: 'line',
  262. legend: {
  263. position: "top"
  264. },
  265. fontSize: 11,
  266. background: '#FFFFFF',
  267. pixelRatio: 1,
  268. animation: true,
  269. dataLabel: false,
  270. categories: xtitle,
  271. series: xinfo,
  272. enableScroll: true, //开启图表拖拽功能
  273. xAxis: {
  274. disableGrid: true,
  275. type: 'grid',
  276. gridType: 'dash',
  277. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  278. scrollShow: true, //新增是否显示滚动条,默认false
  279. // scrollAlign: 'left', //滚动条初始位置
  280. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  281. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  282. },
  283. yAxis: {},
  284. width: _self.cWidth * 1,
  285. height: _self.cHeight * 1,
  286. extra: {
  287. line: {
  288. type: 'curve'
  289. }
  290. }
  291. });
  292. },
  293. touchLineA(e) {
  294. console.log(e)
  295. canvaColumnA.scrollStart(e);
  296. },
  297. moveLineA(e) {
  298. canvaColumnA.scroll(e);
  299. },
  300. touchEndLineA(e) {
  301. canvaColumnA.scrollEnd(e);
  302. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  303. canvaColumnA.showToolTip(e, {
  304. format: function(item, category) {
  305. return category + ' ' + item.name + ':' + item.data
  306. }
  307. });
  308. },
  309. async newdata() {
  310. const res = await this.$myRequest({
  311. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  312. data: {
  313. device_type_id: 7,
  314. d_id: this.d_id,
  315. control_type: "data"
  316. }
  317. })
  318. if (res) {
  319. uni.showToast({
  320. title: '刷新成功',
  321. duration: 2000,
  322. icon: "none"
  323. });
  324. } else {
  325. uni.showToast({
  326. title: '刷新失败',
  327. duration: 2000,
  328. icon: "none"
  329. });
  330. }
  331. },
  332. refresh() { //获取当前时间的数据
  333. this.newdata()
  334. },
  335. },
  336. onLoad(option) {
  337. this.d_id = option.d_id
  338. this.device_id = option.device_id
  339. this.cWidth = uni.upx2px(650);
  340. this.cHeight = uni.upx2px(500);
  341. },
  342. onShow() {
  343. this.end_time = +new Date()
  344. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  345. setTimeout(() => {
  346. this.history()
  347. this.historylist()
  348. }, 1000)
  349. },
  350. onPullDownRefresh() {
  351. console.log('refresh');
  352. this.this.historydatas = []
  353. this.this.historylistdata = []
  354. this.history()
  355. this.historylist()
  356. setTimeout(function() {
  357. uni.stopPullDownRefresh();
  358. }, 1000);
  359. }
  360. }
  361. </script>
  362. <style lang="scss">
  363. .shuju_one,
  364. .shuju_two {
  365. position: absolute;
  366. top: 54px;
  367. width: 90%;
  368. left: 5%;
  369. box-shadow: 0 0 10rpx #bcb9ca;
  370. padding-top: 20rpx;
  371. height: 550rpx;
  372. .canvastishi {
  373. font-size: 32rpx;
  374. position: absolute;
  375. top: 50%;
  376. left: 50%;
  377. margin-left: -64rpx;
  378. margin-top: -21rpx;
  379. .dataloading:after {
  380. overflow: hidden;
  381. display: inline-block;
  382. vertical-align: bottom;
  383. animation: ellipsis 2s infinite;
  384. content: "\2026";
  385. }
  386. @keyframes ellipsis {
  387. from {
  388. width: 2px;
  389. }
  390. to {
  391. width: 15px;
  392. }
  393. }
  394. }
  395. .shuju_one_title {
  396. width: 70%;
  397. margin: 0 auto;
  398. display: flex;
  399. .tltle_text {
  400. width: 25%;
  401. border: 2rpx solid #B2B2B2;
  402. color: #57c878;
  403. text-align: center;
  404. font-size: 24rpx;
  405. height: 50rpx;
  406. line-height: 50rpx;
  407. }
  408. .title_text_color {
  409. width: 25%;
  410. border: 2rpx solid #57c878;
  411. background-color: #57c878;
  412. color: #fff;
  413. text-align: center;
  414. font-size: 24rpx;
  415. height: 50rpx;
  416. line-height: 50rpx;
  417. }
  418. }
  419. }
  420. .refresh {
  421. position: absolute;
  422. top: 700rpx;
  423. left: 5%;
  424. width: 160rpx;
  425. height: 50rpx;
  426. background-color: #57c878;
  427. color: #FFFFFF;
  428. line-height: 50rpx;
  429. text-align: center;
  430. }
  431. .condition {
  432. position: absolute;
  433. top: 770rpx;
  434. display: flex;
  435. flex-wrap: wrap;
  436. width: 90%;
  437. left: 5%;
  438. box-shadow: 0 0 10rpx #bcb9ca;
  439. margin-bottom: 30rpx;
  440. .scroll-X {
  441. width: 95%;
  442. margin: 20rpx auto;
  443. .table {
  444. width: 1672px;
  445. }
  446. .tr {
  447. display: flex;
  448. overflow: hidden;
  449. .th,
  450. .td {
  451. display: inline-block;
  452. padding: 5rpx;
  453. width: 300rpx;
  454. text-align: center;
  455. height: 52rpx;
  456. line-height: 52rpx;
  457. border: 2rpx solid #F1F1F1;
  458. }
  459. .th:first-child,
  460. .td:first-child {
  461. width: 300rpx;
  462. }
  463. }
  464. .tr:nth-child(2n-1) {
  465. background-color: #f5fff8;
  466. }
  467. .tr:first-child {
  468. background-color: #57c878;
  469. color: #fff;
  470. }
  471. }
  472. .pagenumber {
  473. display: flex;
  474. margin: 20rpx auto;
  475. button {
  476. width: 150rpx;
  477. height: 50rpx;
  478. line-height: 50rpx;
  479. font-size: 26rpx;
  480. text-align: center;
  481. background-color: #57c878;
  482. color: #FFFFFF;
  483. margin: 0 10rpx;
  484. }
  485. .pagenumber_page {
  486. width: 100rpx;
  487. height: 50rpx;
  488. line-height: 50rpx;
  489. font-size: 26rpx;
  490. text-align: center;
  491. }
  492. }
  493. }
  494. </style>