bzyhistoryile.vue 13 KB

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