newhistoryfile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <view style="background-color: #f7f7f7; height: 100vh;padding-top: 88rpx;">
  3. <!-- <view class="status_bar"></view> -->
  4. <view>
  5. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="历史数据" backgroundColor="#f7f7f7"></uni-nav-bar>
  6. </view>
  7. <view style="padding: 0 48rpx; background-color: #f7f7f7;">
  8. <u-calendar v-model="dataShow" :mode="mode" @change="tiemchange" :maxDate="maxDate"></u-calendar>
  9. <view class="date" @click="dataShow = true">
  10. <span>选择日期 </span>
  11. <span style="color: #cccccc;">
  12. {{start_time}} <span style="margin: 0 10rpx;"> /</span> {{end_time}}
  13. <u-icon style="margin-left: 20rpx;" name="arrow-right" size="28"></u-icon>
  14. </span>
  15. </view>
  16. <view class="title">温湿度数据</view>
  17. <view class="shuju_one">
  18. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  19. 暂无数据
  20. </view>
  21. <view class="canvastishi" v-if="dataloadingtf">
  22. <p class="dataloading">加载中</p>
  23. </view>
  24. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  25. @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>
  26. </view>
  27. <!-- <pest-line
  28. :device_type_id="device_type"
  29. :d_id="d_id"
  30. :start_time="start_time"
  31. :end_time="end_time"
  32. :notify="notify"
  33. ></pest-line> -->
  34. <view class="title">监测数据
  35. <u-button size="mini" :loading='refreshLoading' class="refresh" throttle-time="500" @click="refresh" :customStyle="customStyle">刷 新</u-button>
  36. </view>
  37. <view class="condition">
  38. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  39. <table class="table" :style="tableStyle">
  40. <tr class="tr">
  41. <th style="background-color: #E6E8EB;" class="th" v-for="(value,key) in thdata" :key="key">{{value}}</th>
  42. </tr>
  43. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  44. <td class="td" v-for="(value,key) in thdata">{{items[key]}}</td>
  45. </tr>
  46. <tr class="tr" v-if="forbidden">
  47. <td class="td" v-for="item in Object.keys(thdata)">暂无数据</td>
  48. </tr>
  49. </table>
  50. </scroll-view>
  51. <view class="pagenumber">
  52. <button @click="prev">上一页</button>
  53. <view class="pagenumber_page">
  54. 第 {{page}} 页
  55. </view>
  56. <view class="pagenumber_page">
  57. 共 {{pagesum}} 页
  58. </view>
  59. <button @click="next" :disabled="forbidden">下一页</button>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  68. import pestLine from './pestLine';
  69. var canvaColumnA = null;
  70. export default {
  71. data() {
  72. return {
  73. maxDate:'2050-12-31',
  74. styles: {
  75. // width: "650rpx",
  76. height: "400rpx"
  77. },
  78. d_id: '',
  79. start_time: "",
  80. end_time: "",
  81. historydatas: [],
  82. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  83. titleidnex: 0,
  84. device_id: '',
  85. page: 1,
  86. historylistdata: [],
  87. thdata: {},
  88. forbidden: false,
  89. cWidth: '400',
  90. cHeight: '400',
  91. pixelRatio: 1,
  92. canvastishiTF: false,//暂无数据提示
  93. dataloadingtf:true,//加载中提示
  94. pagesum: 1,
  95. device_type:"",
  96. dataShow: false,
  97. mode: 'range',
  98. refreshLoading:false,
  99. notify:0
  100. }
  101. },
  102. components:{pestLine},
  103. computed:{
  104. customStyle(){
  105. return {
  106. background: '#018B3F',
  107. fontSize:'12px',
  108. border:'none',
  109. color:'#fff'
  110. }
  111. },
  112. tableStyle(){
  113. return{
  114. width: Object.keys(this.thdata).length*150 + 'px'
  115. }
  116. }
  117. },
  118. methods: {
  119. tiemchange(e) {
  120. console.log(e)
  121. this.start_time = e.startDate
  122. this.end_time = e.endDate
  123. this.history()
  124. this.historylist()
  125. this.notify++
  126. },
  127. async history() { //历史数据列表折线图
  128. this.dataloadingtf = true
  129. const res = await this.$myRequest({
  130. url: '/api/api_gateway?method=new_gateway.data_info.temp_hum',
  131. data: {
  132. device_type_id: this.device_type,
  133. id: this.d_id,
  134. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  135. end: +new Date(this.end_time + ' 23:59:59') / 1000
  136. }
  137. })
  138. this.dataloadingtf = false
  139. this.historydatas = res || []
  140. console.log(this.historydatas)
  141. if (this.historydatas.length == 0) {
  142. this.canvastishiTF = false
  143. } else {
  144. this.canvastishiTF = true
  145. let arr1 = []
  146. let arr2 = []
  147. let arr3 = []
  148. let xtitle = []
  149. for (let i = 0; i < res.length; i++) {
  150. // let times = new Date(res[i].addtime * 1000)
  151. xtitle.push(res[i].addtime.split(' ')[0])
  152. arr1.push(res[i].tem)
  153. arr2.push(res[i].hum)
  154. if ('lux' in res[i]) {
  155. arr3.push(res[i].lux)
  156. }
  157. }
  158. // console.log(arr1)
  159. let obj = [{
  160. name: '温度',
  161. data: arr1,
  162. color: '#00E29D'
  163. }, {
  164. name: '湿度',
  165. data: arr2,
  166. color: '#6CBBFF'
  167. }]
  168. if (arr3.length > 0) {
  169. obj.push({
  170. index: 1,
  171. name: '光照',
  172. data: arr3,
  173. color: '#E67B3E'
  174. })
  175. }
  176. let yAxis = {
  177. data: [{
  178. position: 'left'
  179. }, {
  180. position: 'right'
  181. }]
  182. }
  183. // console.log('----温度:',obj)
  184. this.showColumn("canvasColumnA", xtitle, obj, yAxis)
  185. }
  186. },
  187. //历史数据列表
  188. async historylist() {
  189. const res = await this.$myRequest({
  190. url: '/api/api_gateway?method=new_gateway.data_info.history_data',
  191. data: {
  192. device_type_id: this.device_type,
  193. id: this.d_id,
  194. start: +new Date(this.start_time +' 00:00:00') / 1000,
  195. end: +new Date(this.end_time +' 23:59:59') / 1000,
  196. page: this.page
  197. }
  198. })
  199. this.refreshLoading = false
  200. // this.thdata = Object.values(res.title)
  201. Object.keys(res.title).forEach(item=>{
  202. this.$set(this.thdata,item,res.title[item])
  203. })
  204. this.historylistdata = res.data
  205. this.pagesum = Math.ceil(res.total / 10) || 1
  206. if (res.data.length == 0) {
  207. this.forbidden = true
  208. } else {
  209. this.forbidden = false
  210. }
  211. console.log(this.historylistdata,'historylistdata')
  212. },
  213. // forecast.send_control.get_device_config 获取当前时间的数据
  214. async newdata() {
  215. const res = await this.$myRequest({
  216. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  217. data: {
  218. device_type_id: 3,
  219. d_id: this.d_id,
  220. control_type: "data"
  221. }
  222. })
  223. if(res){
  224. uni.showToast({
  225. title: '刷新成功',
  226. duration: 2000,
  227. icon: "none"
  228. });
  229. this.historylist()
  230. }else{
  231. uni.showToast({
  232. title: '刷新失败',
  233. duration: 2000,
  234. icon: "none"
  235. });
  236. }
  237. },
  238. refresh() { //获取当前时间的数据
  239. this.refreshLoading = true
  240. this.historylist()
  241. },
  242. prev() { //上一页
  243. if (this.page > 1) {
  244. this.page--
  245. this.historylist()
  246. }
  247. },
  248. next() { //下一页
  249. if(this.page<this.pagesum){
  250. this.page++
  251. this.historylist()
  252. }
  253. },
  254. clickLeft() {
  255. uni.navigateBack({
  256. delta: 1
  257. })
  258. },
  259. showColumn(id, xtitle, xinfo, yAxis) {
  260. let _self = this
  261. const ctx = uni.createCanvasContext(id, this);
  262. canvaColumnA = new uCharts({
  263. context: ctx,
  264. type: 'line',
  265. legend: {
  266. position: "top"
  267. },
  268. fontSize: 11,
  269. background: '#FFFFFF',
  270. pixelRatio: 1,
  271. animation: true,
  272. dataLabel: false,
  273. categories: xtitle,
  274. series: xinfo,
  275. enableScroll: true, //开启图表拖拽功能
  276. xAxis: {
  277. disableGrid: true,
  278. type: 'grid',
  279. gridType: 'dash',
  280. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  281. scrollShow: true, //新增是否显示滚动条,默认false
  282. // scrollAlign: 'left', //滚动条初始位置
  283. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  284. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  285. },
  286. yAxis: yAxis || {},
  287. width: _self.cWidth * 1,
  288. height: _self.cHeight * 1,
  289. extra: {
  290. line: {
  291. type: 'curve'
  292. }
  293. }
  294. });
  295. },
  296. touchLineA(e) {
  297. console.log(e)
  298. canvaColumnA.scrollStart(e);
  299. },
  300. moveLineA(e) {
  301. canvaColumnA.scroll(e);
  302. },
  303. touchEndLineA(e) {
  304. canvaColumnA.scrollEnd(e);
  305. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  306. canvaColumnA.showToolTip(e, {
  307. format: function(item, category) {
  308. return category + ' ' + item.name + ':' + item.data
  309. }
  310. });
  311. },
  312. },
  313. onLoad(option) {
  314. this.d_id = option.d_id
  315. this.device_id = option.device_id
  316. this.device_type = option.device_type
  317. this.cWidth = uni.upx2px(650);
  318. this.cHeight = uni.upx2px(500);
  319. let endTime = +new Date()/1000
  320. let startTime = endTime - 60 * 60 * 24
  321. this.end_time = this.formatTime(endTime*1000,'yyyy-MM-dd')
  322. console.log(this.end_time)
  323. this.start_time = this.formatTime(startTime*1000,'yyyy-MM-dd')
  324. setTimeout(()=>{
  325. this.history()
  326. this.historylist()
  327. },1000)
  328. },
  329. onShow(){
  330. // this.end_time = +new Date()/1000
  331. // this.start_time = this.end_time - 24 * 60 * 60
  332. // // this.formatTime(date, 'yyyy-MM-dd')
  333. // setTimeout(()=>{
  334. // this.history()
  335. // this.historylist()
  336. // },1000)
  337. },
  338. onPullDownRefresh() {
  339. this.history()
  340. this.historylist()
  341. setTimeout(() => {
  342. uni.stopPullDownRefresh()
  343. }, 1000)
  344. },
  345. }
  346. </script>
  347. <style lang="scss" scoped>
  348. /deep/.u-calendar__action {
  349. display: flex;
  350. justify-content: space-around;
  351. .u-calendar__action__text {
  352. line-height: 25px;
  353. }
  354. }
  355. page{
  356. background: #f7f7f7;
  357. }
  358. .title{
  359. color: #999999;
  360. margin: 32rpx 0;
  361. }
  362. .date{
  363. height: 92rpx;
  364. line-height: 92rpx;
  365. border-radius: 92rpx;
  366. background: #fff;
  367. display: flex;
  368. justify-content: space-between;
  369. margin-top: 16rpx;
  370. padding: 0 48rpx;
  371. position: relative;
  372. }
  373. .shuju_one,
  374. .shuju_two {
  375. // position: absolute;
  376. // top: 54px;
  377. width: 100%;
  378. // left: 5%;
  379. // box-shadow: 0 0 10rpx #bcb9ca;
  380. padding-top: 20rpx;
  381. height: 550rpx;
  382. background-color: #fff;
  383. border-radius: 24rpx;
  384. .canvastishi {
  385. font-size: 32rpx;
  386. position: absolute;
  387. top: 50%;
  388. left: 50%;
  389. margin-left: -64rpx;
  390. margin-top: -21rpx;
  391. .dataloading:after {
  392. overflow: hidden;
  393. display: inline-block;
  394. vertical-align: bottom;
  395. animation: ellipsis 2s infinite;
  396. content: "\2026";
  397. }
  398. @keyframes ellipsis {
  399. from {
  400. width: 2px;
  401. }
  402. to {
  403. width: 15px;
  404. }
  405. }
  406. }
  407. }
  408. .refresh {
  409. // position: absolute;
  410. // top: 700rpx;
  411. // left: 5%;
  412. font-size: 12px;
  413. float: right;
  414. // padding: 0 10rpx;
  415. // height: 40rpx;
  416. // border-radius: 8rpx;
  417. // background-color: #018B3F;
  418. // color: #FFFFFF;
  419. // line-height: 40rpx;
  420. // text-align: center;
  421. }
  422. .condition {
  423. // position: absolute;
  424. // top: 770rpx;
  425. display: flex;
  426. flex-wrap: wrap;
  427. width: 100%;
  428. // left: 5%;
  429. // box-shadow: 0 0 10rpx #bcb9ca;
  430. margin-bottom: 30rpx;
  431. .scroll-X {
  432. width: 100%;
  433. margin: 20rpx auto;
  434. .table{
  435. width: 1620px;
  436. }
  437. .tr {
  438. display: flex;
  439. overflow: hidden;
  440. .th,
  441. .td {
  442. display: inline-block;
  443. padding: 4rpx;
  444. width: 286rpx;
  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: #E6E8EB;
  460. color: #31373D;
  461. }
  462. }
  463. .pagenumber {
  464. display: flex;
  465. margin: 20rpx auto;
  466. button {
  467. width: 150rpx;
  468. height: 50rpx;
  469. line-height: 50rpx;
  470. font-size: 26rpx;
  471. text-align: center;
  472. background-color: #17BB89;
  473. color: #FFFFFF;
  474. }
  475. .pagenumber_page {
  476. width: 100rpx;
  477. height: 50rpx;
  478. line-height: 50rpx;
  479. font-size: 26rpx;
  480. text-align: center;
  481. }
  482. }
  483. }
  484. </style>