bzyhistoryile.vue 14 KB

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