浏览代码

检查本机和服务器时间的差异

Michael Wang 6 年之前
父节点
当前提交
5aa0be85fe
共有 2 个文件被更改,包括 9 次插入1 次删除
  1. 8 0
      src/features/Login/Login.vue
  2. 1 1
      vue.config.js

+ 8 - 0
src/features/Login/Login.vue

@@ -48,6 +48,7 @@
 </template>
 
 <script>
+import moment from "moment";
 /**
  * 在任何组件需要强制退出,做以下步骤
  * 1. this.$Message.info()
@@ -112,6 +113,12 @@ export default {
           domain: this.$route.params.domain
         });
         let data = response.data;
+        if (
+          Math.abs(moment(response.headers.date).diff(moment())) >
+          30 * 1000
+        ) {
+          throw "与服务器时间差异超过30秒,请校准本机时间之后再重试!";
+        }
         if (data.token) {
           this.errorInfo = "";
           //缓存用户信息
@@ -129,6 +136,7 @@ export default {
         }
       } catch (e) {
         console.log(e);
+        this.$Message.error(e);
       }
     }
   }

+ 1 - 1
vue.config.js

@@ -1,6 +1,6 @@
 let proxy = {
   "/api": {
-    target: "http://192.168.10.39:8878", // 考务 王伟
+    target: "https://192.168.10.39:8878", // 考务 王伟
     changeOrigin: true
   }
 };