diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 6031398..363b9e0 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -5,15 +5,10 @@ import * as enums from './common/enums'; import * as wsApi from './common/wssocket'; import UNI_APP from '@/.env.js' - + import { getCurrentInstance } from 'vue' export default { data() { return { - chatStore: this.useChatStore(), - friendStore: this.useFriendStore(), - groupStore: this.useGroupStore(), - configStore: this.useConfigStore(), - userStore: this.useUserStore(), isExit: false, // 是否已退出 audioTip: null, reconnecting: false // 正在重连标志 @@ -355,10 +350,10 @@ } }, onLaunch() { + this.$mountStore(); // 登录状态校验 let loginInfo = uni.getStorageSync("loginInfo") if (!this.isExpired(loginInfo)) { - console.log("初始化") // 初始化 this.init(); // 跳转到聊天页面 diff --git a/im-uniapp/components/chat-at-box/chat-at-box.vue b/im-uniapp/components/chat-at-box/chat-at-box.vue index d40518a..a44a179 100644 --- a/im-uniapp/components/chat-at-box/chat-at-box.vue +++ b/im-uniapp/components/chat-at-box/chat-at-box.vue @@ -49,7 +49,6 @@ }, data() { return { - userStore: this.useUserStore(), searchText: "", showMembers:[] }; diff --git a/im-uniapp/components/chat-group-readed/chat-group-readed.vue b/im-uniapp/components/chat-group-readed/chat-group-readed.vue index 117636d..a55649b 100644 --- a/im-uniapp/components/chat-group-readed/chat-group-readed.vue +++ b/im-uniapp/components/chat-group-readed/chat-group-readed.vue @@ -37,7 +37,6 @@ name: "chat-group-readed", data() { return { - chatStore: this.useChatStore(), items: ['已读', '未读'], current: 0, readedMembers: [], diff --git a/im-uniapp/components/group-rtc-join/group-rtc-join.vue b/im-uniapp/components/group-rtc-join/group-rtc-join.vue index 2ffcec1..6b36b55 100644 --- a/im-uniapp/components/group-rtc-join/group-rtc-join.vue +++ b/im-uniapp/components/group-rtc-join/group-rtc-join.vue @@ -26,7 +26,6 @@ export default { data() { return { - userStore: this.useUserStore(), rtcInfo: {} } }, diff --git a/im-uniapp/main.js b/im-uniapp/main.js index 1f3965c..7e5c597 100644 --- a/im-uniapp/main.js +++ b/im-uniapp/main.js @@ -22,6 +22,7 @@ import * as recorder from './common/recorder-app'; // #endif + export function createApp() { const app = createSSRApp(App) app.use(uviewPlus); @@ -33,12 +34,14 @@ export function createApp() { app.config.globalProperties.$enums = enums; app.config.globalProperties.$date = date; app.config.globalProperties.$rc = recorder; - app.config.globalProperties.useChatStore = useChatStore; - app.config.globalProperties.useFriendStore = useFriendStore; - app.config.globalProperties.useGroupStore = useGroupStore; - app.config.globalProperties.useConfigStore = useConfigStore; - app.config.globalProperties.useUserStore = useUserStore; - + // 初始化时再挂载store对象 + app.config.globalProperties.$mountStore = ()=>{ + app.config.globalProperties.chatStore = useChatStore(); + app.config.globalProperties.friendStore = useFriendStore(); + app.config.globalProperties.groupStore = useGroupStore(); + app.config.globalProperties.configStore = useConfigStore(); + app.config.globalProperties.userStore = useUserStore(); + } return { app, pinia diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index bee917f..64c943f 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -119,16 +119,10 @@