bzyhistoryile.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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,index) in thdata" :key="index" v-if="(!isShowBwc && item.indexOf('保温仓') < 0) || isShowBwc">暂无数据</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,index) in thdata2" :key="index" v-if="(!isShowBwc && item.indexOf('保温仓') < 0) || isShowBwc">暂无数据</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. console.log(_self.cWidth, '_self.cWidth');
  260. const ctx = uni.createCanvasContext(id, this);
  261. canvaColumnA = new uCharts({
  262. context: ctx,
  263. type: 'line',
  264. legend: {
  265. position: "top"
  266. },
  267. fontSize: 11,
  268. background: '#FFFFFF',
  269. pixelRatio: 1,
  270. animation: true,
  271. dataLabel: false,
  272. categories: xtitle,
  273. series: xinfo,
  274. enableScroll: true, //开启图表拖拽功能
  275. xAxis: {
  276. disableGrid: true,
  277. type: 'grid',
  278. gridType: 'dash',
  279. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  280. scrollShow: true, //新增是否显示滚动条,默认false
  281. // scrollAlign: 'left', //滚动条初始位置
  282. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  283. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  284. },
  285. yAxis: {},
  286. width: _self.cWidth * 1,
  287. height: _self.cHeight * 1,
  288. extra: {
  289. line: {
  290. type: 'curve'
  291. }
  292. }
  293. });
  294. },
  295. touchLineA(e) {
  296. console.log(e)
  297. canvaColumnA.scrollStart(e);
  298. },
  299. moveLineA(e) {
  300. canvaColumnA.scroll(e);
  301. },
  302. touchEndLineA(e) {
  303. canvaColumnA.scrollEnd(e);
  304. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  305. canvaColumnA.showToolTip(e, {
  306. format: function(item, category) {
  307. return category + ' ' + item.name + ':' + item.data
  308. }
  309. });
  310. },
  311. async newdata() {
  312. const res = await this.$myRequest({
  313. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  314. data: {
  315. device_type_id: 7,
  316. d_id: this.d_id,
  317. control_type: "data"
  318. }
  319. })
  320. if (res) {
  321. uni.showToast({
  322. title: '刷新成功',
  323. duration: 2000,
  324. icon: "none"
  325. });
  326. } else {
  327. uni.showToast({
  328. title: '刷新失败',
  329. duration: 2000,
  330. icon: "none"
  331. });
  332. }
  333. },
  334. refresh() { //获取当前时间的数据
  335. this.newdata()
  336. },
  337. },
  338. onLoad(option) {
  339. this.d_id = option.d_id
  340. this.device_id = option.device_id
  341. this.cWidth = uni.upx2px(650);
  342. this.cHeight = uni.upx2px(500);
  343. },
  344. onShow() {
  345. this.end_time = +new Date()
  346. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  347. setTimeout(() => {
  348. this.history()
  349. this.historylist()
  350. }, 1000)
  351. },
  352. onPullDownRefresh() {
  353. console.log('refresh');
  354. this.this.historydatas = []
  355. this.this.historylistdata = []
  356. this.history()
  357. this.historylist()
  358. setTimeout(function() {
  359. uni.stopPullDownRefresh();
  360. }, 1000);
  361. }
  362. }
  363. </script>
  364. <style lang="scss">
  365. .shuju_one,
  366. .shuju_two {
  367. position: absolute;
  368. top: 54px;
  369. width: 90%;
  370. left: 5%;
  371. box-shadow: 0 0 10rpx #bcb9ca;
  372. padding-top: 20rpx;
  373. height: 550rpx;
  374. .canvastishi {
  375. font-size: 32rpx;
  376. position: absolute;
  377. top: 50%;
  378. left: 50%;
  379. margin-left: -64rpx;
  380. margin-top: -21rpx;
  381. .dataloading:after {
  382. overflow: hidden;
  383. display: inline-block;
  384. vertical-align: bottom;
  385. animation: ellipsis 2s infinite;
  386. content: "\2026";
  387. }
  388. @keyframes ellipsis {
  389. from {
  390. width: 2px;
  391. }
  392. to {
  393. width: 15px;
  394. }
  395. }
  396. }
  397. .shuju_one_title {
  398. width: 70%;
  399. margin: 0 auto;
  400. display: flex;
  401. .tltle_text {
  402. width: 25%;
  403. border: 2rpx solid #B2B2B2;
  404. color: #57c878;
  405. text-align: center;
  406. font-size: 24rpx;
  407. height: 50rpx;
  408. line-height: 50rpx;
  409. }
  410. .title_text_color {
  411. width: 25%;
  412. border: 2rpx solid #57c878;
  413. background-color: #57c878;
  414. color: #fff;
  415. text-align: center;
  416. font-size: 24rpx;
  417. height: 50rpx;
  418. line-height: 50rpx;
  419. }
  420. }
  421. }
  422. .refresh {
  423. position: absolute;
  424. top: 700rpx;
  425. left: 5%;
  426. width: 160rpx;
  427. height: 50rpx;
  428. background-color: #57c878;
  429. color: #FFFFFF;
  430. line-height: 50rpx;
  431. text-align: center;
  432. }
  433. .condition {
  434. position: absolute;
  435. top: 770rpx;
  436. display: flex;
  437. flex-wrap: wrap;
  438. width: 90%;
  439. left: 5%;
  440. box-shadow: 0 0 10rpx #bcb9ca;
  441. margin-bottom: 30rpx;
  442. .scroll-X {
  443. width: 95%;
  444. margin: 20rpx auto;
  445. .table {
  446. width: 1672px;
  447. }
  448. .tr {
  449. display: flex;
  450. overflow: hidden;
  451. .th,
  452. .td {
  453. display: inline-block;
  454. padding: 5rpx;
  455. width: 300rpx;
  456. text-align: center;
  457. height: 52rpx;
  458. line-height: 52rpx;
  459. border: 2rpx solid #F1F1F1;
  460. }
  461. .th:first-child,
  462. .td:first-child {
  463. width: 350rpx;
  464. }
  465. }
  466. .tr:nth-child(2n-1) {
  467. background-color: #f5fff8;
  468. }
  469. .tr:first-child {
  470. background-color: #57c878;
  471. color: #fff;
  472. }
  473. }
  474. .pagenumber {
  475. display: flex;
  476. margin: 20rpx auto;
  477. button {
  478. width: 150rpx;
  479. height: 50rpx;
  480. line-height: 50rpx;
  481. font-size: 26rpx;
  482. text-align: center;
  483. background-color: #57c878;
  484. color: #FFFFFF;
  485. margin: 0 10rpx;
  486. }
  487. .pagenumber_page {
  488. width: 100rpx;
  489. height: 50rpx;
  490. line-height: 50rpx;
  491. font-size: 26rpx;
  492. text-align: center;
  493. }
  494. }
  495. }
  496. </style>