historyfile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. const ctx = uni.createCanvasContext(id, this);
  278. canvaColumnA = new uCharts({
  279. context: ctx,
  280. type: 'line',
  281. legend: {
  282. position: "top"
  283. },
  284. fontSize: 11,
  285. background: '#FFFFFF',
  286. pixelRatio: 1,
  287. animation: true,
  288. dataLabel: false,
  289. categories: xtitle,
  290. series: xinfo,
  291. enableScroll: true, //开启图表拖拽功能
  292. xAxis: {
  293. disableGrid: true,
  294. type: 'grid',
  295. gridType: 'dash',
  296. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  297. scrollShow: true, //新增是否显示滚动条,默认false
  298. // scrollAlign: 'left', //滚动条初始位置
  299. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  300. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  301. },
  302. yAxis: {},
  303. width: _self.cWidth * 1,
  304. height: _self.cHeight * 1,
  305. extra: {
  306. line: {
  307. type: 'curve'
  308. }
  309. }
  310. });
  311. },
  312. touchLineA(e) {
  313. console.log(e)
  314. canvaColumnA.scrollStart(e);
  315. },
  316. moveLineA(e) {
  317. canvaColumnA.scroll(e);
  318. },
  319. touchEndLineA(e) {
  320. canvaColumnA.scrollEnd(e);
  321. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  322. canvaColumnA.showToolTip(e, {
  323. format: function(item, category) {
  324. return category + ' ' + item.name + ':' + item.data
  325. }
  326. });
  327. },
  328. },
  329. onLoad(option) {
  330. this.d_id = option.d_id
  331. this.device_id = option.device_id
  332. this.cWidth = uni.upx2px(650);
  333. this.cHeight = uni.upx2px(500);
  334. this.myuser_type = uni.getStorageSync('myuser_type')
  335. },
  336. onShow(){
  337. this.end_time = +new Date() + 1000
  338. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  339. this.history()
  340. this.historylist()
  341. },
  342. onPullDownRefresh() {
  343. this.historydatas = []
  344. this.historylistdata = []
  345. this.history()
  346. this.historylist()
  347. setTimeout(() => {
  348. uni.stopPullDownRefresh()
  349. }, 1000)
  350. },
  351. }
  352. </script>
  353. <style lang="scss">
  354. .shuju_one,
  355. .shuju_two {
  356. position: absolute;
  357. top: 54px;
  358. width: 90%;
  359. left: 5%;
  360. box-shadow: 0 0 10rpx #bcb9ca;
  361. padding-top: 20rpx;
  362. height: 550rpx;
  363. .canvastishi {
  364. font-size: 32rpx;
  365. position: absolute;
  366. top: 50%;
  367. left: 50%;
  368. margin-left: -64rpx;
  369. margin-top: -21rpx;
  370. .dataloading:after {
  371. overflow: hidden;
  372. display: inline-block;
  373. vertical-align: bottom;
  374. animation: ellipsis 2s infinite;
  375. content: "\2026";
  376. }
  377. @keyframes ellipsis {
  378. from {
  379. width: 2px;
  380. }
  381. to {
  382. width: 15px;
  383. }
  384. }
  385. }
  386. .shuju_one_title {
  387. width: 70%;
  388. margin: 0 auto;
  389. display: flex;
  390. .tltle_text {
  391. width: 25%;
  392. border: 2rpx solid #B2B2B2;
  393. color: #57c878;
  394. text-align: center;
  395. font-size: 24rpx;
  396. height: 50rpx;
  397. line-height: 50rpx;
  398. }
  399. .title_text_color {
  400. width: 25%;
  401. border: 2rpx solid #57c878;
  402. background-color: #57c878;
  403. color: #fff;
  404. text-align: center;
  405. font-size: 24rpx;
  406. height: 50rpx;
  407. line-height: 50rpx;
  408. }
  409. }
  410. }
  411. .refresh {
  412. position: absolute;
  413. top: 700rpx;
  414. left: 5%;
  415. width: 160rpx;
  416. height: 50rpx;
  417. background-color: #57c878;
  418. color: #FFFFFF;
  419. line-height: 50rpx;
  420. text-align: center;
  421. }
  422. .condition {
  423. position: absolute;
  424. top: 770rpx;
  425. display: flex;
  426. flex-wrap: wrap;
  427. width: 90%;
  428. left: 5%;
  429. box-shadow: 0 0 10rpx #bcb9ca;
  430. margin-bottom: 30rpx;
  431. .scroll-X {
  432. width: 95%;
  433. margin: 20rpx auto;
  434. .table{
  435. width: 1672px;
  436. }
  437. .tr {
  438. display: flex;
  439. overflow: hidden;
  440. .th,
  441. .td {
  442. display: inline-block;
  443. padding: 5rpx;
  444. width: 240rpx;
  445. text-align: center;
  446. height: 52rpx;
  447. line-height: 52rpx;
  448. border: 2rpx solid #F1F1F1;
  449. }
  450. .th:first-child,
  451. .td:first-child {
  452. width: 300rpx;
  453. }
  454. }
  455. .tr:nth-child(2n-1){
  456. background-color: #f5fff8;
  457. }
  458. .tr:first-child{
  459. background-color: #57c878;
  460. color: #fff;
  461. }
  462. .redText{
  463. .td{
  464. color: #dc143c;
  465. }
  466. }
  467. }
  468. .pagenumber {
  469. display: flex;
  470. margin: 20rpx auto;
  471. button {
  472. width: 150rpx;
  473. height: 50rpx;
  474. line-height: 50rpx;
  475. font-size: 26rpx;
  476. text-align: center;
  477. background-color: #57c878;
  478. color: #FFFFFF;
  479. }
  480. .pagenumber_page {
  481. width: 100rpx;
  482. height: 50rpx;
  483. line-height: 50rpx;
  484. font-size: 26rpx;
  485. text-align: center;
  486. }
  487. }
  488. }
  489. </style>