diff --git a/im-web/src/api/date.js b/im-web/src/api/date.js index 3407a13..cd4fc17 100644 --- a/im-web/src/api/date.js +++ b/im-web/src/api/date.js @@ -4,16 +4,16 @@ let toTimeText = (timeStamp, simple) => { var timeDiff = currentTime - dateTime; //与当前时间误差 var timeText = ''; if (timeDiff <= 60000) { //一分钟内 - timeText = 'Just now'; + timeText = '刚刚'; } else if (timeDiff > 60000 && timeDiff < 3600000) { //1小时内 - timeText = Math.floor(timeDiff / 60000) + ' minutes ago'; + timeText = Math.floor(timeDiff / 60000) + '分钟前'; } else if (timeDiff >= 3600000 && timeDiff < 86400000 && !isYestday(dateTime)) { //今日 timeText = formatDateTime(dateTime).substr(11, 5); } else if (isYestday(dateTime)) { //昨天 - timeText = 'Yesterday ' + formatDateTime(dateTime).substr(11, 5); + timeText = '昨天' + formatDateTime(dateTime).substr(11, 5); } else if (isYear(dateTime)) { //今年 timeText = formatDateTime(dateTime).substr(5, simple ? 5 : 14); diff --git a/im-web/src/components/chat/ChatBox.vue b/im-web/src/components/chat/ChatBox.vue index ebb383f..8fcac66 100644 --- a/im-web/src/components/chat/ChatBox.vue +++ b/im-web/src/components/chat/ChatBox.vue @@ -863,11 +863,17 @@ export default { url: `/user/find/${friendId}`, method: "GET", }); - this.userInfo = userInfo; + + // 先获取IP地址信息 + let location = ""; if (userInfo.lastLoginIp) { - const location = await this.getIpLocation(userInfo.lastLoginIp); + location = await this.getIpLocation(userInfo.lastLoginIp); this.ipLocation = location; } + + // 然后再设置 userInfo,这样IP和地址会一起显示 + this.userInfo = userInfo; + this.updateFriendInfo(); await this.loadLabelOptions(friendId); this.selectedLabels = []; @@ -1036,34 +1042,13 @@ export default { async getIpLocation(ip) { if (!ip) return ""; try { - const response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`); - const data = await response.json(); - if (data && data.status === "success") { - let location = []; - if (data.country) location.push(data.country); - if (data.regionName) location.push(data.regionName); - if (data.city) location.push(data.city); - return location.join(" "); - } - return ""; + // 请求后端 + const res = await this.$http.get(`/user/ip/location?ip=${ip}`); + console.log("IP定位结果:", res); + // res 就是后端返回的 data 里的内容 + return res || ""; } catch (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); - } + console.error("IP定位失败:", error); return ""; } }, diff --git a/im-web/src/view/Home.vue b/im-web/src/view/Home.vue index cf14feb..7d2e02f 100644 --- a/im-web/src/view/Home.vue +++ b/im-web/src/view/Home.vue @@ -39,7 +39,6 @@ --> -
@@ -84,7 +83,6 @@
- -