Browse Source

websocket请求

lihongxiao 1 năm trước cách đây
mục cha
commit
2a284edf51
2 tập tin đã thay đổi với 34 bổ sung31 xóa
  1. 27 27
      src/views/Home.vue
  2. 7 4
      src/views/Login.vue

+ 27 - 27
src/views/Home.vue

@@ -26,34 +26,34 @@ export default {
     NavBar,
     MainContent
   },
-  // created() {
-  //   setInterval(() => {
-  //     setTimeout(() => {
-  //       if (Cookies.get("token")) {
-  //         let userId = sessionStorage.getItem("user");
-  //         getUserIP((ip) => {
-  //           // getAddressLocation(ip, (info) => {
-  //             let data = {
-  //               ip,
-  //               systemType: '1',
-  //               userId
-  //             };
-  //             websocketSend(
-  //               data
-  //             );
-  //           // });
-  //         })
-  //       }
-  //       else {
-  //         closeWebsocket()
-  //       } 
-  //     }, 0);
-  //     // // }, 2 * 60 * 60000); // 两个小时
-  //      }, 19 * 60000); // 19分钟
-  //     // }, 20 * 60000); // 半小时
-  //   // }, 5000); // 一秒
+  created() {
+    setInterval(() => {
+      setTimeout(() => {
+        if (Cookies.get("token")) {
+          let userId = sessionStorage.getItem("user");
+          getUserIP((ip) => {
+            // getAddressLocation(ip, (info) => {
+              let data = {
+                ip,
+                systemType: '1',
+                userId
+              };
+              websocketSend(
+                data
+              );
+            // });
+          })
+        }
+        else {
+          closeWebsocket()
+        } 
+      }, 0);
+      // // }, 2 * 60 * 60000); // 两个小时
+       }, 19 * 60000); // 19分钟
+      // }, 20 * 60000); // 半小时
+    // }, 5000); // 一秒
 
-  // }
+  }
 
 };
 </script>

+ 7 - 4
src/views/Login.vue

@@ -198,6 +198,7 @@ export default {
       sysId: null,
       systemType: "1", //系统类型
       addressInfo: {}, //当前登录信息
+      locationIp:'',//当前ip
     };
   },
   created() {
@@ -326,7 +327,8 @@ export default {
                   setTimeout(() => {
                     let userId = sessionStorage.getItem("user");
                     let data = {
-                      ...this.addressInfo,
+                      // ...this.addressInfo,
+                      ip:this.locationIp,
                       userId,
                       systemType: this.systemType,
                     };
@@ -505,9 +507,10 @@ export default {
     this.refreshCaptcha();
     /**获取当前登录的ip地址 */
     getUserIP((ip) => {
-      getAddressLocation(ip, (info) => {
-        this.addressInfo = info;
-      });
+      this.locationIp=ip
+      // getAddressLocation(ip, (info) => {
+      //   this.addressInfo = info;
+      // });
     });
   },
   computed: {