ソースを参照

改进时间处理方法,增加每日定时重启APP功能

wzx 3 年 前
コミット
9fa3e13f91

+ 3 - 3
src/Global.js

@@ -25,7 +25,7 @@ if (appType == 1) {    // 1: 小飞龙
 
 
 // 本机测试 TV端映射到本机进行测试
-// runVersion = 'localtest';    //tmp mod
+runVersion = 'localtest';    //tmp mod
 
 // 当前版本   演示版
 // runVersion = 'test';
@@ -34,7 +34,7 @@ if (appType == 1) {    // 1: 小飞龙
 // runVersion = 'outDoor';
 
 // 正式版 normal
-runVersion = 'normal';
+// runVersion = 'normal';
 
 // headapi = process.env.NODE_ENV === 'development' ? '/api/' : '../';
 // headapi = 'http://127.0.0.1/';           //从本机获得数据源
@@ -48,7 +48,7 @@ if (runVersion == 'normal')
 // 七牛云imgsrc
 imgUrl = "http://qjzpcd34v.hb-bkt.clouddn.com";
 
-// pad测试版本
+timer_headclock = null;
 
 // 常用选项
 globalQuipState = function () {

BIN
src/assets/font/Artifakt.ttf


BIN
src/assets/font/vista.otf


+ 49 - 40
src/components/Headside.vue

@@ -43,7 +43,7 @@
 </template>
 
 <script>
-import global from '../Global'
+import '../Global'
 import '../libs/rem';
 import QRCode from 'qrcodejs2'
 
@@ -66,62 +66,71 @@ export default {
       curLogoClass: 'logo_bsw',
       currunVersion: runVersion,
       curheadapi: headapi,
-      timer: null,
+      // timer: null,
     }
   },
   mounted() {
     console.log("Headside mounted");
-    // console.log("this.timer = " + this.timer);
+    console.log("route: " + this.$route.path);
+    console.log("[Headside mounted] timer_headclock = " + timer_headclock);
 
     this.getLogo();
+    this.getCurVersion();
 
-    if (this.timer == null) {
-      this.timer = setInterval(() => {
-        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 s = date.getSeconds()
-        s = s < 10 ? '0' + s : s;
-
-        this.nowTime = h + m + s;
-        // this.nowTime = h + m;
-        // console.log(this.nowTime);
+    this.clearTimer();
+    console.log("[Headside mounted] clearTimer run! timer_headclock = " + timer_headclock);
 
-        this.nowDayFunc();
-        
-        // 获取版本号
-        this.version = localStorage.version;
-        this.currunVersion = runVersion
-        this.curheadapi = headapi
+    // 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");
-        clearInterval(this.timer);
-        this.timer = null;
+        console.log("[Headside hook:beforeDestroy] timer_headclock = " + timer_headclock);
+        this.clearTimer();
+        console.log("[Headside hook:beforeDestroy] timer_headclock = " + timer_headclock);
       });
     }
-
-    this.getCurVersion();
+    else {
+      console.log("[Headside mounted] 不加载时间 timer_headclock = " + timer_headclock);
+    }
   },
-  // watch: {
-  //   '$route': function (val) {
-  //     console.log("Headside val.path: " + val.path);
-  //     clearInterval(this.timer);
-  //     this.timer = null;
-  //   }
-  // },
   // beforeDestroy() {
-  //   console.log("Headside beforeDestroy");
-  //   clearInterval(this.timer);
-  //   this.timer = null;
+  //   console.log("[Headside beforeDestroy] timer_headclock = " + timer_headclock);
+  //   this.clearTimer();
+  //   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 + ':';
+
+      let m = date.getMinutes();
+      m = m < 10 ? '0' + m + ':' : m + ':';
+
+      let s = date.getSeconds();
+      s = s < 10 ? '0' + s : s;
+
+      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;
+    },
     getLogo() {
       if (this.curAppType == 1) {    // 1: 小飞龙
         this.curLogoImg = logo_xfl;

+ 38 - 5
src/views/Index.vue

@@ -51,7 +51,9 @@ export default {
         'd76a54a795fb5774', // 公司电视盒2
         '9ecb2cb6cb3bf318', // 公司电视盒2 基座测试
         '30:9C:23:0C:8B:1E', // 默认
-      ]
+      ],
+      intervTime_checkUpdate: 600000, //检测升级信息的轮询时间 毫秒
+      appRuntime: 0, //APP运行时长 分钟
     }
   }, 
   mounted() {
@@ -111,23 +113,38 @@ export default {
             // 教室版本自动升级,户外版禁用自动升级
             if (runVersion == 'outDoor') {
               console.log('户外版禁用自动升级');
+              
+              setInterval(() => {
+                that.checkAppRuntime();
+              }, that.intervTime_checkUpdate);
+
               return false
-            } else if (runVersion == 'localtest') {
+            } 
+            else if (runVersion == 'localtest') {
               console.log('本机测试禁用自动升级');
               plus.nativeUI.toast("本机测试 禁用自动升级 UUID: " + uuid);
+
+              setInterval(() => {
+                that.checkAppRuntime();
+              }, that.intervTime_checkUpdate);
+              
               return false
-            } else {
+            } 
+            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");
+                  console.log(">>> checkUpdate");
                   that.checkUpdate();
                 }
-              }, 600000);
+              }, that.intervTime_checkUpdate);
             }
           },
           fail: function (e) {
@@ -136,6 +153,18 @@ export default {
         });
       }
     },
+    checkAppRuntime() {
+      let that = this;
+      that.appRuntime += that.intervTime_checkUpdate / 1000 / 60; //更新APP运行时长 分钟
+      console.log('>>> App Runtime: ' + that.appRuntime + ' 分钟');
+      let date = new Date();
+      if (date.getHours() == 6 && that.appRuntime >= 720) {  //每天早上6点 且 运行时长大于12小时
+      // if (date.getHours() == 13 && that.appRuntime >= 1) {
+        plus.nativeUI.toast("APP即将重启,请稍等...");
+        that.restartApp();
+        that.appRuntime = 0;
+      }
+    },
     // 是否有新版本
     checkUpdate() {
       let that = this;
@@ -191,6 +220,10 @@ export default {
         plus.nativeUI.toast("升级失败[" + e.code + "]:" + e.message);
       });
     },
+    // 重启当前的应用
+    restartApp() {
+      plus.runtime.restart();
+    },
     // 获取配置参数
     getConfigParam(eqsn) {
       const that = this;

+ 4 - 4
src/views/Wait.vue

@@ -488,10 +488,10 @@ ul, li {
   padding: 0;
 }
 
-@font-face {
-  font-family: Artifakt;
-  src: url('../assets/font/Artifakt.ttf');
-}
+// @font-face {
+//   font-family: Artifakt;
+//   src: url('../assets/font/Artifakt.ttf');
+// }
 
 @font-face {
   font-family: Georgia;