bzyhistoryile.vue 12 KB

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