historyfile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. const ctx = uni.createCanvasContext(id, this);
  276. canvaColumnA = new uCharts({
  277. context: ctx,
  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. setTimeout(()=>{
  337. this.history()
  338. this.historylist()
  339. },1000)
  340. },
  341. onPullDownRefresh() {
  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: #B2B2B2;
  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 #28AE4F;
  399. color: #28AE4F;
  400. text-align: center;
  401. font-size: 24rpx;
  402. height: 50rpx;
  403. line-height: 50rpx;
  404. }
  405. }
  406. }
  407. .refresh {
  408. position: absolute;
  409. top: 700rpx;
  410. left: 5%;
  411. width: 160rpx;
  412. height: 50rpx;
  413. background-color: #28AE4F;
  414. color: #FFFFFF;
  415. line-height: 50rpx;
  416. text-align: center;
  417. }
  418. .condition {
  419. position: absolute;
  420. top: 770rpx;
  421. display: flex;
  422. flex-wrap: wrap;
  423. width: 90%;
  424. left: 5%;
  425. box-shadow: 0 0 10rpx #bcb9ca;
  426. margin-bottom: 30rpx;
  427. .scroll-X {
  428. width: 95%;
  429. margin: 20rpx auto;
  430. .table{
  431. width: 1672px;
  432. }
  433. .tr {
  434. display: flex;
  435. overflow: hidden;
  436. .th,
  437. .td {
  438. display: inline-block;
  439. padding: 5rpx;
  440. width: 240rpx;
  441. text-align: center;
  442. height: 52rpx;
  443. line-height: 52rpx;
  444. border: 2rpx solid #F1F1F1;
  445. }
  446. .th:first-child,
  447. .td:first-child {
  448. width: 300rpx;
  449. }
  450. }
  451. .tr:nth-child(2n-1){
  452. background-color: #f5fff8;
  453. }
  454. .tr:first-child{
  455. background-color: #57c878;
  456. color: #fff;
  457. }
  458. }
  459. .pagenumber {
  460. display: flex;
  461. margin: 20rpx auto;
  462. button {
  463. width: 150rpx;
  464. height: 50rpx;
  465. line-height: 50rpx;
  466. font-size: 26rpx;
  467. text-align: center;
  468. background-color: #17BB89;
  469. color: #FFFFFF;
  470. }
  471. .pagenumber_page {
  472. width: 100rpx;
  473. height: 50rpx;
  474. line-height: 50rpx;
  475. font-size: 26rpx;
  476. text-align: center;
  477. }
  478. }
  479. }
  480. </style>