historyfile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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.historydatas = []
  317. this.historylistdata = []
  318. this.history()
  319. this.historylist()
  320. setTimeout(() => {
  321. uni.stopPullDownRefresh()
  322. }, 1000)
  323. },
  324. }
  325. </script>
  326. <style lang="scss">
  327. .shuju_one,
  328. .shuju_two {
  329. position: absolute;
  330. top: 54px;
  331. width: 90%;
  332. left: 5%;
  333. box-shadow: 0 0 10rpx #bcb9ca;
  334. padding-top: 20rpx;
  335. height: 550rpx;
  336. .canvastishi {
  337. font-size: 32rpx;
  338. position: absolute;
  339. top: 50%;
  340. left: 50%;
  341. margin-left: -64rpx;
  342. margin-top: -21rpx;
  343. .dataloading:after {
  344. overflow: hidden;
  345. display: inline-block;
  346. vertical-align: bottom;
  347. animation: ellipsis 2s infinite;
  348. content: "\2026";
  349. }
  350. @keyframes ellipsis {
  351. from {
  352. width: 2px;
  353. }
  354. to {
  355. width: 15px;
  356. }
  357. }
  358. }
  359. .shuju_one_title {
  360. width: 70%;
  361. margin: 0 auto;
  362. display: flex;
  363. .tltle_text {
  364. width: 25%;
  365. border: 2rpx solid #B2B2B2;
  366. color: #57c878;
  367. text-align: center;
  368. font-size: 24rpx;
  369. height: 50rpx;
  370. line-height: 50rpx;
  371. }
  372. .title_text_color {
  373. width: 25%;
  374. border: 2rpx solid #57c878;
  375. background-color: #57c878;
  376. color: #fff;
  377. text-align: center;
  378. font-size: 24rpx;
  379. height: 50rpx;
  380. line-height: 50rpx;
  381. }
  382. }
  383. }
  384. .refresh {
  385. position: absolute;
  386. top: 700rpx;
  387. left: 5%;
  388. width: 160rpx;
  389. height: 50rpx;
  390. background-color: #57c878;
  391. color: #FFFFFF;
  392. line-height: 50rpx;
  393. text-align: center;
  394. }
  395. .condition {
  396. position: absolute;
  397. top: 770rpx;
  398. display: flex;
  399. flex-wrap: wrap;
  400. width: 90%;
  401. left: 5%;
  402. box-shadow: 0 0 10rpx #bcb9ca;
  403. margin-bottom: 30rpx;
  404. .scroll-X {
  405. width: 95%;
  406. margin: 20rpx auto;
  407. .table{
  408. width: 1672px;
  409. }
  410. .tr {
  411. display: flex;
  412. overflow: hidden;
  413. .th,
  414. .td {
  415. display: inline-block;
  416. padding: 5rpx;
  417. width: 240rpx;
  418. text-align: center;
  419. height: 52rpx;
  420. line-height: 52rpx;
  421. border: 2rpx solid #F1F1F1;
  422. }
  423. .th:first-child,
  424. .td:first-child {
  425. width: 300rpx;
  426. }
  427. }
  428. .tr:nth-child(2n-1){
  429. background-color: #f5fff8;
  430. }
  431. .tr:first-child{
  432. background-color: #57c878;
  433. color: #fff;
  434. }
  435. }
  436. .pagenumber {
  437. display: flex;
  438. margin: 20rpx auto;
  439. button {
  440. width: 150rpx;
  441. height: 50rpx;
  442. line-height: 50rpx;
  443. font-size: 26rpx;
  444. text-align: center;
  445. background-color: #57c878;
  446. color: #FFFFFF;
  447. }
  448. .pagenumber_page {
  449. width: 100rpx;
  450. height: 50rpx;
  451. line-height: 50rpx;
  452. font-size: 26rpx;
  453. text-align: center;
  454. }
  455. }
  456. }
  457. </style>