fix: 问题修复

This commit is contained in:
huxuejian 2026-04-30 17:55:34 +08:00
parent e47d5b4dd8
commit 6d97ecfb43
4 changed files with 125 additions and 163 deletions

View File

@ -51,6 +51,9 @@
</view> </view>
</template> </template>
</view> </view>
<template #footer>
<button-footer :showCancel="false" confirmText="返回首页" @confirm="backHome" />
</template>
</full-page> </full-page>
</template> </template>
<script setup> <script setup>
@ -62,6 +65,7 @@ import useAccount from '@/store/account';
import api from '@/utils/api'; import api from '@/utils/api';
import FullPage from '@/components/full-page.vue'; import FullPage from '@/components/full-page.vue';
import buttonFooter from '@/components/button-footer.vue';
const team = ref(null); const team = ref(null);
const { useLoad } = useGuard(); const { useLoad } = useGuard();
@ -104,6 +108,10 @@ async function getTeam(corpId, teamId) {
} }
} }
function backHome() {
uni.switchTab({ url: '/pages/home/home' })
}
useLoad(options => { useLoad(options => {
corpId.value = options.corpId; corpId.value = options.corpId;
if (options.teamId && options.corpId) { if (options.teamId && options.corpId) {

View File

@ -15,6 +15,8 @@ import useAccountStore from "@/store/account";
const env = __VITE_ENV__; const env = __VITE_ENV__;
const appid = env.MP_WX_APP_ID; const appid = env.MP_WX_APP_ID;
const { account } = storeToRefs(useAccountStore()); const { account } = storeToRefs(useAccountStore());
const { login } = useAccountStore();
const loading = ref(false); const loading = ref(false);
@ -38,6 +40,7 @@ async function changeTeam({ teamId, corpId, corpUserId }) {
teamId: team.value.teamId, teamId: team.value.teamId,
corpUserId: corpUserId || '' corpUserId: corpUserId || ''
}); });
await login()
if (account.value) { if (account.value) {
bindTeam(corpUserId) bindTeam(corpUserId)
} else { } else {

View File

@ -1,50 +1,29 @@
<template> <template>
<page-meta <page-meta :page-style="'overflow:' + (keyboardHeight > 0 ? 'hidden' : 'visible')"></page-meta>
:page-style="'overflow:' + (keyboardHeight > 0 ? 'hidden' : 'visible')"
></page-meta>
<view class="chat-page" :style="{ paddingBottom: keyboardHeight + 'px' }"> <view class="chat-page" :style="{ paddingBottom: keyboardHeight + 'px' }">
<!-- 患者信息栏 --> <!-- 患者信息栏 -->
<view class="patient-info-bar" v-if="patientInfo.name"> <view class="patient-info-bar" v-if="patientInfo.name">
<view class="patient-info-content"> <view class="patient-info-content">
<view class="patient-basic-info"> <view class="patient-basic-info">
<text class="patient-name">{{ patientInfo.name }}</text> <text class="patient-name">{{ patientInfo.name }}</text>
<text class="patient-detail" <text class="patient-detail">{{ patientInfo.sex }} · {{ patientInfo.age }}</text>
>{{ patientInfo.sex }} · {{ patientInfo.age }}</text </view>
> <view class="header-actions">
</view> <view class="status-badge" :class="chatStatusInfo.badgeClass" v-if="chatStatusInfo.badgeText">
<view class="header-actions"> <text class="badge-text">{{ chatStatusInfo.badgeText }}</text>
<view </view>
class="status-badge" <view v-if="showSubscribeEntry" class="remind-btn" @click="handleSubscribeReminder">
:class="chatStatusInfo.badgeClass" <text class="remind-btn-text">接收提醒</text>
v-if="chatStatusInfo.badgeText" </view>
> </view>
<text class="badge-text">{{ chatStatusInfo.badgeText }}</text> </view>
</view> </view>
<view
v-if="showSubscribeEntry"
class="remind-btn"
@click="handleSubscribeReminder"
>
<text class="remind-btn-text">接收提醒</text>
</view>
</view>
</view>
</view>
<!-- 聊天消息区域 --> <!-- 聊天消息区域 -->
<scroll-view <scroll-view class="chat-content" :style="{
class="chat-content" bottom: (keyboardHeight > 0 ? keyboardHeight + 60 : 60) + 'px',
:style="{ }" scroll-y="true" enhanced="true" bounces="false" :scroll-into-view="scrollIntoView" @scroll="onScroll"
bottom: (keyboardHeight > 0 ? keyboardHeight + 60 : 60) + 'px', @scrolltoupper="handleScrollToUpper" ref="chatScrollView">
}"
scroll-y="true"
enhanced="true"
bounces="false"
:scroll-into-view="scrollIntoView"
@scroll="onScroll"
@scrolltoupper="handleScrollToUpper"
ref="chatScrollView"
>
<!-- 加载更多提示 --> <!-- 加载更多提示 -->
<view class="load-more-tip" v-if="messageList.length >= 15"> <view class="load-more-tip" v-if="messageList.length >= 15">
<view class="loading" v-if="isLoadingMore"> <view class="loading" v-if="isLoadingMore">
@ -60,21 +39,13 @@
<!-- 聊天消息列表 --> <!-- 聊天消息列表 -->
<view class="message-list" @click="closeMorePanel"> <view class="message-list" @click="closeMorePanel">
<view <view v-for="(message, index) in messageList" :key="message.ID" :id="`msg-${message.ID}`" class="message-item"
v-for="(message, index) in messageList"
:key="message.ID"
:id="`msg-${message.ID}`"
class="message-item"
:class="{ :class="{
'message-right': message.flow === 'out', 'message-right': message.flow === 'out',
'message-left': message.flow === 'in', 'message-left': message.flow === 'in',
}" }">
>
<!-- 时间分割线 --> <!-- 时间分割线 -->
<view <view v-if="shouldShowTime(message, index, messageList)" class="time-divider">
v-if="shouldShowTime(message, index, messageList)"
class="time-divider"
>
<text class="time-text">{{ formatTime(message.lastTime) }}</text> <text class="time-text">{{ formatTime(message.lastTime) }}</text>
</view> </view>
@ -85,31 +56,20 @@
<!-- 消息内容 --> <!-- 消息内容 -->
<view v-else class="message-content"> <view v-else class="message-content">
<!-- 发送者头像统一处理 --> <!-- 发送者头像统一处理 -->
<image <image v-if="message.flow === 'in'" class="doctor-msg-avatar" :src="getUserAvatar(message.from)"
v-if="message.flow === 'in'" mode="aspectFill" />
class="doctor-msg-avatar"
:src="getUserAvatar(message.from)"
mode="aspectFill"
/>
<!-- 发送者头像统一处理 --> <!-- 发送者头像统一处理 -->
<image <image v-if="message.flow === 'out'" class="user-msg-avatar" :src="getUserAvatar(message.from)"
v-if="message.flow === 'out'" mode="aspectFill" />
class="user-msg-avatar"
:src="getUserAvatar(message.from)"
mode="aspectFill"
/>
<!-- 消息内容区域 --> <!-- 消息内容区域 -->
<view class="message-bubble-container"> <view class="message-bubble-container">
<!-- 用户名显示 --> <!-- 用户名显示 -->
<view <view class="username-label" :class="{
class="username-label" left: message.flow === 'in',
:class="{ right: message.flow === 'out',
left: message.flow === 'in', }">
right: message.flow === 'out',
}"
>
<text class="username-text">{{ <text class="username-text">{{
chatMember[message.from]?.name chatMember[message.from]?.name
}}</text> }}</text>
@ -117,25 +77,15 @@
<view class="message-bubble" :class="getBubbleClass(message)"> <view class="message-bubble" :class="getBubbleClass(message)">
<!-- 消息内容 --> <!-- 消息内容 -->
<MessageTypes <MessageTypes :corpId="corpId" :message="message" :formatTime="formatTime"
:corpId="corpId" :playingVoiceId="playingVoiceId" @playVoice="playVoice" @previewImage="previewImage"
:message="message" @viewDetail="(message) => handleViewDetail(message)" />
:formatTime="formatTime"
:playingVoiceId="playingVoiceId"
@playVoice="playVoice"
@previewImage="previewImage"
@viewDetail="(message) => handleViewDetail(message)"
/>
</view> </view>
</view> </view>
<!-- 发送状态 --> <!-- 发送状态 -->
<view v-if="message.flow === 'out'" class="message-status"> <view v-if="message.flow === 'out'" class="message-status">
<text <text v-if="message.status === 'failed'" class="status-text failed">发送失败</text>
v-if="message.status === 'failed'"
class="status-text failed"
>发送失败</text
>
</view> </view>
</view> </view>
</view> </view>
@ -149,22 +99,12 @@
<ConsultApply v-if="showConsultApply" @apply="handleApplyConsult" /> <ConsultApply v-if="showConsultApply" @apply="handleApplyConsult" />
<!-- 聊天输入组件 --> <!-- 聊天输入组件 -->
<ChatInput <ChatInput v-if="!isEvaluationPopupOpen && !showConsultCancel && !showConsultApply" ref="chatInputRef"
v-if="!isEvaluationPopupOpen && !showConsultCancel && !showConsultApply" :timChatManager="timChatManager" :formatTime="formatTime" :groupId="chatInfo.conversationID
ref="chatInputRef"
:timChatManager="timChatManager"
:formatTime="formatTime"
:groupId="
chatInfo.conversationID
? chatInfo.conversationID.replace('GROUP', '') ? chatInfo.conversationID.replace('GROUP', '')
: '' : ''
" " :userId="openid" :corpId="corpId.value" :keyboardHeight="keyboardHeight"
:userId="openid" @scrollToBottom="() => scrollToBottom(true)" @messageSent="() => scrollToBottom(true)" />
:corpId="corpId.value"
:keyboardHeight="keyboardHeight"
@scrollToBottom="() => scrollToBottom(true)"
@messageSent="() => scrollToBottom(true)"
/>
</view> </view>
</template> </template>
@ -194,32 +134,33 @@ import {
} from "@/utils/chat-utils.js"; } from "@/utils/chat-utils.js";
import api from "@/utils/api.js"; import api from "@/utils/api.js";
import useGroupChat from "./hooks/use-group-chat"; import useGroupChat from "./hooks/use-group-chat";
import MessageTypes from "./components/message-types.vue"; import MessageTypes from "./components/message-types.vue";
import ChatInput from "./components/chat-input.vue"; import ChatInput from "./components/chat-input.vue";
import SystemMessage from "./components/system-message.vue"; import SystemMessage from "./components/system-message.vue";
import ConsultCancel from "./components/consult-cancel.vue"; import ConsultCancel from "./components/consult-cancel.vue";
import ConsultApply from "./components/consult-apply.vue"; import ConsultApply from "./components/consult-apply.vue";
import { import {
checkConversationSubscribeEntryVisible, checkConversationSubscribeEntryVisible,
requestConversationSubscribeMessage, requestConversationSubscribeMessage,
} from "@/utils/subscribe-message"; } from "@/utils/subscribe-message";
import { import {
SUBSCRIBE_MESSAGE_ROLE, SUBSCRIBE_MESSAGE_ROLE,
SUBSCRIBE_MESSAGE_SCENE, SUBSCRIBE_MESSAGE_SCENE,
} from "@/utils/subscribe-message-config"; } from "@/utils/subscribe-message-config";
const timChatManager = globalTimChatManager; const timChatManager = globalTimChatManager;
// corpId // corpId
const corpId = ref(""); const corpId = ref("");
const showSubscribeEntry = ref(false); const showSubscribeEntry = ref(false);
// //
const { account, openid, isIMInitialized } = storeToRefs(useAccountStore()); const { account, openid, isIMInitialized } = storeToRefs(useAccountStore());
const { initIMAfterLogin } = useAccountStore(); const { initIMAfterLogin, login } = useAccountStore();
// //
const chatInputRef = ref(null); const chatInputRef = ref(null);
const loginPromise = ref(null);
const groupId = ref(""); const groupId = ref("");
const { chatMember, getGroupInfo, getUserAvatar } = useGroupChat(groupId); const { chatMember, getGroupInfo, getUserAvatar } = useGroupChat(groupId);
@ -463,7 +404,10 @@ function getBubbleClass(message) {
// //
onLoad(async (options) => { onLoad(async (options) => {
groupId.value = options.groupID || ""; loginPromise.value = login();
await loginPromise.value;
loginPromise.value = null;
groupId.value = decodeURIComponent(options.groupID) || "";
messageList.value = []; messageList.value = [];
isLoading.value = false; isLoading.value = false;
if (options.conversationID) { if (options.conversationID) {
@ -535,7 +479,7 @@ const initTIMCallbacks = async () => {
loadMessageList(); loadMessageList();
} }
}); });
timChatManager.setCallback("onSDKNotReady", () => {}); timChatManager.setCallback("onSDKNotReady", () => { });
timChatManager.setCallback("onMessageReceived", (message) => { timChatManager.setCallback("onMessageReceived", (message) => {
console.log("页面收到消息:", { console.log("页面收到消息:", {
@ -874,11 +818,15 @@ const handleScrollToUpper = async () => {
}; };
// //
onShow(() => { onShow(async () => {
loadSubscribeEntryState(); if (loginPromise.value) {
if (!account.value || !openid.value) { await loginPromise.value;
uni.redirectTo({ }
url: "/pages/login/login",
loadSubscribeEntryState();
if (!account.value || !openid.value) {
uni.redirectTo({
url: "/pages/login/login",
}); });
return; return;
} }
@ -924,16 +872,16 @@ onShow(() => {
} }
startIMMonitoring(30000); startIMMonitoring(30000);
} }
}); });
watch( watch(
() => corpId.value, () => corpId.value,
() => { () => {
loadSubscribeEntryState(); loadSubscribeEntryState();
}, },
{ immediate: true } { immediate: true }
); );
// //
onHide(() => { onHide(() => {
@ -1003,7 +951,7 @@ const handleCancelConsult = async () => {
}; };
// //
const handleApplyConsult = async () => { const handleApplyConsult = async () => {
try { try {
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
@ -1087,36 +1035,36 @@ const handleApplyConsult = async () => {
title: error.message || "操作失败", title: error.message || "操作失败",
icon: "none", icon: "none",
}); });
} }
}; };
const handleSubscribeReminder = async () => { const handleSubscribeReminder = async () => {
await requestConversationSubscribeMessage({ await requestConversationSubscribeMessage({
role: SUBSCRIBE_MESSAGE_ROLE.PATIENT, role: SUBSCRIBE_MESSAGE_ROLE.PATIENT,
scene: SUBSCRIBE_MESSAGE_SCENE.CHAT, scene: SUBSCRIBE_MESSAGE_SCENE.CHAT,
conversationId: chatInfo.value.conversationID || "", conversationId: chatInfo.value.conversationID || "",
groupId: groupId.value || "", groupId: groupId.value || "",
corpId: corpId.value || "", corpId: corpId.value || "",
patientId: patientId.value || "", patientId: patientId.value || "",
userId: openid.value || account.value?.openid || "", userId: openid.value || account.value?.openid || "",
openid: openid.value || account.value?.openid || "", openid: openid.value || account.value?.openid || "",
unionid: account.value?.unionid || "", unionid: account.value?.unionid || "",
extraData: { extraData: {
orderStatus: orderStatus.value || "", orderStatus: orderStatus.value || "",
page: "pages/message/index", page: "pages/message/index",
}, },
}); });
}; };
const loadSubscribeEntryState = async () => { const loadSubscribeEntryState = async () => {
showSubscribeEntry.value = await checkConversationSubscribeEntryVisible( showSubscribeEntry.value = await checkConversationSubscribeEntryVisible(
corpId.value || "", corpId.value || "",
true true
); );
}; };
// //
onUnmounted(() => { onUnmounted(() => {
clearMessageCache(); clearMessageCache();
// //

View File

@ -25,6 +25,9 @@ export default defineStore("accountStore", () => {
async function login(phoneCode = '') { async function login(phoneCode = '') {
if (loading.value) return; if (loading.value) return;
if (account.value && account.value.mobile) {
return account.value
}
loading.value = true; loading.value = true;
try { try {
const { code } = await uni.login({ const { code } = await uni.login({