Ver Fonte

版本检测

lilei há 3 anos atrás
pai
commit
b5616ef8fa
3 ficheiros alterados com 28 adições e 1 exclusões
  1. 3 0
      public/version.json
  2. 22 0
      src/libs/versionUpdate.js
  3. 3 1
      src/permission.js

+ 3 - 0
public/version.json

@@ -0,0 +1,3 @@
+{
+    "version": "1.0.1"
+}

+ 22 - 0
src/libs/versionUpdate.js

@@ -0,0 +1,22 @@
+import axios from 'axios'
+ 
+const isNewVersion = () => {
+  let url = `//${window.location.host}/version.json?t=${new Date().getTime()}`;
+  axios.get(url).then(res => {
+    if (res.status === 200) {
+      let vueVersion = res.data.version;
+      let localVueVersion = localStorage.getItem('vueVersion');
+      if (localVueVersion && localVueVersion != vueVersion) {
+        localStorage.setItem('vueVersion', vueVersion);
+        window.location.reload();
+        return;
+      } else {
+        localStorage.setItem('vueVersion', vueVersion);
+      }
+    }
+  });
+}
+ 
+export default {
+  isNewVersion
+}

+ 3 - 1
src/permission.js

@@ -7,13 +7,15 @@ import '@/components/NProgress/nprogress.less' // progress bar custom style
 import notification from 'ant-design-vue/es/notification'
 import { setDocumentTitle, domTitle } from '@/utils/domUtil'
 import { ACCESS_TOKEN } from '@/store/mutation-types'
-
+import versionTood from '@/libs/versionUpdate'
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
 
 const whiteList = ['login', 'register', 'registerResult','updateBrowser'] // no redirect whitelist
 const defaultRoutePath = '/home'
 
 router.beforeEach((to, from, next) => {
+  //判断当前代码版本是否与服务器中代码版本一致,如不一致则刷新页面获取最新
+  versionTood.isNewVersion()
 	store.commit('TOGGLE_NOW_ROUTER',to.fullPath)
   NProgress.start() // start progress bar
   to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))