|
|
@ -863,11 +863,17 @@ export default { |
|
|
url: `/user/find/${friendId}`, |
|
|
url: `/user/find/${friendId}`, |
|
|
method: "GET", |
|
|
method: "GET", |
|
|
}); |
|
|
}); |
|
|
this.userInfo = userInfo; |
|
|
|
|
|
|
|
|
// 先获取IP地址信息 |
|
|
|
|
|
let location = ""; |
|
|
if (userInfo.lastLoginIp) { |
|
|
if (userInfo.lastLoginIp) { |
|
|
const location = await this.getIpLocation(userInfo.lastLoginIp); |
|
|
location = await this.getIpLocation(userInfo.lastLoginIp); |
|
|
this.ipLocation = location; |
|
|
this.ipLocation = location; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 然后再设置 userInfo,这样IP和地址会一起显示 |
|
|
|
|
|
this.userInfo = userInfo; |
|
|
|
|
|
|
|
|
this.updateFriendInfo(); |
|
|
this.updateFriendInfo(); |
|
|
await this.loadLabelOptions(friendId); |
|
|
await this.loadLabelOptions(friendId); |
|
|
this.selectedLabels = []; |
|
|
this.selectedLabels = []; |
|
|
@ -1036,34 +1042,13 @@ export default { |
|
|
async getIpLocation(ip) { |
|
|
async getIpLocation(ip) { |
|
|
if (!ip) return ""; |
|
|
if (!ip) return ""; |
|
|
try { |
|
|
try { |
|
|
const response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`); |
|
|
// 请求后端 |
|
|
const data = await response.json(); |
|
|
const res = await this.$http.get(`/user/ip/location?ip=${ip}`); |
|
|
if (data && data.status === "success") { |
|
|
console.log("IP定位结果:", res); |
|
|
let location = []; |
|
|
// res 就是后端返回的 data 里的内容 |
|
|
if (data.country) location.push(data.country); |
|
|
return res || ""; |
|
|
if (data.regionName) location.push(data.regionName); |
|
|
|
|
|
if (data.city) location.push(data.city); |
|
|
|
|
|
return location.join(" "); |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
|
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error("获取IP地理位置失败:", error); |
|
|
console.error("IP定位失败:", error); |
|
|
try { |
|
|
|
|
|
const backupResponse = await fetch( |
|
|
|
|
|
`https://whois.pconline.com.cn/ipJson.jsp?ip=${ip}&json=true` |
|
|
|
|
|
); |
|
|
|
|
|
const text = await backupResponse.text(); |
|
|
|
|
|
const data = JSON.parse(text); |
|
|
|
|
|
if (data) { |
|
|
|
|
|
let location = []; |
|
|
|
|
|
if (data.pro) location.push(data.pro); |
|
|
|
|
|
if (data.city) location.push(data.city); |
|
|
|
|
|
if (data.addr) location.push(data.addr); |
|
|
|
|
|
return location.join(" "); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (backupError) { |
|
|
|
|
|
console.error("备用API也失败了:", backupError); |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|