每次進入綫路規劃都刷新token避免token過期導致無法創建長連接

lu_quan_dev
han 8 months ago
parent 114befaa04
commit 81c97c5086
  1. 55
      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
this.$Request.get(this.$config.getHomestayOrderList, this.param, null, null, false, true).then((res) => {
this.getUserInfo()
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(err=>{
console.log(err)
})
.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 +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() {

Loading…
Cancel
Save