Bläddra i källkod

feat:首页添加自动刷新

guotianliang 3 år sedan
förälder
incheckning
57eedb3eaf
7 ändrade filer med 61 tillägg och 24 borttagningar
  1. 1 0
      app.js
  2. 21 3
      pages/adjust/index.js
  3. 4 4
      pages/adjust/index.less
  4. 4 4
      pages/adjust/index.wxss
  5. 23 4
      pages/index/index.js
  6. 4 5
      pages/index/index.less
  7. 4 4
      pages/index/index.wxss

+ 1 - 0
app.js

@@ -46,6 +46,7 @@ App({
     this.checkUpdate();
   },
   globalData: {
+    autoRefreshTime:5000,
     specialProject:["Pj1101080259"],
     StatusBar: null,
     Custom: null,

+ 21 - 3
pages/adjust/index.js

@@ -15,7 +15,7 @@ import {
   workLeave,
   contactTenant
 } from "../../requests/api";
-let timer=null;
+let refreshTimer=null;
 Page({
 
   /**
@@ -99,6 +99,10 @@ Page({
     },
     picInitUrl:$.store.get("picInitUrl"),
   },
+  onHide(){
+    clearInterval(refreshTimer);
+    refreshTimer=null;
+  },
   // 关闭问卷
   surveyClose(value){
     this.setData({surveyShow:false,lottieShow:true});
@@ -811,6 +815,18 @@ Page({
       }
     })
   },
+  // 自动刷新
+  autoRefresh(fn){
+    if(refreshTimer){
+      clearInterval(refreshTimer);
+      refreshTimer = null;
+    }
+    let refreshTime=$.store.get("autoRefreshTime");
+    refreshTimer = setTimeout(()=>{
+      fn();
+      this.autoRefresh(fn);
+    },refreshTime)
+  },
   /**
    * 生命周期函数--监听页面加载
    */
@@ -818,6 +834,7 @@ Page({
     options = JSON.parse(decodeURIComponent(JSON.stringify(options)));
     if(options.md1){
       this.getDetail(options.md1);
+      this.autoRefresh(this.getDetail);
     }else{
       options.humidity&&(options.humiditylevel = this.checkLevel(options.humidity,"humidity"));
       options.co2&&(options.co2level = this.checkLevel(options.co2,"co2"));
@@ -838,6 +855,7 @@ Page({
           this.setData({singleOffice:true})
         }
         this.checkPower();
+        this.autoRefresh(this.getDetail);
       })
     }
 
@@ -863,9 +881,9 @@ Page({
         }
       }
     }
-    wx.showLoading();
+    // wx.showLoading();
     let res = await getSpacedetail(data);
-    wx.hideLoading();
+    // wx.hideLoading();
     let {content} = res;
     if(content){
       (content[0].humidity||content[0].humidity==0)&&(content[0].humiditylevel = this.checkLevel(content[0].humidity,"humidity"));

+ 4 - 4
pages/adjust/index.less

@@ -149,17 +149,17 @@ page{
             .peoplestate{
                 display: inline-block;
                 box-sizing: border-box;
-                padding: 4px 12px;
+                padding: 1px 7px;
                 margin-left: 10px;
                 // line-height: 56rpx;#c86672
-                background:#92af67;
+                background: #34c724;
                 vertical-align: middle;
                 color: #ffffff;
                 border-radius: 12px;
-                font-size: 24rpx;
+                font-size: 20rpx;
             }
             .activepeople{
-                background:#c86672;
+                background: #f54e45;
             }
             .spacestate{
                 font-size: 30rpx;

+ 4 - 4
pages/adjust/index.wxss

@@ -140,16 +140,16 @@ page {
 .adjust_main .space_msg .msg_left .peoplestate {
   display: inline-block;
   box-sizing: border-box;
-  padding: 4px 12px;
+  padding: 1px 7px;
   margin-left: 10px;
-  background: #92af67;
+  background: #34c724;
   vertical-align: middle;
   color: #ffffff;
   border-radius: 12px;
-  font-size: 24rpx;
+  font-size: 20rpx;
 }
 .adjust_main .space_msg .msg_left .activepeople {
-  background: #c86672;
+  background: #f54e45;
 }
 .adjust_main .space_msg .msg_left .spacestate {
   font-size: 30rpx;

+ 23 - 4
pages/index/index.js

@@ -16,6 +16,7 @@ import {
   powerCheck,
   openSpace,
 } from "../../requests/api";
+var refreshTimer=null;
 Page({
   data: {
     surveyShow:false, //是否显示调查问卷
@@ -232,6 +233,7 @@ Page({
             // 第一次进入获取数据
             console.log($.storage.get('wxqcode'),"$.storage.get('wxqcode')")
             !$.storage.get('wxqcode')&&that.getData();
+            !$.storage.get('wxqcode')&&that.autoRefresh(this.getData);
             if($.storage.get('wxqcode')&&$.storage.get('logined')){
               this.checkCode($.storage.get('wxqcode'));
             }
@@ -349,6 +351,18 @@ Page({
   gotoUser(){
     router.push('usercenter')
   },
+  // 自动刷新
+  autoRefresh(fn){
+    if(refreshTimer){
+      clearInterval(refreshTimer);
+      refreshTimer = null;
+    }
+    let refreshTime=$.store.get("autoRefreshTime");
+    refreshTimer = setTimeout(()=>{
+      fn();
+      this.autoRefresh(fn);
+    },refreshTime)
+  },
   /**
    * 获取页面服务端数据
    */
@@ -358,9 +372,9 @@ Page({
     if(!userId){
       return;
     }
-    wx.showLoading({
-      title:"加载中"
-    })
+    // wx.showLoading({
+    //   title:"加载中"
+    // })
     const data = {
       "criteria": {
         "userId": userId,
@@ -387,7 +401,7 @@ Page({
     }else{
       this.setData({noDate:true,cardList:[]})
     }
-    wx.hideLoading()
+    // wx.hideLoading()
     // $.hideLoading()
   },
   checkLevel(value,name){
@@ -534,6 +548,7 @@ Page({
     // await this.inItUserdate();
     if($.storage.get("tenantId")&&!$.store.get('changeTenantId')&&!this.data.formList){
       this.getData();
+      this.autoRefresh(this.getData);
     }
 
     if(this.data.formList){
@@ -555,6 +570,10 @@ Page({
     }
 
   },
+  onHide(){
+    clearInterval(refreshTimer);
+    refreshTimer=null;
+  },
   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */

+ 4 - 5
pages/index/index.less

@@ -162,17 +162,16 @@ page{
                    .peoplestate{
                         display: inline-block;
                         box-sizing: border-box;
-                        padding: 4px 12px;
+                        padding: 1px 7px;
                         margin-left: 10px;
-                        // line-height: 56rpx;#c86672
-                        background:#92af67;
+                        background: #34c724;
                         vertical-align: middle;
                         color: #ffffff;
                         border-radius: 12px;
-                        font-size: 24rpx;
+                        font-size: 20rpx;
                     }
                     .activepeople{
-                        background:#c86672;
+                        background: #f54e45;
                     }
                    .spacestate{
                         font-size: 30rpx;

+ 4 - 4
pages/index/index.wxss

@@ -143,16 +143,16 @@ page {
 .contant_box .spacelist_box .space_item .space_msg .msg_left .peoplestate {
   display: inline-block;
   box-sizing: border-box;
-  padding: 4px 12px;
+  padding: 1px 7px;
   margin-left: 10px;
-  background: #92af67;
+  background: #34c724;
   vertical-align: middle;
   color: #ffffff;
   border-radius: 12px;
-  font-size: 24rpx;
+  font-size: 20rpx;
 }
 .contant_box .spacelist_box .space_item .space_msg .msg_left .activepeople {
-  background: #c86672;
+  background: #f54e45;
 }
 .contant_box .spacelist_box .space_item .space_msg .msg_left .spacestate {
   font-size: 30rpx;