diff --git a/subPageC/Ai/index.vue b/subPageC/Ai/index.vue index b52ed76..f82845f 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 @@ -106,7 +107,7 @@ //是否长按事件 islongPress: false, timer: null, //长按计时器 - + param: { pageSize: 10, pageNo: 1, @@ -116,6 +117,7 @@ openid: undefined, appid: undefined, }, + nowUserId:null } }, onUnload() { @@ -126,19 +128,46 @@ this.outWs() }, onShow() { - const userInfo = uni.getStorageSync("userInfo"); - const extConfig = uni.getAccountInfoSync().miniProgram; - let appId = extConfig.appId - - this.param.openid = userInfo.openid - this.param.appid = appId - - this.$Request.get(this.$config.getHomestayOrderList, this.param, null, null, false, true).then((res) => { - this.getUserInfo() - this.connectWs() - }).catch(err=>{ - console.log(err) - }); + 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.nowUserId = response.data.userId + this.getUserInfo(response.data.userId) + }) + .catch(error => { + store.commit('setUserInfo', null) + uni.removeStorageSync('userInfo'); + setTimeout(() => { + uni.navigateBack({ delta: 1 }) + }, 1500) + uni.showToast({ + title: '登录过期,请重新登录', + icon: 'none', + mask: true + }) + }); + } + }, created: function() { const res = uni.getSystemInfoSync(); @@ -148,15 +177,15 @@ }, 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; + console.log('querUserInfo',this.querUserInfo) + this.connectWs() }, // websocket connectWs() { @@ -225,7 +254,7 @@ //发送消息 handlerMessage(data) { let $this = this - if (Number(data.userId) == Number(this.querUserInfo.userId)) { + if (Number(data.userId) == Number(this.querUserInfo.userId)) { if (data.identity == this.querUserInfo.identity) { if (data.context !== null) { this.list[this.list.length - 1].content += data.context @@ -275,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', @@ -351,12 +381,12 @@ } }) }, - //长按事件 + //长按事件 longpress() { const $this = this this.islongPress = true; if (this.islongPress == true && this.inputDisabled == false) { - //开始录音 + //开始录音 const _permission = 'scope.record' uni.getSetting({ success: (res) => { @@ -732,4 +762,4 @@ .loading-dot:nth-child(3) { animation-delay: 0.4s; } - \ No newline at end of file +