Explorar el Código

[add] app check update version

x hace 5 años
padre
commit
5ca2393edb
Se han modificado 1 ficheros con 35 adiciones y 0 borrados
  1. 35 0
      src/views/home/Index.vue

+ 35 - 0
src/views/home/Index.vue

@@ -663,6 +663,7 @@
   </div>
 </template>
 <script>
+import axios from "axios";
 import { getUserInfo } from "@api/user";
 import { swiper, swiperSlide } from "vue-awesome-swiper";
 import "@assets/css/swiper.min.css";
@@ -891,9 +892,11 @@ export default {
     var processUri = function(params) {
       that.$router.push({ path: params.uri });
     };
+    this.$store.commit("LOAD");
 
     JPush.init(processUri);
     WeChat.init();
+    this.checkUpdate();
 
     this.updateVIP();
     // this.getFollow();
@@ -914,6 +917,38 @@ export default {
     }
   },
   methods: {
+    checkUpdate() {
+			var that = this;
+      if (typeof(cordova) == "undefined") {
+        return;
+      }
+			
+      axios.get("http://qndownload.shotshock.shop/version?ts=" + Date.parse(new Date())).then(res => {
+        var ver = res.data.version
+        var url = res.data.download
+        console.log(JSON.stringify(res.data))
+				console.log(navigator.platform)
+        cordova.getAppVersion.getVersionNumber().then(version => {
+          console.log("current version: " + version);
+          console.log("remote  version: " + ver);
+          if (ver > version) {
+            console.log("current need update !");
+            that.$dialog.confirm({
+							mes: "检查到有新版本,点击确定去下载!", 
+							title: "更新提示",
+							opts: () => {
+								cordova.InAppBrowser.open(url, "_system")
+							}
+						});
+          } else {
+            console.log("current alreay is latest !");
+          }
+        });
+      }).catch(err => {
+        // that.$dialog.error("检查更新失败!")
+      });
+    },
+
     updateVIP() {
       var userinfo = this.$store.state.app.userInfo;
       if (this.$store.state.app.token) {