bzyhistoryile.vue 12 KB

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