bzyhistoryile.vue 11 KB

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