Refactor token handling and enable MQTT connection
This commit is contained in:
@ -67,6 +67,7 @@
|
||||
import { top } from '~/api/home/index'
|
||||
import type { ProjectDrawStatisticAppRespVO } from '~/api/home/type'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import refreshToken from "~/utils/RefreshToken";
|
||||
import useUserStore from '~/store/user'
|
||||
const userStore = useUserStore()
|
||||
const app = useNuxtApp()
|
||||
@ -88,6 +89,8 @@
|
||||
|
||||
// 是否登录
|
||||
const isLogin = computed(() => {
|
||||
console.log('userStore.token', userStore);
|
||||
|
||||
return !!userStore.token
|
||||
})
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@ import { getUserInfo } from "~/api/common/index";
|
||||
import type { AppMemberUserInfoRespVO } from "~/api/common/types";
|
||||
import MQTTClient from "~/utils/mqttClient";
|
||||
import { socialLoginByCode } from "~/api/pay";
|
||||
const app = useNuxtApp();
|
||||
|
||||
export default defineStore("useUserStore", {
|
||||
|
||||
state: () => ({
|
||||
token: refreshToken.getToken().token || "",
|
||||
refreshToken: refreshToken.getToken().refreshToken || "",
|
||||
@ -32,7 +32,7 @@ export default defineStore("useUserStore", {
|
||||
logout() {
|
||||
refreshToken.removeToken();
|
||||
if (self === top) {
|
||||
navigateTo("/index");
|
||||
navigateTo("/");
|
||||
} else {
|
||||
window.top?.postMessage({ event: "logout" }, "*");
|
||||
}
|
||||
@ -49,19 +49,20 @@ export default defineStore("useUserStore", {
|
||||
// 建立连接mqtt
|
||||
async connectMqtt() {
|
||||
if (process.client) {
|
||||
// this.mqttClient = new MQTTClient("wss://www.tuxixi.net/mqtt", {
|
||||
// clientId: this.userInfoRes.id,
|
||||
// });
|
||||
// await this.mqttClient.connect();
|
||||
// await this.mqttClient?.subscribe(
|
||||
// `zbjk_message_single/${this.userInfoRes.id}`
|
||||
// );
|
||||
// await this.mqttClient?.subscribe(
|
||||
// `zbjk_message_kefu/${this.userInfoRes.id}`
|
||||
// );
|
||||
this.mqttClient = new MQTTClient("wss://www.tuxixi.net/mqtt", {
|
||||
clientId: this.userInfoRes.id,
|
||||
});
|
||||
await this.mqttClient.connect();
|
||||
await this.mqttClient?.subscribe(
|
||||
`zbjk_message_single/${this.userInfoRes.id}`
|
||||
);
|
||||
await this.mqttClient?.subscribe(
|
||||
`zbjk_message_kefu/${this.userInfoRes.id}`
|
||||
);
|
||||
}
|
||||
},
|
||||
async getToken(row: any) {
|
||||
const app = useNuxtApp();
|
||||
try {
|
||||
// 验证state
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user