bzyhistoryile.vue 11 KB

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