Переглянути джерело

v2.5.2 将时间处理模块移植到主线程中

wzx 3 роки тому
батько
коміт
bd7af83b09
6 змінених файлів з 241 додано та 170 видалено
  1. 39 14
      src/Global.js
  2. 5 5
      src/Mock/index.js
  3. 50 54
      src/components/Headside.vue
  4. 31 1
      src/store/index.js
  5. 103 85
      src/views/Index.vue
  6. 13 11
      src/views/Main.vue

+ 39 - 14
src/Global.js

@@ -99,8 +99,9 @@ getHoursAndMin = function (datetime) {
     return h + m;
 };
 
-getHoursAndMinAndSec = function () {
-    let date = new Date();
+getHoursAndMinAndSec = function (date='') {
+    if (date == '') date = new Date();
+
     h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
     m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
     s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
@@ -129,9 +130,10 @@ nonTfmtDatetoLength = function (datetime, length) {
     return datetime
 };
 
-// 获取当前时间
-globalcurrent = function () {
-    let date = new Date();
+// 获取当前日期
+globalcurrent = function (date='') {
+    if (date == '') date = new Date();
+
     let seperator1 = "-";
     let year = date.getFullYear();
     let month = date.getMonth() + 1;
@@ -145,8 +147,27 @@ globalcurrent = function () {
     let thisdata = year + seperator1 + month + seperator1 + strDate;
     return thisdata;
 };
-globalcurrentByCN = function () {
-    let date = new Date();
+
+// 获取当前时间
+globalGetCurrentTime = function (date='') {
+    if (date == '') date = new Date();
+
+    let h = date.getHours();
+    h = h < 10 ? '0' + h + ':' : h + ':';
+
+    let m = date.getMinutes();
+    m = m < 10 ? '0' + m + ':' : m + ':';
+
+    let s = date.getSeconds();
+    s = s < 10 ? '0' + s : s;
+
+    let curTime = h + m + s;
+    return curTime;
+};
+
+globalcurrentByCN = function (date='') {
+    if (date == '') date = new Date();
+
     let month = date.getMonth() + 1;
     let strDate = date.getDate();
     if (month >= 1 && month <= 9) {
@@ -201,8 +222,9 @@ globalCheckPhone = function (val) {
     }
 };
 
-getNowDate = function () {
-    let date = new Date();
+getNowDate = function (date='') {
+    if (date == '') date = new Date();
+
     let y = date.getFullYear();
     let m = date.getMonth() + 1;
     let d = date.getDate();
@@ -215,14 +237,17 @@ getNowDate = function () {
     return y + "年" + m + "月" + d + "日";
 }
 
-globalcurrentWeek = function () {
-    let weeks = new Date().getDay();
-    let d = new Date().getDate();
+globalcurrentWeek = function (date='') {
+    if (date == '') date = new Date();
+
+    let weeks = date.getDay();
+    let d = date.getDate();
     return getNowDate() + ' ' + numberToWeekdays(weeks) + ' 第' + getWeekOfYear() + '周';
 }
 
-getWeekOfYear = function () {
-    var today = new Date();
+getWeekOfYear = function (today='') {
+    if (today == '') today = new Date();
+
     var firstDay = new Date(today.getFullYear(), 0, 1);
     var dayOfWeek = firstDay.getDay();
     var spendDay = 1;

+ 5 - 5
src/Mock/index.js

@@ -441,20 +441,20 @@ if (t == 1) {
         // 上团课
         Mock.mock(curheadapi + 'ClassStatQuery', 'post', getClassStat(1, 1));
         Mock.mock(Mockapi + 'ClassStatQuery', 'post', getClassStat(1, 1));
-        Mock.mock(curheadapi + 'UserListInfo', 'post', testStudent(35, 1));//true
-        Mock.mock(Mockapi + 'UserListInfo', 'post', testStudent(9, 2)); //
+        Mock.mock(curheadapi + 'UserListInfo', 'post', testStudent(25, 1));//true
+        Mock.mock(Mockapi + 'UserListInfo', 'post', testStudent(25, 2)); //
     } else if (LessonClass == 2) {
         // 上2队PK课
         Mock.mock(curheadapi + 'ClassStatQuery', 'post', getClassStat(1, 2));
         Mock.mock(Mockapi + 'ClassStatQuery', 'post', getClassStat(1, 2));
         Mock.mock(curheadapi + 'UserListInfo', 'post', testStudent(16, 2,));
-        Mock.mock(Mockapi + 'UserListInfo', 'post', testStudent(10, 1,));
+        Mock.mock(Mockapi + 'UserListInfo', 'post', testStudent(16, 1,));
     } else if (LessonClass == 3) {
         // 上3队PK课
         Mock.mock(curheadapi + 'ClassStatQuery', 'post', getClassStat(1, 3));
         Mock.mock(Mockapi + 'ClassStatQuery', 'post', getClassStat(1, 3));
-        Mock.mock(curheadapi + 'UserListInfo', 'post', testStudent(5, 3,));
-        Mock.mock(Mockapi + 'UserListInfo', 'post', testStudent(4, 3,));
+        Mock.mock(curheadapi + 'UserListInfo', 'post', testStudent(30, 3,));
+        Mock.mock(Mockapi + 'UserListInfo', 'post', testStudent(30, 3,));
         Mock.mock(curheadapi + 'ClassUserRank', 'post', testStudent(1, 2));
         Mock.mock(Mockapi + 'ClassUserRank', 'post', testStudent(1, 3));
     } else if (LessonClass == 0) {

+ 50 - 54
src/components/Headside.vue

@@ -7,10 +7,10 @@
       <img v-show="this.$store.state.wsState" src="../static/img/bleUpload.svg">
     </div>
     <div class="rt">
-      <p @click="showUuid()">版本 {{ version }}</p>
-      <span>{{ nowTime }}</span>
-      <span>{{ nowWeeks }}</span>
-      <span>{{ nowDay }}</span>
+      <p @click="showUuid()">版本 {{ this.$store.state.localVersion }}</p>
+      <span>{{ this.$store.state.curTime }}</span>
+      <span>{{ this.$store.state.curWeek }}</span>
+      <span>{{ this.$store.state.curDay }}</span>
       <!-- <span @click="refreshPage()">{{ nowWeeks }}</span> -->
       <!-- <span @click="showfullScreen()">{{ nowDay }}</span> -->
     </div>
@@ -60,7 +60,6 @@ export default {
       nowWeeks: '',
       nowDay: '',
       nowTime: '',
-      version: '',
       curAppType: appType,
       curLogoImg: logo,
       curLogoClass: 'logo_bsw',
@@ -72,30 +71,30 @@ export default {
   mounted() {
     console.log("Headside mounted");
     console.log("route: " + this.$route.path);
-    console.log("[Headside mounted] timer_headclock = " + timer_headclock);
+    // console.log("[Headside mounted] timer_headclock = " + timer_headclock);
 
     this.getLogo();
     this.getCurVersion();
 
-    this.clearTimer();
-    console.log("[Headside mounted] clearTimer run! timer_headclock = " + timer_headclock);
+    // this.clearTimer();
+    // console.log("[Headside mounted] clearTimer run! timer_headclock = " + timer_headclock);
 
-    // if (this.timer == null) {
-    if (timer_headclock == null) {
-      timer_headclock = setInterval(() => {
-        this.getCurrentTime();
-      }, 1000);
-      console.log("[Headside mounted] getCurrentTime run! timer_headclock = " + timer_headclock);
+    // // if (this.timer == null) {
+    // if (timer_headclock == null) {
+    //   timer_headclock = setInterval(() => {
+    //     this.getCurrentTime();
+    //   }, 1000);
+    //   console.log("[Headside mounted] getCurrentTime run! timer_headclock = " + timer_headclock);
 
-      this.$once('hook:beforeDestroy', () => {
-        console.log("[Headside hook:beforeDestroy] timer_headclock = " + timer_headclock);
-        this.clearTimer();
-        console.log("[Headside hook:beforeDestroy] timer_headclock = " + timer_headclock);
-      });
-    }
-    else {
-      console.log("[Headside mounted] 不加载时间 timer_headclock = " + timer_headclock);
-    }
+    //   this.$once('hook:beforeDestroy', () => {
+    //     console.log("[Headside hook:beforeDestroy] timer_headclock = " + timer_headclock);
+    //     this.clearTimer();
+    //     console.log("[Headside hook:beforeDestroy] timer_headclock = " + timer_headclock);
+    //   });
+    // }
+    // else {
+    //   console.log("[Headside mounted] 不加载时间 timer_headclock = " + timer_headclock);
+    // }
   },
   // beforeDestroy() {
   //   console.log("[Headside beforeDestroy] timer_headclock = " + timer_headclock);
@@ -103,34 +102,30 @@ export default {
   //   console.log("[Headside beforeDestroy] timer_headclock = " + timer_headclock);
   // },
   methods: {
-    clearTimer() {
-      if (timer_headclock != null) {
-        clearInterval(timer_headclock);
-        timer_headclock = null;
-      }
-    },
-    getCurrentTime() {
-      let date = new Date();
-      let h = date.getHours();
-      h = h < 10 ? '0' + h + ':' : h + ':';
+    // clearTimer() {
+    //   if (timer_headclock != null) {
+    //     clearInterval(timer_headclock);
+    //     timer_headclock = null;
+    //   }
+    // },
+    // getCurrentTime() {
+    //   let date = new Date();
+    //   let h = date.getHours();
+    //   h = h < 10 ? '0' + h + ':' : h + ':';
 
-      let m = date.getMinutes();
-      m = m < 10 ? '0' + m + ':' : m + ':';
+    //   let m = date.getMinutes();
+    //   m = m < 10 ? '0' + m + ':' : m + ':';
 
-      let s = date.getSeconds();
-      s = s < 10 ? '0' + s : s;
+    //   let s = date.getSeconds();
+    //   s = s < 10 ? '0' + s : s;
 
-      this.nowTime = h + m + s;
-      // this.nowTime = h + m;
-      // console.log(this.nowTime);
+    //   this.nowTime = h + m + s;
+    //   // this.nowTime = h + m;
+    //   // console.log(this.nowTime);
 
-      this.nowDayFunc();
-      
-      // 获取版本号
-      this.version = localStorage.version;
-      this.currunVersion = runVersion;
-      this.curheadapi = headapi;
-    },
+    //   this.nowDayFunc();
+
+    // },
     getLogo() {
       if (this.curAppType == 1) {    // 1: 小飞龙
         this.curLogoImg = logo_xfl;
@@ -177,15 +172,16 @@ export default {
     refreshPage() {
       location.reload();
     },
-    nowDayFunc() {
-      let days = new Date().getDay();
-      let wd = numberToWeekdays(days);
-      this.nowWeeks = wd;
-      this.nowDay = globalcurrentByCN();
-    },
+    // nowDayFunc() {
+    //   let days = new Date().getDay();
+    //   let wd = numberToWeekdays(days);
+    //   this.nowWeeks = wd;
+    //   this.nowDay = globalcurrentByCN();
+    // },
     // 获取当前版本
     getCurVersion() {
-      // console.log(version)
+      this.currunVersion = runVersion;
+      this.curheadapi = headapi;
     },
     qrcode(code) {
       this.$refs.qrCodeUrl.innerHTML = "";

+ 31 - 1
src/store/index.js

@@ -6,18 +6,36 @@ Vue.use(Vuex);
 export default new Vuex.Store({
     state: {
         eqSn: "",
+        remoteVersion: "",
+        localVersion: "",
+        // headapi: "",        
         wsUrl: "",
         shopName: "",
         bleState: false,    // BLE状态 false:关闭 true:开启
         bleDiscovery: false,// BLE设备搜索状态 false:关闭 true:开启
         wsState: false,     // webSocket状态 false:关闭 true:开启
         classOn: 0,         // 上课状态 0: 下课 1:团课/私教 2:竞技课2PK 3:竞技课3pk
+        curTime: "",
+        curDay: "",
+        curWeek: "",
     },
     mutations: {
         setEqSn(state, eqSn) {
             state.eqSn = eqSn;
             console.log("[setEqSn] state.eqSn = " + eqSn);
         },
+        setRemoteVersion(state, remoteVersion) {
+            state.remoteVersion = remoteVersion;
+            console.log("[setRemoteVersion] state.remoteVersion = " + remoteVersion);
+        },
+        setLocalVersion(state, localVersion) {
+            state.localVersion = localVersion;
+            console.log("[setLocalVersion] state.localVersion = " + localVersion);
+        },
+        // setHeadapi(state, headapi) {
+        //     state.headapi = headapi;
+        //     console.log("[setHeadapi] state.headapi = " + headapi);
+        // },
         setWsUrl(state, wsUrl) {
             state.wsUrl = wsUrl;
             console.log("[setWsUrl] state.wsUrl = " + wsUrl);
@@ -43,7 +61,19 @@ export default new Vuex.Store({
                 state.classOn = classOn;
                 console.log("[setClassOn] state.classOn = " + classOn);
             }
-        }
+        },
+        setCurTime(state, curTime) {
+            state.curTime = curTime;
+            // console.log("[setCurTime] state.curTime = " + curTime);
+        },
+        setCurDay(state, curDay) {
+            state.curDay = curDay;
+            // console.log("[setCurDay] state.curDay = " + curDay);
+        },
+        setCurWeek(state, curWeek) {
+            state.curWeek = curWeek;
+            // console.log("[setCurWeek] state.curWeek = " + curWeek);
+        },
     },
     actions: {
     },

+ 103 - 85
src/views/Index.vue

@@ -39,7 +39,7 @@ export default {
         clmurl: '/',
       }],
       editableTabsValue: '1',
-      curVersion: '2.0',
+      localVersion: '2.5',
       isPad: true,// pad 展示版本
       ClentHeight: document.documentElement.clientHeight + 'px',
       testEqsnArr: [
@@ -55,103 +55,119 @@ export default {
       intervTime_checkUpdate: 600000, //检测升级信息的轮询时间 毫秒
       appRuntime: 0, //APP运行时长 分钟
     }
-  }, 
+  },
   mounted() {
-    this.getCurVersion();
-  },  
-  methods: {    
+    this.sysInit();
+  },
+  methods: {
     // 获取当前版本号
-    getCurVersion() {
+    sysInit() {
       let that = this;
       //浏览器默认的
       localStorage.eqSn = '30:9C:23:0C:8B:1E';
       // localStorage.eqSn = 'd104bd6ffec3d5ba';
       that.$store.commit('setEqSn', localStorage.eqSn);
-      localStorage.version = '2.3.1';
+      that.$store.commit('setLocalVersion', that.localVersion);
+
+      that.getSysDateTime();
 
       if (window.plus) {
-        plusReady();
+        that.plusReady();
       } else {
         console.log('>>> plus is not ready');
         // 调试时候关闭
         this.getConfigParam(localStorage.eqSn);
-        // plusReady();
-        document.addEventListener('plusready', plusReady, false);
-      }
+        document.addEventListener('plusready', that.plusReady, false);
+      }     
+    },
+    getSysDateTime() {
+      let that = this;
+      console.log('[sysInit] getSysDateTime() run!');
+
+      setInterval(() => {
+        let date = new Date();
+        let curTime = globalGetCurrentTime(date);
+        let curDay = globalcurrentByCN(date);
+        let curWeek = numberToWeekdays(date.getDay());
+        that.$store.commit('setCurTime', curTime);
+        that.$store.commit('setCurDay', curDay);
+        that.$store.commit('setCurWeek', curWeek);
+        // console.log(curTime);
+      }, 1000);
+    },
+    plusReady() {
+      let that = this;
+      console.log('>>> plus is ready');
+
+      if (typeof plus == 'undefined') return false;
+      // 获取本地应用资源版本号
+      plus.runtime.getProperty(plus.runtime.appid, function (inf) {
+        that.localVersion = inf.version;
+        that.$store.commit('setLocalVersion', that.localVersion);
+      });
+
+      //   获取手机UUID
+      plus.device.getInfo({
+        success: function (e) {
+          let uuid = JSON.stringify(e.uuid).toString().substr(1);
+          uuid = uuid.substring(0, uuid.length - 1);
+          localStorage.eqSn = uuid;
+          that.$store.commit('setEqSn', uuid);
+          
+          console.log('>>> [uuid]: ' + uuid);
+          console.log('getDeviceInfo success: ' + JSON.stringify(e.uuid));
+          // 正式版打开
+          // 获取配置参数
+          that.getConfigParam(e.uuid);
+
+          // 公司测试机用公司版本升级 
+          if (that.testEqsnArr.includes(uuid)) {
+            that.testMode = true;                 
+          } else {  // 正式版
+            that.testMode = false;            
+          }
 
-      function plusReady() {
-        console.log('>>> plus is ready');
-
-        if (typeof plus == 'undefined') return false;
-        // 获取本地应用资源版本号
-        plus.runtime.getProperty(plus.runtime.appid, function (inf) {
-          localStorage.version = inf.version;
-          that.curVersion = inf.version;
-        });
-
-        //   获取手机UUID
-        plus.device.getInfo({
-          success: function (e) {
-            let uuid = JSON.stringify(e.uuid).toString().substr(1);
-            uuid = uuid.substring(0, uuid.length - 1);
-            localStorage.eqSn = uuid;
-            that.$store.commit('setEqSn', uuid);
+          // 教室版本自动升级,户外版禁用自动升级
+          if (runVersion == 'outDoor') {
+            console.log('户外版禁用自动升级');
             
-            console.log('>>> [uuid]: ' + uuid);
-            console.log('getDeviceInfo success: ' + JSON.stringify(e.uuid));
-            // 正式版打开
-            // 获取配置参数
-            that.getConfigParam(e.uuid);
-
-            // 公司测试机用公司版本升级 
-            if (that.testEqsnArr.includes(uuid)) {
-              that.testMode = true;                 
-            } else {  // 正式版
-              that.testMode = false;            
-            }
+            setInterval(() => {
+              that.checkAppRuntime();
+            }, that.intervTime_checkUpdate);
+
+            return false
+          } 
+          else if (runVersion == 'localtest') {
+            console.log('本机测试禁用自动升级');
+            plus.nativeUI.toast("本机测试 禁用自动升级 UUID: " + uuid);
+
+            setInterval(() => {
+              that.checkAppRuntime();
+            }, that.intervTime_checkUpdate);
+            
+            return false
+          } 
+          else {
+            that.checkUpdate();
 
-            // 教室版本自动升级,户外版禁用自动升级
-            if (runVersion == 'outDoor') {
-              console.log('户外版禁用自动升级');
-              
-              setInterval(() => {
-                that.checkAppRuntime();
-              }, that.intervTime_checkUpdate);
+            // 每10分钟检测一下升级信息
+            setInterval(() => {
+              // console.log("$route.path: " + that.$route.path);
+              // console.log("$route.name: " + that.$route.name);
 
-              return false
-            } 
-            else if (runVersion == 'localtest') {
-              console.log('本机测试禁用自动升级');
-              plus.nativeUI.toast("本机测试 禁用自动升级 UUID: " + uuid);
-
-              setInterval(() => {
-                that.checkAppRuntime();
-              }, that.intervTime_checkUpdate);
-              
-              return false
-            } 
-            else {
-              that.checkUpdate();
-
-              // 每10分钟检测一下升级信息
-              setInterval(() => {
-                // console.log("$route.path: " + that.$route.path);
-                // console.log("$route.name: " + that.$route.name);
-
-                that.checkAppRuntime();
-
-                if (that.$route.name == "Wait") {
-                  console.log(">>> checkUpdate");
-                  that.checkUpdate();
-                }
-              }, that.intervTime_checkUpdate);
-            }
-          },
-          fail: function (e) {
-            console.log('getDeviceInfo failed: ' + JSON.stringify(e));
+              that.checkAppRuntime();
+
+              if (that.$route.name == "Wait") {
+                console.log(">>> checkUpdate");
+                that.checkUpdate();
+              }
+            }, that.intervTime_checkUpdate);
           }
-        });
-      }
+        },
+        fail: function (e) {
+          console.log('getDeviceInfo failed: ' + JSON.stringify(e));
+        }
+      });
     },
     checkAppRuntime() {
       let that = this;
@@ -176,12 +192,14 @@ export default {
       QueryVueFramework(postdata, that.testMode).then(res => {
         let json = res;
         if (json.Code == 0) {
-          console.log('localStorage.version: ' + localStorage.version);
-          console.log('json.VueFramework.Version: ' + json.VueFramework.Version);
-          // plus.nativeUI.toast("当前安装版本: " + localStorage.version);
-          if (localStorage.version != json.VueFramework.Version) {
+          let remoteVersion = json.VueFramework.Version;
+          that.$store.commit('setRemoteVersion', remoteVersion);
+
+          console.log('localVersion: ' + that.$store.state.localVersion);
+          console.log('remoteVersion: ' + that.$store.state.remoteVersion);
+          if (that.$store.state.localVersion != that.$store.state.remoteVersion) {
             // 正式
-            plus.nativeUI.toast("发现新版本 " + json.VueFramework.Version + ",准备升级...");
+            plus.nativeUI.toast("发现新版本 " + that.$store.state.remoteVersion + ",准备升级...");
             let url = DownloadVueFramework(that.testMode);
             that.downWgt(url);
           }

+ 13 - 11
src/views/Main.vue

@@ -104,6 +104,9 @@ export default {
         clearInterval(this.mainTimer);
         clearInterval(this.timer2);
         clearInterval(this.timer3);
+        this.mainTimer = null;
+        this.timer2 = null;
+        this.timer3 = null;
       }
     }
   },
@@ -124,10 +127,8 @@ export default {
       this.curgetClassStat();
 
       this.mainTimer = setInterval(() => {
-        // this.$router.push({path: '/'});
         this.GetgetUserList();
         this.curgetClassStat();
-        // console.log("this.toperInfo.dialogVisible: " + this.toperInfo.dialogVisible);
       }, 1000);
       
       this.timer2 = setInterval(() => {
@@ -316,30 +317,31 @@ export default {
       let that = this;
       let numberClass = '';
       let colorClass = '';
-      for (let i = 0; i < parseInt(res.length); i++) {
+      let resLength = parseInt(res.length);
+      for (let i = 0; i < resLength; i++) {
         switch (true) {
-          case  parseInt(res.length) == 1:
+          case  resLength == 1:
             numberClass = 'max';
             break;
-          case  parseInt(res.length) == 2:
+          case  resLength == 2:
             numberClass = 'two';
             break;
-          case  parseInt(res.length) <= 4 && parseInt(res.length) > 2:
+          case  resLength <= 4 && resLength > 2:
             numberClass = 'four';
             break;
-          case  parseInt(res.length) <= 9 && parseInt(res.length) > 4:
+          case  resLength <= 9 && resLength > 4:
             numberClass = 'nine';
             break;
-          // case  parseInt(res.length) <= 9 && parseInt(res.length) > 6:
+          // case  resLength <= 9 && resLength > 6:
           //   numberClass = 'nine';
           //   break;
-          case parseInt(res.length) <= 16 && parseInt(res.length) > 9:
+          case resLength <= 16 && resLength > 9:
             numberClass = 'sixteen';
             break;
-          case parseInt(res.length) <= 25 && parseInt(res.length) > 16:
+          case resLength <= 25 && resLength > 16:
             numberClass = 'twentyFive';
             break;
-          case parseInt(res.length) >= 26:
+          case resLength >= 26:
             numberClass = 'twentyFive';
             break;
         }