diff --git a/.env.production b/.env.production index 4b5a015..0f7253f 100644 --- a/.env.production +++ b/.env.production @@ -1,5 +1,5 @@ -MP_API_BASE_URL=https://ytk.youcan365.com -MP_IMAGE_URL=https://ytk.youcan365.com +MP_API_BASE_URL=https://ykt.youcan365.com +MP_IMAGE_URL=https://ykt.youcan365.com MP_CACHE_PREFIX=production MP_WX_APP_ID=wx1d8337a40c11d66c MP_CORP_ID=wpLgjyawAA8N0gWmXgyJq8wpjGcOT7fg diff --git a/package.json b/package.json index c1c3bdf..0a76c7f 100644 --- a/package.json +++ b/package.json @@ -1,40 +1,46 @@ -{ - "name": "ykt-wxapp", - "version": "1.0.0", - "description": "", - "main": "main.js", - "scripts": { - "prebuild": "node scripts/pre-build.js", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "dayjs": "^1.11.10", - "tim-upload-plugin": "^1.4.2", - "tim-wx-sdk": "^2.27.6" - }, - "uni-app": { - "scripts": { - "dev": { - "title": "测试", - "env": { - "UNI_PLATFORM": "mp-weixin" - } - }, - "localhost": { - "title": "本地", - "env": { - "UNI_PLATFORM": "mp-weixin" - } - }, - "ip": { - "title": "本机ip", - "env": { - "UNI_PLATFORM": "mp-weixin" - } - } - } - }, - "devDependencies": {} +{ + "name": "ykt-wxapp", + "version": "1.0.0", + "description": "", + "main": "main.js", + "scripts": { + "prebuild": "node scripts/pre-build.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "dayjs": "^1.11.10", + "tim-upload-plugin": "^1.4.2", + "tim-wx-sdk": "^2.27.6" + }, + "uni-app": { + "scripts": { + "dev": { + "title": "测试", + "env": { + "UNI_PLATFORM": "mp-weixin" + } + }, + "localhost": { + "title": "本地", + "env": { + "UNI_PLATFORM": "mp-weixin" + } + }, + "pro": { + "title": "线上", + "env": { + "UNI_PLATFORM": "mp-weixin" + } + }, + "ip": { + "title": "本机ip", + "env": { + "UNI_PLATFORM": "mp-weixin" + } + } + } + }, + "devDependencies": {} } \ No newline at end of file diff --git a/pages/home/message-home.vue b/pages/home/message-home.vue index a8cba98..5270017 100644 --- a/pages/home/message-home.vue +++ b/pages/home/message-home.vue @@ -101,7 +101,9 @@ import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.j import MessageHeader from "../home/components/message-header.vue"; // 获取登录状态 -const { account, openid, isIMInitialized } = storeToRefs(useAccountStore()); +const { account, openid, isIMInitialized, doctorInfo } = storeToRefs( + useAccountStore() +); const { initIMAfterLogin } = useAccountStore(); // 获取团队信息 @@ -277,26 +279,12 @@ const handleReloginIM = async () => { uni.hideLoading(); if (success) { - // uni.showToast({ - // title: "IM连接成功", - // icon: "success", - // }); - // 重新加载会话列表 await loadConversationList(); setupConversationListener(); - } else { - // uni.showToast({ - // title: "IM连接失败,请检查网络", - // icon: "none", - // }); } } catch (error) { uni.hideLoading(); console.error("重新登陆IM失败:", error); - // uni.showToast({ - // title: "重新登陆失败", - // icon: "none", - // }); } }; @@ -304,6 +292,13 @@ const handleReloginIM = async () => { const loadConversationList = async () => { if (loading.value) return; loading.value = true; + + const accountStore = useAccountStore(); + if (!doctorInfo.value?.userid) { + console.warn("userId 未获取,跳过加载会话列表"); + loading.value = false; + return; + } try { console.log("开始加载群聊列表"); @@ -317,7 +312,7 @@ const loadConversationList = async () => { console.warn("TIM实例不存在,尝试重新初始化IM"); const reinitialized = await initIMAfterLogin(); if (!reinitialized) { - throw new Error("IM重新初始化失败"); + // throw new Error("IM重新初始化失败"); } } @@ -636,7 +631,9 @@ const handleClickConversation = (conversation) => { // 跳转到聊天页面 uni.navigateTo({ - url: `/pages/message/index?conversationID=${encodeURIComponent(conversation.conversationID)}&groupID=${encodeURIComponent(conversation.groupID)}`, + url: `/pages/message/index?conversationID=${encodeURIComponent( + conversation.conversationID + )}&groupID=${encodeURIComponent(conversation.groupID)}`, }); }; diff --git a/pages/message/message.vue b/pages/message/message.vue deleted file mode 100644 index 2e7e741..0000000 --- a/pages/message/message.vue +++ /dev/null @@ -1,796 +0,0 @@ - - - - - diff --git a/store/account.js b/store/account.js index 82d41d9..12eba8e 100644 --- a/store/account.js +++ b/store/account.js @@ -82,6 +82,9 @@ export default defineStore("accountStore", () => { async function getDoctorInfo(data = {}) { try { + if (!account.value?.openid) { + return + } const res = await api('getCorpMemberData', { ...data, weChatOpenId: account.value.openid, @@ -112,12 +115,9 @@ export default defineStore("accountStore", () => { await getDoctorInfo(); } try { - const userID = doctorInfo.value.userid; + const userID = doctorInfo.value?.userid; if (!userID) { - await getDoctorInfo(); - if (!doctorInfo.value?.userid) { - throw new Error('无法获取用户ID'); - } + return } const success = await initGlobalTIM(userID); diff --git a/utils/tim-chat.js b/utils/tim-chat.js index 14d8ed4..1db8052 100644 --- a/utils/tim-chat.js +++ b/utils/tim-chat.js @@ -1033,7 +1033,7 @@ class TimChatManager { // 检查userId是否存在,不存在则不需要初始化 if (!this.currentUserID) { console.error('currentUserID不存在,无法获取群聊列表') - reject(new Error('用户ID不存在')) + reject() return } diff --git a/vite.config.js b/vite.config.js index e957f3e..4f4b8ca 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,43 +1,43 @@ -import { - loadEnv -} from "vite"; -import uni from "@dcloudio/vite-plugin-uni"; - -export default (command, mode) => { - //uniapp中,这个mode,不用命令行的添加--mode编译的话,是undefined的 - if (!mode) { - //这里是为了确保mode有值,假如开发人员直接在开发工具选择编译到浏览器,也能兼容到 - if (process.env.NODE_ENV == "production") { - mode = "production"; - } else { - mode = "development"; - } - } - //这个就是第三步配置的uni-app的script,一一对应判断 - switch (process.env.UNI_SCRIPT) { - case "dev": - mode = "development"; - break; - case "localhost": - mode = "localhost"; - break; - case "ip": - mode = "ip"; - break; - default: - mode = "production"; - break; - } - const env = loadEnv(mode, __dirname, "MP_"); - console.log('mode: ', mode); - console.log(process.env.UNI_SCRIPT) - console.log(`📦 正在编译 ${mode} 环境`); - return { - envPrefix: "MP_", - plugins: [uni()], - define: { - //根据vite的官方文档,可以把define定义的变量名,在项目编译时,识别项目文件中的这个变量名直接替换成env配置,我们把这个变量放到config.js文件中,对env配置进行集中管理 - __VITE_ENV__: JSON.stringify(env), - }, - }; +import { + loadEnv +} from "vite"; +import uni from "@dcloudio/vite-plugin-uni"; + +export default (command, mode) => { + //uniapp中,这个mode,不用命令行的添加--mode编译的话,是undefined的 + if (!mode) { + //这里是为了确保mode有值,假如开发人员直接在开发工具选择编译到浏览器,也能兼容到 + if (process.env.NODE_ENV == "production") { + mode = "production"; + } else { + mode = "development"; + } + } + //这个就是第三步配置的uni-app的script,一一对应判断 + switch (process.env.UNI_SCRIPT) { + case "dev": + mode = "development"; + break; + case "localhost": + mode = "localhost"; + break; + case "ip": + mode = "ip"; + break; + default: + mode = "production"; + break; + } + const env = loadEnv(mode, __dirname, "MP_"); + console.log('mode: ', mode); + console.log(process.env.UNI_SCRIPT) + console.log(`📦 正在编译 ${mode} 环境`); + return { + envPrefix: "MP_", + plugins: [uni()], + define: { + //根据vite的官方文档,可以把define定义的变量名,在项目编译时,识别项目文件中的这个变量名直接替换成env配置,我们把这个变量放到config.js文件中,对env配置进行集中管理 + __VITE_ENV__: JSON.stringify(env), + }, + }; }; \ No newline at end of file