From f35311c8057516fcc8442ac15cb062ace15f597c Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Mon, 2 Oct 2023 22:36:24 +0800 Subject: [PATCH] =?UTF-8?q?uniapp=20=20=E5=8D=95=E4=BA=BA=E6=96=87?= =?UTF-8?q?=E5=AD=97=E8=81=8A=E5=A4=A9=E3=80=81=E5=8F=91=E9=80=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/UserServiceImpl.java | 2 +- .../imserver/netty/tcp/TcpSocketServer.java | 2 +- .../bx/imserver/netty/ws/WebSocketServer.java | 2 +- im-ui/src/components/chat/ChatBox.vue | 10 +- im-uniapp/App.vue | 18 +- im-uniapp/common/request.js | 60 +----- .../components/friend-item/friend-item.vue | 19 +- im-uniapp/main.js | 9 +- im-uniapp/pages.json | 25 +-- im-uniapp/pages/chat/chat.vue | 6 +- im-uniapp/pages/common/user-info.vue | 93 ++++++--- im-uniapp/pages/login/login.vue | 178 ++++++++++++++++-- im-uniapp/static/iconfont/iconfont.ttf | Bin 1932 -> 0 bytes im-uniapp/store/chatStore.js | 53 +++--- im-uniapp/store/friendStore.js | 5 +- im-uniapp/store/groupStore.js | 2 +- im-uniapp/store/index.js | 9 +- im-uniapp/store/userStore.js | 7 +- 18 files changed, 315 insertions(+), 185 deletions(-) delete mode 100644 im-uniapp/static/iconfont/iconfont.ttf diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java index a5d1799..4e47101 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java @@ -103,7 +103,7 @@ public class UserServiceImpl extends ServiceImpl implements IU String strJson = JwtUtil.getInfo(refreshToken); Long userId = JwtUtil.getUserId(refreshToken); String accessToken = JwtUtil.sign(userId,strJson,jwtProperties.getAccessTokenExpireIn(),jwtProperties.getAccessTokenSecret()); - String newRefreshToken = JwtUtil.sign(userId,strJson,jwtProperties.getAccessTokenExpireIn(),jwtProperties.getAccessTokenSecret()); + String newRefreshToken = JwtUtil.sign(userId,strJson,jwtProperties.getRefreshTokenExpireIn(),jwtProperties.getRefreshTokenSecret()); LoginVO vo =new LoginVO(); vo.setAccessToken(accessToken); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); diff --git a/im-server/src/main/java/com/bx/imserver/netty/tcp/TcpSocketServer.java b/im-server/src/main/java/com/bx/imserver/netty/tcp/TcpSocketServer.java index 6143e4d..1e89d73 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/tcp/TcpSocketServer.java +++ b/im-server/src/main/java/com/bx/imserver/netty/tcp/TcpSocketServer.java @@ -59,7 +59,7 @@ public class TcpSocketServer implements IMServer { protected void initChannel(Channel ch) throws Exception { // 获取职责链 ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(new IdleStateHandler(15, 0, 0, TimeUnit.SECONDS)); + pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS)); pipeline.addLast("encode",new MessageProtocolEncoder()); pipeline.addLast("decode",new MessageProtocolDecoder()); pipeline.addLast("handler", new IMChannelHandler()); diff --git a/im-server/src/main/java/com/bx/imserver/netty/ws/WebSocketServer.java b/im-server/src/main/java/com/bx/imserver/netty/ws/WebSocketServer.java index 2d51ab8..efd4d6e 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/ws/WebSocketServer.java +++ b/im-server/src/main/java/com/bx/imserver/netty/ws/WebSocketServer.java @@ -63,7 +63,7 @@ public class WebSocketServer implements IMServer { protected void initChannel(Channel ch) throws Exception { // 获取职责链 ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(new IdleStateHandler(15, 0, 0, TimeUnit.SECONDS)); + pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS)); pipeline.addLast("http-codec", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65535)); pipeline.addLast("http-chunked", new ChunkedWriteHandler()); diff --git a/im-ui/src/components/chat/ChatBox.vue b/im-ui/src/components/chat/ChatBox.vue index 99047e6..4918033 100644 --- a/im-ui/src/components/chat/ChatBox.vue +++ b/im-ui/src/components/chat/ChatBox.vue @@ -134,7 +134,7 @@ loadStatus: "loading" } // 填充对方id - this.setTargetId(msgInfo, this.chat.targetId); + this.fillTargetId(msgInfo, this.chat.targetId); // 插入消息 this.$store.commit("insertMessage", msgInfo); // 滚动到底部 @@ -182,7 +182,7 @@ loadStatus: "loading" } // 填充对方id - this.setTargetId(msgInfo, this.chat.targetId); + this.fillTargetId(msgInfo, this.chat.targetId); // 插入消息 this.$store.commit("insertMessage", msgInfo); // 滚动到底部 @@ -232,7 +232,7 @@ type: 3 } // 填充对方id - this.setTargetId(msgInfo, this.chat.targetId); + this.fillTargetId(msgInfo, this.chat.targetId); this.$http({ url: this.messageAction, method: 'post', @@ -252,7 +252,7 @@ this.showVoice = false; }) }, - setTargetId(msgInfo, targetId) { + fillTargetId(msgInfo, targetId) { if (this.chat.type == "GROUP") { msgInfo.groupId = targetId; } else { @@ -269,7 +269,7 @@ type: 0 } // 填充对方id - this.setTargetId(msgInfo, this.chat.targetId); + this.fillTargetId(msgInfo, this.chat.targetId); this.lockMessage = true; this.$http({ url: this.messageAction, diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 23ee413..fc94f96 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -1,16 +1,18 @@ \ No newline at end of file diff --git a/im-uniapp/common/request.js b/im-uniapp/common/request.js index 0a652d8..ec8e148 100644 --- a/im-uniapp/common/request.js +++ b/im-uniapp/common/request.js @@ -1,14 +1,14 @@ -const BASE_URL = "http://192.168.43.6:8888" + + const request = (options) => { - const header = options.header||{}; - const accessToken = uni.getStorageSync("accessToken"); - if (accessToken) { - header.accessToken = accessToken; + const loginInfo = uni.getStorageSync("loginInfo"); + if (loginInfo) { + header.accessToken = loginInfo.accessToken; } return new Promise(function(resolve, reject) { uni.request({ - url: BASE_URL + options.url, + url: process.env.BASE_URL + options.url, method: options.method || 'GET', header: header, data: options.data || {}, @@ -21,8 +21,7 @@ const request = (options) => { }); } else if (res.data.code == 401) { console.log("token失效,尝试重新获取") - const refreshToken = uni.getStorageSync("refreshToken"); - if (!refreshToken) { + if (!loginInfo) { uni.navigateTo({ url: '/pages/login/login' }); @@ -32,7 +31,7 @@ const request = (options) => { method: 'PUT', url: '/refreshToken', header: { - refreshToken: refreshToken + refreshToken: loginInfo.refreshToken } }) // 换取token失败,跳转至登录界面 @@ -42,10 +41,7 @@ const request = (options) => { }); } // 保存token - uni.setStorageSync("accessToken", data.accessToken); - uni.setStorageSync("refreshToken", data.refreshToken); - // 这里需要把headers清掉,否则请求时会报错,原因暂不详... - //response.config.headers=undefined; + uni.setStorageSync("loginInfo", data); // 重新发送刚才的请求 return request(options) } else { @@ -58,44 +54,6 @@ const request = (options) => { } }, fail(error) { - switch (error.response.status) { - case 400: - uni.showToast({ - title: error.response.data, - type: 'error', - duration: 1500, - - }) - break - case 401: - uni.navigateTo({ - url: '/pages/login/login' - }); - break - case 405: - uni.showToast({ - title: 'http请求方式有误', - icon: 'error', - duration: 1500 - }) - break - case 404: - case 500: - uni.showToast({ - title: '服务器出了点小差,请稍后再试', - icon: 'error', - duration: 1500 - }) - break - case 501: - uni.showToast({ - title: '服务器不支持当前请求所需要的某个功能', - icon: 'error', - duration: 1500 - }) - break - } - return reject(error) } }); diff --git a/im-uniapp/components/friend-item/friend-item.vue b/im-uniapp/components/friend-item/friend-item.vue index 847abe1..2708a1d 100644 --- a/im-uniapp/components/friend-item/friend-item.vue +++ b/im-uniapp/components/friend-item/friend-item.vue @@ -12,13 +12,12 @@