historyfile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 && !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-top="0" scroll-x="true" class="scroll-X">
  29. <table class="table">
  30. <tr class="tr">
  31. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  32. </tr>
  33. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  34. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  35. <td class="td">{{items.d_h_t.at==""||items.d_h_t.at=="25"||items.d_h_t.at=="25.0"||items.d_h_t.at=="2.5"?items.d_h_t.new_tem:items.d_h_t.at}}</td>
  36. <td class="td">{{items.d_h_t.ah==""||items.d_h_t.ah=="30"||items.d_h_t.ah=="30.0"||items.d_h_t.ah=="3.0"?items.d_h_t.new_hum:items.d_h_t.ah}}</td>
  37. <td class="td">{{items.d_h_t.hrt}}</td>
  38. <td class="td">{{items.d_h_t.rps==0?"正常":"雨控"}}</td>
  39. <td class="td">{{items.d_h_t.tps==0?"正常":"温控"}}</td>
  40. <td class="td">{{items.d_h_t.lps==0?"正常":"光控"}}</td>
  41. <td class="td">{{items.d_h_t.dg}}</td>
  42. <td class="td">{{items.d_h_t.csq}}</td>
  43. <td class="td">{{items.d_h_t.current}}</td>
  44. <td class="td">{{items.d_h_t.vbat}}</td>
  45. <td class="td">{{items.d_h_t.lng}}</td>
  46. <td class="td">{{items.d_h_t.lat}}</td>
  47. </tr>
  48. <tr class="tr" v-if="forbidden">
  49. <td class="td" v-for="item in 13">暂无数据</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. historylistdata: [],
  86. thdata: ["上报时间", "环境温度(°C)", "环境湿度(%)", "加热仓温度(°C)", "雨控状态", "温控状态", "光控状态", "灯管状态", "信号强度", "电流(mA)", "电压(V)",
  87. "经度", "纬度"
  88. ],
  89. forbidden: false,
  90. cWidth: '400',
  91. cHeight: '400',
  92. pixelRatio: 1,
  93. canvastishiTF: false,//暂无数据提示
  94. dataloadingtf:true,//加载中提示
  95. pagesum: 1
  96. }
  97. },
  98. methods: {
  99. async history() { //历史数据列表折线图
  100. this.dataloadingtf = true
  101. const res = await this.$myRequest({
  102. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  103. data: {
  104. device_type_id: 3,
  105. d_id: this.d_id,
  106. start_time: parseInt(this.start_time / 1000),
  107. end_time: parseInt(this.end_time / 1000)
  108. }
  109. })
  110. this.dataloadingtf = false
  111. this.historydatas = res
  112. console.log(this.historydatas)
  113. if (this.historydatas.length == 0) {
  114. this.canvastishiTF = false
  115. } else {
  116. this.canvastishiTF = true
  117. var arr1 = []
  118. var arr2 = []
  119. var arr3 = []
  120. var xtitle = []
  121. for (var i = 0; i < res.length; i++) {
  122. var times = new Date(res[i].addtime * 1000)
  123. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  124. arr1.unshift(res[i].temperature == "" ? "0" : res[i].temperature)
  125. arr2.unshift(res[i].humidity == "" ? "0" : res[i].humidity)
  126. arr3.unshift(res[i].others == "" ? "0" : res[i].others)
  127. }
  128. // console.log(arr1)
  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. this.historylistdata=[]
  148. const res = await this.$myRequest({
  149. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  150. data: {
  151. device_type_id: 3,
  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. for (var i = 0; i < this.historylistdata.length; i++) {
  168. if (Number(this.historylistdata[i].d_h_t.ws) == 0) {
  169. this.historylistdata[i].d_h_t.dg = "待机"
  170. } else if (Number(this.historylistdata[i].d_h_t.ws) == 1) {
  171. if (Number(this.historylistdata[i].d_h_t.lamp) == 0) {
  172. this.historylistdata[i].d_h_t.dg = "工作"
  173. } else if (Number(this.historylistdata[i].d_h_t.lamp) == 1) {
  174. this.historylistdata[i].d_h_t.dg = "异常"
  175. }
  176. }
  177. }
  178. console.log(this.historylistdata)
  179. },
  180. // forecast.send_control.get_device_config 获取当前时间的数据
  181. async newdata() {
  182. const res = await this.$myRequest({
  183. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  184. data: {
  185. device_type_id: 3,
  186. d_id: this.d_id,
  187. control_type: "data"
  188. }
  189. })
  190. if(res){
  191. uni.showToast({
  192. title: '刷新成功',
  193. duration: 2000,
  194. icon: "none"
  195. });
  196. this.historylist()
  197. }else{
  198. uni.showToast({
  199. title: '刷新失败',
  200. duration: 2000,
  201. icon: "none"
  202. });
  203. }
  204. },
  205. refresh() { //获取当前时间的数据
  206. this.newdata()
  207. },
  208. changeindex(index) {
  209. this.titleidnex = index
  210. var now = new Date()
  211. this.$forceUpdate()
  212. if (index == 0) {
  213. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  214. this.history()
  215. this.historylist()
  216. } else if (index == 1) {
  217. var oldtime = now.setMonth(now.getMonth() - 1)
  218. this.start_time = parseInt(oldtime)
  219. this.history()
  220. this.historylist()
  221. } else if (index == 2) {
  222. var oldtime = now.setMonth(now.getMonth() - 6)
  223. this.start_time = parseInt(oldtime)
  224. this.history()
  225. this.historylist()
  226. } else if (index == 3) {
  227. var oldtime = now.setFullYear(now.getFullYear() - 1)
  228. this.start_time = parseInt(oldtime)
  229. this.history()
  230. this.historylist()
  231. }
  232. },
  233. prev() { //上一页
  234. if (this.page > 1) {
  235. this.page--
  236. this.historylist()
  237. }
  238. },
  239. next() { //下一页
  240. if(this.page < this.pagesum){
  241. this.page++
  242. this.historylist()
  243. }
  244. },
  245. clickLeft() {
  246. uni.navigateBack({
  247. delta: 1
  248. })
  249. },
  250. showColumn(id, xtitle, xinfo) {
  251. var _self = this
  252. canvaColumnA = new uCharts({
  253. canvasId: id,
  254. type: 'line',
  255. legend: {
  256. position: "top"
  257. },
  258. fontSize: 11,
  259. background: '#FFFFFF',
  260. pixelRatio: 1,
  261. animation: true,
  262. dataLabel: false,
  263. categories: xtitle,
  264. series: xinfo,
  265. enableScroll: true, //开启图表拖拽功能
  266. xAxis: {
  267. disableGrid: true,
  268. type: 'grid',
  269. gridType: 'dash',
  270. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  271. scrollShow: true, //新增是否显示滚动条,默认false
  272. // scrollAlign: 'left', //滚动条初始位置
  273. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  274. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  275. },
  276. yAxis: {},
  277. width: _self.cWidth * 1,
  278. height: _self.cHeight * 1,
  279. extra: {
  280. line: {
  281. type: 'curve'
  282. }
  283. }
  284. });
  285. },
  286. touchLineA(e) {
  287. console.log(e)
  288. canvaColumnA.scrollStart(e);
  289. },
  290. moveLineA(e) {
  291. canvaColumnA.scroll(e);
  292. },
  293. touchEndLineA(e) {
  294. canvaColumnA.scrollEnd(e);
  295. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  296. canvaColumnA.showToolTip(e, {
  297. format: function(item, category) {
  298. return category + ' ' + item.name + ':' + item.data
  299. }
  300. });
  301. },
  302. },
  303. onLoad(option) {
  304. this.d_id = option.d_id
  305. this.device_id = option.device_id
  306. this.cWidth = uni.upx2px(650);
  307. this.cHeight = uni.upx2px(500);
  308. },
  309. onShow(){
  310. this.end_time = +new Date() + 1000
  311. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  312. this.history()
  313. this.historylist()
  314. },
  315. onPullDownRefresh() {
  316. this.history()
  317. this.historylist()
  318. setTimeout(() => {
  319. uni.stopPullDownRefresh()
  320. }, 1000)
  321. },
  322. }
  323. </script>
  324. <style lang="scss">
  325. .shuju_one,
  326. .shuju_two {
  327. position: absolute;
  328. top: 54px;
  329. width: 90%;
  330. left: 5%;
  331. box-shadow: 0 0 10rpx #bcb9ca;
  332. padding-top: 20rpx;
  333. height: 550rpx;
  334. .canvastishi {
  335. font-size: 32rpx;
  336. position: absolute;
  337. top: 50%;
  338. left: 50%;
  339. margin-left: -64rpx;
  340. margin-top: -21rpx;
  341. .dataloading:after {
  342. overflow: hidden;
  343. display: inline-block;
  344. vertical-align: bottom;
  345. animation: ellipsis 2s infinite;
  346. content: "\2026";
  347. }
  348. @keyframes ellipsis {
  349. from {
  350. width: 2px;
  351. }
  352. to {
  353. width: 15px;
  354. }
  355. }
  356. }
  357. .shuju_one_title {
  358. width: 70%;
  359. margin: 0 auto;
  360. display: flex;
  361. .tltle_text {
  362. width: 25%;
  363. border: 2rpx solid #B2B2B2;
  364. color: #57c878;
  365. text-align: center;
  366. font-size: 24rpx;
  367. height: 50rpx;
  368. line-height: 50rpx;
  369. }
  370. .title_text_color {
  371. width: 25%;
  372. border: 2rpx solid #57c878;
  373. background-color: #57c878;
  374. color: #fff;
  375. text-align: center;
  376. font-size: 24rpx;
  377. height: 50rpx;
  378. line-height: 50rpx;
  379. }
  380. }
  381. }
  382. .refresh {
  383. position: absolute;
  384. top: 700rpx;
  385. left: 5%;
  386. width: 160rpx;
  387. height: 50rpx;
  388. background-color: #57c878;
  389. color: #FFFFFF;
  390. line-height: 50rpx;
  391. text-align: center;
  392. }
  393. .condition {
  394. position: absolute;
  395. top: 770rpx;
  396. display: flex;
  397. flex-wrap: wrap;
  398. width: 90%;
  399. left: 5%;
  400. box-shadow: 0 0 10rpx #bcb9ca;
  401. margin-bottom: 30rpx;
  402. .scroll-X {
  403. width: 95%;
  404. margin: 20rpx auto;
  405. .table{
  406. width: 1672px;
  407. }
  408. .tr {
  409. display: flex;
  410. overflow: hidden;
  411. .th,
  412. .td {
  413. display: inline-block;
  414. padding: 5rpx;
  415. width: 240rpx;
  416. text-align: center;
  417. height: 52rpx;
  418. line-height: 52rpx;
  419. border: 2rpx solid #F1F1F1;
  420. }
  421. .th:first-child,
  422. .td:first-child {
  423. width: 300rpx;
  424. }
  425. }
  426. .tr:nth-child(2n-1){
  427. background-color: #f5fff8;
  428. }
  429. .tr:first-child{
  430. background-color: #57c878;
  431. color: #fff;
  432. }
  433. }
  434. .pagenumber {
  435. display: flex;
  436. margin: 20rpx auto;
  437. button {
  438. width: 150rpx;
  439. height: 50rpx;
  440. line-height: 50rpx;
  441. font-size: 26rpx;
  442. text-align: center;
  443. background-color: #57c878;
  444. color: #FFFFFF;
  445. }
  446. .pagenumber_page {
  447. width: 100rpx;
  448. height: 50rpx;
  449. line-height: 50rpx;
  450. font-size: 26rpx;
  451. text-align: center;
  452. }
  453. }
  454. }
  455. </style>