historyfile.vue 13 KB

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