historyfile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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" 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. this.historylistdata=[]
  172. const res = await this.$myRequest({
  173. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  174. data: {
  175. device_type_id: 3,
  176. device_id: this.device_id,
  177. start_time: parseInt(this.start_time / 1000),
  178. end_time: parseInt(this.end_time / 1000),
  179. page: this.page
  180. }
  181. })
  182. this.historylistdata = res.data
  183. this.pagesum = Math.ceil(res.counts / 10) || 1
  184. if (res.data.length == 0) {
  185. this.forbidden = true
  186. console.log(res.data.length)
  187. } else {
  188. this.forbidden = false
  189. console.log(res.data.length)
  190. }
  191. for (var i = 0; i < this.historylistdata.length; i++) {
  192. if (Number(this.historylistdata[i].d_h_t.ws) == 0) {
  193. this.historylistdata[i].d_h_t.dg = "待机"
  194. } else if (Number(this.historylistdata[i].d_h_t.ws) == 1) {
  195. if (Number(this.historylistdata[i].d_h_t.lamp) == 0) {
  196. this.historylistdata[i].d_h_t.dg = "工作"
  197. } else if (Number(this.historylistdata[i].d_h_t.lamp) == 1) {
  198. this.historylistdata[i].d_h_t.dg = "异常"
  199. }
  200. }
  201. }
  202. console.log(this.historylistdata)
  203. },
  204. // forecast.send_control.get_device_config 获取当前时间的数据
  205. async newdata() {
  206. const res = await this.$myRequest({
  207. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  208. data: {
  209. device_type_id: 3,
  210. d_id: this.d_id,
  211. control_type: "data"
  212. }
  213. })
  214. if(res){
  215. uni.showToast({
  216. title: '刷新成功',
  217. duration: 2000,
  218. icon: "none"
  219. });
  220. this.historylist()
  221. }else{
  222. uni.showToast({
  223. title: '刷新失败',
  224. duration: 2000,
  225. icon: "none"
  226. });
  227. }
  228. },
  229. refresh() { //获取当前时间的数据
  230. this.newdata()
  231. },
  232. changeindex(index) {
  233. this.titleidnex = index
  234. var now = new Date()
  235. this.$forceUpdate()
  236. if (index == 0) {
  237. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  238. this.history()
  239. this.historylist()
  240. } else if (index == 1) {
  241. var oldtime = now.setMonth(now.getMonth() - 1)
  242. this.start_time = parseInt(oldtime)
  243. this.history()
  244. this.historylist()
  245. } else if (index == 2) {
  246. var oldtime = now.setMonth(now.getMonth() - 6)
  247. this.start_time = parseInt(oldtime)
  248. this.history()
  249. this.historylist()
  250. } else if (index == 3) {
  251. var oldtime = now.setFullYear(now.getFullYear() - 1)
  252. this.start_time = parseInt(oldtime)
  253. this.history()
  254. this.historylist()
  255. }
  256. },
  257. prev() { //上一页
  258. if (this.page > 1) {
  259. this.page--
  260. this.historylist()
  261. }
  262. },
  263. next() { //下一页
  264. if(this.page < this.pagesum){
  265. this.page++
  266. this.historylist()
  267. }
  268. },
  269. clickLeft() {
  270. uni.navigateBack({
  271. delta: 1
  272. })
  273. },
  274. showColumn(id, xtitle, xinfo) {
  275. var _self = this
  276. canvaColumnA = new uCharts({
  277. canvasId: id,
  278. type: 'line',
  279. legend: {
  280. position: "top"
  281. },
  282. fontSize: 11,
  283. background: '#FFFFFF',
  284. pixelRatio: 1,
  285. animation: true,
  286. dataLabel: false,
  287. categories: xtitle,
  288. series: xinfo,
  289. enableScroll: true, //开启图表拖拽功能
  290. xAxis: {
  291. disableGrid: true,
  292. type: 'grid',
  293. gridType: 'dash',
  294. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  295. scrollShow: true, //新增是否显示滚动条,默认false
  296. // scrollAlign: 'left', //滚动条初始位置
  297. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  298. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  299. },
  300. yAxis: {},
  301. width: _self.cWidth * 1,
  302. height: _self.cHeight * 1,
  303. extra: {
  304. line: {
  305. type: 'curve'
  306. }
  307. }
  308. });
  309. },
  310. touchLineA(e) {
  311. console.log(e)
  312. canvaColumnA.scrollStart(e);
  313. },
  314. moveLineA(e) {
  315. canvaColumnA.scroll(e);
  316. },
  317. touchEndLineA(e) {
  318. canvaColumnA.scrollEnd(e);
  319. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  320. canvaColumnA.showToolTip(e, {
  321. format: function(item, category) {
  322. return category + ' ' + item.name + ':' + item.data
  323. }
  324. });
  325. },
  326. },
  327. onLoad(option) {
  328. this.d_id = option.d_id
  329. this.device_id = option.device_id
  330. this.cWidth = uni.upx2px(650);
  331. this.cHeight = uni.upx2px(500);
  332. },
  333. onShow(){
  334. this.end_time = +new Date() + 1000
  335. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  336. this.history()
  337. this.historylist()
  338. },
  339. onPullDownRefresh() {
  340. this.historydatas = []
  341. this.historylistdata = []
  342. this.history()
  343. this.historylist()
  344. setTimeout(() => {
  345. uni.stopPullDownRefresh()
  346. }, 1000)
  347. },
  348. }
  349. </script>
  350. <style lang="scss">
  351. .shuju_one,
  352. .shuju_two {
  353. position: absolute;
  354. top: 54px;
  355. width: 90%;
  356. left: 5%;
  357. box-shadow: 0 0 10rpx #bcb9ca;
  358. padding-top: 20rpx;
  359. height: 550rpx;
  360. .canvastishi {
  361. font-size: 32rpx;
  362. position: absolute;
  363. top: 50%;
  364. left: 50%;
  365. margin-left: -64rpx;
  366. margin-top: -21rpx;
  367. .dataloading:after {
  368. overflow: hidden;
  369. display: inline-block;
  370. vertical-align: bottom;
  371. animation: ellipsis 2s infinite;
  372. content: "\2026";
  373. }
  374. @keyframes ellipsis {
  375. from {
  376. width: 2px;
  377. }
  378. to {
  379. width: 15px;
  380. }
  381. }
  382. }
  383. .shuju_one_title {
  384. width: 70%;
  385. margin: 0 auto;
  386. display: flex;
  387. .tltle_text {
  388. width: 25%;
  389. border: 2rpx solid #B2B2B2;
  390. color: #57c878;
  391. text-align: center;
  392. font-size: 24rpx;
  393. height: 50rpx;
  394. line-height: 50rpx;
  395. }
  396. .title_text_color {
  397. width: 25%;
  398. border: 2rpx solid #57c878;
  399. background-color: #57c878;
  400. color: #fff;
  401. text-align: center;
  402. font-size: 24rpx;
  403. height: 50rpx;
  404. line-height: 50rpx;
  405. }
  406. }
  407. }
  408. .refresh {
  409. position: absolute;
  410. top: 700rpx;
  411. left: 5%;
  412. width: 160rpx;
  413. height: 50rpx;
  414. background-color: #57c878;
  415. color: #FFFFFF;
  416. line-height: 50rpx;
  417. text-align: center;
  418. }
  419. .condition {
  420. position: absolute;
  421. top: 770rpx;
  422. display: flex;
  423. flex-wrap: wrap;
  424. width: 90%;
  425. left: 5%;
  426. box-shadow: 0 0 10rpx #bcb9ca;
  427. margin-bottom: 30rpx;
  428. .scroll-X {
  429. width: 95%;
  430. margin: 20rpx auto;
  431. .table{
  432. width: 1672px;
  433. }
  434. .tr {
  435. display: flex;
  436. overflow: hidden;
  437. .th,
  438. .td {
  439. display: inline-block;
  440. padding: 5rpx;
  441. width: 240rpx;
  442. text-align: center;
  443. height: 52rpx;
  444. line-height: 52rpx;
  445. border: 2rpx solid #F1F1F1;
  446. }
  447. .th:first-child,
  448. .td:first-child {
  449. width: 300rpx;
  450. }
  451. }
  452. .tr:nth-child(2n-1){
  453. background-color: #f5fff8;
  454. }
  455. .tr:first-child{
  456. background-color: #57c878;
  457. color: #fff;
  458. }
  459. }
  460. .pagenumber {
  461. display: flex;
  462. margin: 20rpx auto;
  463. button {
  464. width: 150rpx;
  465. height: 50rpx;
  466. line-height: 50rpx;
  467. font-size: 26rpx;
  468. text-align: center;
  469. background-color: #57c878;
  470. color: #FFFFFF;
  471. }
  472. .pagenumber_page {
  473. width: 100rpx;
  474. height: 50rpx;
  475. line-height: 50rpx;
  476. font-size: 26rpx;
  477. text-align: center;
  478. }
  479. }
  480. }
  481. </style>