bzyhistoryile.vue 13 KB

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