historyfile.vue 13 KB

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