From 81c97c508694e02861f2228a26341dcef2fc736e Mon Sep 17 00:00:00 2001 From: han <151435705@qq.com> Date: Tue, 4 Mar 2025 17:28:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E9=80=B2=E5=85=A5?= =?UTF-8?q?=E7=B6=AB=E8=B7=AF=E8=A6=8F=E5=8A=83=E9=83=BD=E5=88=B7=E6=96=B0?= =?UTF-8?q?token=E9=81=BF=E5=85=8Dtoken=E9=81=8E=E6=9C=9F=E5=B0=8E?= =?UTF-8?q?=E8=87=B4=E7=84=A1=E6=B3=95=E5=89=B5=E5=BB=BA=E9=95=B7=E9=80=A3?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- subPageC/Ai/index.vue | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/subPageC/Ai/index.vue b/subPageC/Ai/index.vue index fa0f2e5..a1625e1 100644 --- a/subPageC/Ai/index.vue +++ b/subPageC/Ai/index.vue @@ -59,6 +59,7 @@ mapState, mapMutations } from "vuex"; + import store from "@/store/index.js"; export default { components: { ZeroMarkdownView @@ -126,19 +127,46 @@ this.outWs() }, onShow() { - const userInfo = uni.getStorageSync("userInfo"); - const extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {}; - let appId = extConfig.app_id - - this.param.openid = userInfo.openid - this.param.appid = appId + const userInfo = uni.getStorageSync('userInfo'); + const refreshTokenValue = userInfo.refreshToken; + if (!refreshTokenValue){ + store.commit('setUserInfo', null) + uni.removeStorageSync('userInfo'); + setTimeout(() => { + uni.navigateBack({ delta: 1 }) + }, 1500) + uni.showToast({ + title: '登录过期,请重新登录', + icon: 'none', + mask: true + }) + }else{ + this.$Request.post(this.$config.refreshToken, { refreshToken: refreshTokenValue }, 'application/json', null, false, false) + .then(response => { + console.log('response',response) + const newAccessToken = response.data.accessToken; + const newRefreshToken = response.data.refreshToken; + userInfo.accessToken = newAccessToken; + userInfo.refreshToken = newRefreshToken; + store.commit('setUserInfo', userInfo) + this.Token = newAccessToken + this.getUserInfo(response.data.userId) + this.connectWs() + }) + .catch(error => { + store.commit('setUserInfo', null) + uni.removeStorageSync('userInfo'); + setTimeout(() => { + uni.navigateBack({ delta: 1 }) + }, 1500) + uni.showToast({ + title: '登录过期,请重新登录', + icon: 'none', + mask: true + }) + }); + } - this.$Request.get(this.$config.getHomestayOrderList, this.param, null, null, false, true).then((res) => { - this.getUserInfo() - this.connectWs() - }).catch(err=>{ - console.log(err) - }); }, created: function() { const res = uni.getSystemInfoSync(); @@ -148,15 +176,14 @@ }, methods: { // 用户信息 - getUserInfo() { + getUserInfo(userId) { this.querUserInfo = { "message": "", "dialogId": "", "identity": this.generateRandomString(8), - "userId": this.userInfo.userId + "userId": userId }; console.log(this.querUserInfo) - this.Token = this.userInfo.accessToken; }, // websocket connectWs() { From e8fa5cbdfd57afe7a2eaa32fd97380922a146435 Mon Sep 17 00:00:00 2001 From: han <151435705@qq.com> Date: Tue, 4 Mar 2025 18:01:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0userID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- subPageC/Ai/index.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/subPageC/Ai/index.vue b/subPageC/Ai/index.vue index a1625e1..2674c94 100644 --- a/subPageC/Ai/index.vue +++ b/subPageC/Ai/index.vue @@ -117,6 +117,7 @@ openid: undefined, appid: undefined, }, + nowUserId:null } }, onUnload() { @@ -150,8 +151,8 @@ userInfo.refreshToken = newRefreshToken; store.commit('setUserInfo', userInfo) this.Token = newAccessToken + this.nowUserId = response.data.userId this.getUserInfo(response.data.userId) - this.connectWs() }) .catch(error => { store.commit('setUserInfo', null) @@ -183,7 +184,8 @@ "identity": this.generateRandomString(8), "userId": userId }; - console.log(this.querUserInfo) + console.log('querUserInfo',this.querUserInfo) + this.connectWs() }, // websocket connectWs() { @@ -302,7 +304,8 @@ // 发送消息 sendMsg() { const $this = this - this.getUserInfo() + console.log('$this.nowUserId',$this.nowUserId) + this.getUserInfo($this.nowUserId) this.list.push({ content: this.content, userType: 'friend',