lihongxiao hai 1 ano
pai
achega
e8e0a1e3e9
Modificáronse 4 ficheiros con 25 adicións e 15 borrados
  1. 2 2
      config/dev.env.js
  2. 11 5
      src/utils/ipAndAddress.js
  3. 3 3
      src/views/Home.vue
  4. 9 5
      src/views/Login.vue

+ 2 - 2
config/dev.env.js

@@ -22,8 +22,8 @@ module.exports = merge(prodEnv, {
   CONSOLE_BASE_URL: '"http://localhost:8080/"', //控制台测试服务器
   // CONSOLE_BASE_URL: '"https://test.baoxianzhanggui.com/console-api"' //控制台正式服务器
   APP_BASE_URL: '"https://pre.baoxianzhanggui.com/web-api"',    // app打包上传地址
-  // SOCKET_Url: '"ws://192.168.0.52:8080/"',
-  SOCKET_Url: '"wss://sxzgkj.baoxianzhanggui.com/web-api/"',
+  SOCKET_Url: '"ws://192.168.0.52:8080/"',
+  // SOCKET_Url: '"wss://sxzgkj.baoxianzhanggui.com/web-api/"',
 
 
 })

+ 11 - 5
src/utils/ipAndAddress.js

@@ -24,13 +24,19 @@ export async function getUserLocation(ipInfo, callback) {
 // 获取当前登录的地理 信息
 export async function getAddressLocation(ipInfo, callback) {
   // await fetch(`https://qifu-api.baidubce.com/ip/geo/v1/district?ip=${ipInfo}`)
-  await fetch(`http://ip-api.com/json/${ipInfo}?lang=zh-CN`)
+  // await fetch(`http://ip-api.com/json/${ipInfo}?lang=zh-CN`)
+  await fetch(`http://demo.ip-api.com/json/${ipInfo}?fields=66842623&lang=zh-CN `)
+  // const headers = new Headers({
+  //   'Authorization': 'APPCODE 1408028eb249479cbeeb9d20f611db79'
+  // });
+  // await fetch(`https://c2ba.api.huachen.cn/ip?ip=${ipInfo}`,{
+  //   headers: headers, 
+  // })
     .then(response => response.json())
     .then(res => {
-      callback({ip: res.query,lng:res.lon,lat:res.lat,prov:res.regionName,city:res.city,district:''});
-      // if (res.code === 'Success') {
-      //   callback({ ...res.data, ip: res.ip });
-      // }
+       if (res.ret === 200) {
+        callback({ ...res.data, prov: res.data.region });
+        }
     })
     .catch(error => console.log(error));
 }

+ 3 - 3
src/views/Home.vue

@@ -32,16 +32,16 @@ export default {
         if (Cookies.get("token")) {
           let userId = sessionStorage.getItem("user");
           getUserIP((ip) => {
-            getAddressLocation(ip, (info) => {
+            // getAddressLocation(ip, (info) => {
               let data = {
-                ...info,
+                ip,
                 systemType: '1',
                 userId
               };
               websocketSend(
                 data
               );
-            });
+            // });
           })
         }
         else {

+ 9 - 5
src/views/Login.vue

@@ -198,6 +198,7 @@ export default {
       sysId: null,
       systemType: "1", //系统类型
       addressInfo: {}, //当前登录信息
+      locationIp:'',//当前ip
     };
   },
   created() {
@@ -311,7 +312,8 @@ export default {
                   setTimeout(() => {
                     let userId = sessionStorage.getItem("user");
                     let data = {
-                      ...this.addressInfo,
+                      // ...this.addressInfo,
+                      ip:this.locationIp,
                       userId,
                       systemType: this.systemType,
                     };
@@ -341,7 +343,8 @@ export default {
     submitLocation() {
       let location = {
         systemType: this.systemType,
-        ...this.addressInfo,
+        // ...this.addressInfo,
+        ip:this.locationIp,
       };
       this.$api.login.uploadLocationInfo(location).then((res) => {
         if (res.code !== 200) {
@@ -489,9 +492,10 @@ export default {
     this.refreshCaptcha();
     /**获取当前登录的ip地址 */
     getUserIP((ip) => {
-      getAddressLocation(ip, (info) => {
-        this.addressInfo = info;
-      });
+      this.locationIp=ip
+      // getAddressLocation(ip, (info) => {
+        // this.addressInfo = ip;
+      // });
     });
   },
   computed: {