bzyhistoryile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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)">
  32. <tr class="tr">
  33. <th class="th" v-for="(item,index) in thdata" :key="index">{{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">{{items.d_h_t.set_temp}}</td>
  41. <td class="td">{{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">{{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">{{items.d_h_t.set_temp}}</td>
  64. <td class="td">{{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. styles: {
  97. // width: "650rpx",
  98. height: "400rpx"
  99. },
  100. d_id: '',
  101. start_time: "",
  102. end_time: "",
  103. historydatas: [],
  104. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  105. titleidnex: 0,
  106. device_id: '',
  107. page: 1,
  108. pagesum: 1,
  109. historylistdata: [],
  110. thdata: ["上报时间", "设备开关", "环境温度(°C)", "环境湿度(%)", "保温仓设定温度(°C)", "保温仓当前温度(°C)", "电池状态", "雨控状态", "工作状态",
  111. "信号强度", "电流(mA)", "电压(V)", "设备版本"
  112. ],
  113. thdata2: ["上报时间", "设备开关", "环境温度(°C)", "环境湿度(%)", "保温仓设定温度(°C)", "保温仓当前温度(°C)", "电池状态", "雨控状态", "工作状态",
  114. "设备版本"
  115. ],
  116. forbidden: false,
  117. canvastishiTF: false, //暂无数据提示
  118. dataloadingtf: true, //加载中提示
  119. cWidth: '400',
  120. cHeight: '400',
  121. pixelRatio: 1,
  122. Circulation:Circulation
  123. }
  124. },
  125. methods: {
  126. //forecast.worm_lamp.device_polyline_data 历史数据折线图
  127. // device_type_id 必传(string) 设备类型 3虫情测报灯 7孢子仪 4智能性诱 2杀虫灯 9糖醋测报灯 10测报灯rtu
  128. // d_id 必传 设备id
  129. // start_time 非必传(string 时间戳) 开始时间 (用于时间搜索)
  130. // end_time
  131. async history() {
  132. this.dataloadingtf = true
  133. const res = await this.$myRequest({
  134. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  135. data: {
  136. device_type_id: 7,
  137. d_id: this.d_id,
  138. start_time: parseInt(this.start_time / 1000),
  139. end_time: parseInt(this.end_time / 1000)
  140. }
  141. })
  142. this.dataloadingtf = false
  143. console.log(res)
  144. this.historydatas = res
  145. console.log(this.historydatas)
  146. if (this.historydatas.length == 0) {
  147. this.canvastishiTF = false
  148. } else {
  149. this.canvastishiTF = true
  150. var arr1 = []
  151. var arr2 = []
  152. var arr3 = []
  153. var xtitle = []
  154. for (var i = 0; i < res.length; i++) {
  155. var times = new Date(res[i].addtime * 1000)
  156. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" +
  157. times.getMinutes())
  158. arr1.push(res[i].temperature == "" ? "0" : res[i].temperature)
  159. arr2.push(res[i].humidity == "" ? "0" : res[i].humidity)
  160. arr3.push(res[i].others == "" ? "0" : res[i].others)
  161. }
  162. var obj = [{
  163. name: '温度',
  164. data: arr1,
  165. color: '#00E29D'
  166. }, {
  167. name: '湿度',
  168. data: arr2,
  169. color: '#6CBBFF'
  170. }, {
  171. name: '保温仓温度',
  172. data: arr3,
  173. color: '#FF3F3F'
  174. }]
  175. this.showColumn("canvasColumnA", xtitle, obj)
  176. }
  177. },
  178. //forecast.worm_lamp.device_history_data历史数据列表
  179. async historylist() {
  180. const res = await this.$myRequest({
  181. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  182. data: {
  183. device_type_id: 7,
  184. device_id: this.device_id,
  185. start_time: parseInt(this.start_time / 1000),
  186. end_time: parseInt(this.end_time / 1000),
  187. page: this.page
  188. }
  189. })
  190. this.historylistdata = res.data
  191. this.pagesum = Math.ceil(res.counts / 10) || 1
  192. if (res.data.length == 0) {
  193. this.forbidden = true
  194. console.log(res.data.length)
  195. } else {
  196. this.forbidden = false
  197. console.log(res.data.length)
  198. }
  199. },
  200. changeindex(index) {
  201. this.titleidnex = index
  202. var now = new Date()
  203. this.$forceUpdate()
  204. if (index == 0) {
  205. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  206. this.history()
  207. this.historylist()
  208. } else if (index == 1) {
  209. var oldtime = now.setMonth(now.getMonth() - 1)
  210. this.start_time = parseInt(oldtime)
  211. this.history()
  212. this.historylist()
  213. } else if (index == 2) {
  214. var oldtime = now.setMonth(now.getMonth() - 6)
  215. this.start_time = parseInt(oldtime)
  216. this.history()
  217. this.historylist()
  218. } else if (index == 3) {
  219. var oldtime = now.setFullYear(now.getFullYear() - 1)
  220. this.start_time = parseInt(oldtime)
  221. this.history()
  222. this.historylist()
  223. }
  224. },
  225. prev() { //上一页
  226. if (this.page > 1) {
  227. this.page--
  228. this.historylist()
  229. }
  230. },
  231. next() { //下一页
  232. if (this.page < this.pagesum) {
  233. this.page++
  234. this.historylist()
  235. }
  236. },
  237. clickLeft() {
  238. uni.navigateBack({
  239. delta: 1
  240. })
  241. },
  242. showColumn(id, xtitle, xinfo) {
  243. var _self = this
  244. canvaColumnA = new uCharts({
  245. canvasId: id,
  246. type: 'line',
  247. legend: {
  248. position: "top"
  249. },
  250. fontSize: 11,
  251. background: '#FFFFFF',
  252. pixelRatio: 1,
  253. animation: true,
  254. dataLabel: false,
  255. categories: xtitle,
  256. series: xinfo,
  257. enableScroll: true, //开启图表拖拽功能
  258. xAxis: {
  259. disableGrid: true,
  260. type: 'grid',
  261. gridType: 'dash',
  262. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  263. scrollShow: true, //新增是否显示滚动条,默认false
  264. // scrollAlign: 'left', //滚动条初始位置
  265. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  266. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  267. },
  268. yAxis: {},
  269. width: _self.cWidth * 1,
  270. height: _self.cHeight * 1,
  271. extra: {
  272. line: {
  273. type: 'curve'
  274. }
  275. }
  276. });
  277. },
  278. touchLineA(e) {
  279. console.log(e)
  280. canvaColumnA.scrollStart(e);
  281. },
  282. moveLineA(e) {
  283. canvaColumnA.scroll(e);
  284. },
  285. touchEndLineA(e) {
  286. canvaColumnA.scrollEnd(e);
  287. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  288. canvaColumnA.showToolTip(e, {
  289. format: function(item, category) {
  290. return category + ' ' + item.name + ':' + item.data
  291. }
  292. });
  293. },
  294. async newdata() {
  295. const res = await this.$myRequest({
  296. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  297. data: {
  298. device_type_id: 7,
  299. d_id: this.d_id,
  300. control_type: "data"
  301. }
  302. })
  303. if (res) {
  304. uni.showToast({
  305. title: '刷新成功',
  306. duration: 2000,
  307. icon: "none"
  308. });
  309. } else {
  310. uni.showToast({
  311. title: '刷新失败',
  312. duration: 2000,
  313. icon: "none"
  314. });
  315. }
  316. },
  317. refresh() { //获取当前时间的数据
  318. this.newdata()
  319. },
  320. },
  321. onLoad(option) {
  322. this.d_id = option.d_id
  323. this.device_id = option.device_id
  324. this.cWidth = uni.upx2px(650);
  325. this.cHeight = uni.upx2px(500);
  326. },
  327. onShow() {
  328. this.end_time = +new Date()
  329. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  330. setTimeout(() => {
  331. this.history()
  332. this.historylist()
  333. }, 1000)
  334. },
  335. onPullDownRefresh() {
  336. console.log('refresh');
  337. this.this.historydatas = []
  338. this.this.historylistdata = []
  339. this.history()
  340. this.historylist()
  341. setTimeout(function() {
  342. uni.stopPullDownRefresh();
  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: #57c878;
  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 #57c878;
  396. background-color: #57c878;
  397. color: #fff;
  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: #57c878;
  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: 300rpx;
  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: #57c878;
  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>