This commit is contained in:
wangdongbo 2026-01-28 16:35:14 +08:00
parent afbbb12ec7
commit b475223370
7 changed files with 119 additions and 217 deletions

View File

@ -26,7 +26,7 @@
<script setup>
import { onLoad } from "@dcloudio/uni-app";
import { getArticle } from "@/utils/api.js";
import api from "@/utils/api.js";
import { ref } from "vue";
const env = __VITE_ENV__;
const corpId = env.MP_CORP_ID;
@ -75,7 +75,7 @@ const loadArticle = async () => {
loading.value = true;
error.value = "";
try {
const res = await getArticle({ id: articleId, corpId });
const res = await api("getArticle", { id: articleId, corpId });
if (res.success && res.data) {
//

View File

@ -109,12 +109,7 @@
<script setup>
import { ref, onMounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import {
getArticleCateList,
getArticleList,
getArticle,
sendArticleMessage,
} from "@/utils/api.js";
import api from "@/utils/api.js";
import useAccountStore from "@/store/account.js";
import EmptyData from "@/components/empty-data.vue";
@ -154,7 +149,7 @@ const previewPopup = ref(null);
//
const getCategoryList = async () => {
try {
const res = await getArticleCateList({ corpId: corpId });
const res = await api("getArticleCateList", { corpId: corpId });
if (res.success && res.list) {
const cates = res.list || [];
categoryList.value = [{ _id: "", label: "全部" }, ...cates];
@ -203,7 +198,7 @@ const loadArticleList = async () => {
params.cateIds = [currentCateId.value];
}
const res = await getArticleList(params);
const res = await api("getArticleList", params);
if (res.success && res.list) {
const { list = [], total: count = 0 } = res;
const formattedList = list.map((item) => {
@ -286,7 +281,7 @@ const processRichTextContent = (html) => {
const previewArticle = async (article) => {
try {
uni.showLoading({ title: "加载中..." });
const res = await getArticle({ id: article._id, corpId: corpId });
const res = await api("getArticle", { id: article._id, corpId: corpId });
uni.hideLoading();
if (res.success && res.data) {
@ -320,9 +315,9 @@ const closePreview = () => {
const sendArticle = async (article) => {
try {
const { doctorInfo } = useAccountStore();
const result = await sendArticleMessage({
const result = await api("sendArticleMessage", {
groupId: pageParams.value.groupId,
fromAccount: doctorInfo.weChatOpenId,
fromAccount: doctorInfo.userid,
articleId: article._id,
title: article.title || "宣教文章",
imgUrl: article.cover || "",

View File

@ -85,7 +85,6 @@
}}</text>
</view>
<view class="message-bubble" :class="getBubbleClass(message)">
<!-- 消息内容 -->
<MessageTypes
@ -132,7 +131,11 @@
ref="chatInputRef"
:timChatManager="timChatManager"
:formatTime="formatTime"
:groupId="chatInfo.conversationID ? chatInfo.conversationID.replace('GROUP', '') : ''"
:groupId="
chatInfo.conversationID
? chatInfo.conversationID.replace('GROUP', '')
: ''
"
:userId="openid"
:corpId="corpId"
@scrollToBottom="() => scrollToBottom(true)"
@ -165,7 +168,7 @@ import {
handleViewDetail,
checkIMConnectionStatus,
} from "@/utils/chat-utils.js";
import { sendConsultRejectedMessage, endConsultation, sendArticleMessage } from "@/utils/api.js";
import api from "@/utils/api.js";
import useGroupChat from "./hooks/use-group-chat";
import MessageTypes from "./components/message-types.vue";
import ChatInput from "./components/chat-input.vue";
@ -177,7 +180,7 @@ const timChatManager = globalTimChatManager;
//
const env = __VITE_ENV__;
const corpId = env.MP_CORP_ID || '';
const corpId = env.MP_CORP_ID || "";
//
const { account, openid, isIMInitialized } = storeToRefs(useAccountStore());
@ -202,21 +205,21 @@ const chatInfo = ref({
userID: "",
avatar: "/static/home/avatar.svg",
});
//
const isEvaluationPopupOpen = ref(false);
//
const showConsultAccept = ref(false);
//
const orderStatus = ref("");
// - pending
const showConsultAccept = computed(() => orderStatus.value === "pending");
//
const showRejectReasonModal = ref(false);
//
const messageList = ref([]);
const isLoading = ref(false);
const scrollIntoView = ref("");
//
const isLoadingMore = ref(false);
const isCompleted = ref(false);
@ -258,46 +261,31 @@ function isSystemMessage(message) {
return false;
}
//
const fetchGroupOrderStatus = async () => {
try {
const result = await api("getGroupListByGroupId", {
groupId: groupId.value,
});
if (result.success && result.data) {
orderStatus.value = result.data.orderStatus || "";
console.log("获取群组订单状态:", {
orderStatus: orderStatus.value,
groupId: groupId.value,
});
} else {
console.error("获取群组订单状态失败:", result.message);
}
} catch (error) {
console.error("获取群组订单状态异常:", error);
}
};
//
function checkConsultPendingStatus() {
//
for (let i = messageList.value.length - 1; i >= 0; i--) {
const message = messageList.value[i];
if (message.type === "TIMCustomElem" && message.payload?.data) {
try {
const data =
typeof message.payload.data === "string"
? JSON.parse(message.payload.data)
: message.payload.data;
// consult_pending
if (
data.type === "system_message" &&
data.messageType === "consult_pending"
) {
showConsultAccept.value = true;
return;
}
//
if (
data.type === "system_message" &&
(data.messageType === "consult_accepted" ||
data.messageType === "consult_ended" ||
data.messageType === "consult_rejected")
) {
showConsultAccept.value = false;
return;
}
} catch (error) {
console.error("解析系统消息失败:", error);
}
}
}
//
showConsultAccept.value = false;
//
fetchGroupOrderStatus();
}
//
@ -336,7 +324,7 @@ const checkLoginAndInitTIM = async () => {
uni.showLoading({
title: "连接中...",
});
const success = await initIMAfterLogin(openid.value);
const success = await initIMAfterLogin();
uni.hideLoading();
if (!success) {
uni.showToast({
@ -391,8 +379,10 @@ const initTIMCallbacks = async () => {
messageList.value.push(message);
console.log("✓ 添加消息到列表,当前消息数量:", messageList.value.length);
//
checkConsultPendingStatus();
//
if (isSystemMessage(message)) {
fetchGroupOrderStatus();
}
// 使
nextTick(() => {
@ -514,7 +504,7 @@ const initTIMCallbacks = async () => {
};
//
const loadMessageList = () => {
const loadMessageList = async () => {
if (isLoading.value) {
console.log("正在加载中,跳过重复加载");
return;
@ -531,6 +521,9 @@ const loadMessageList = () => {
mask: false,
});
//
await fetchGroupOrderStatus();
timChatManager.enterConversation(chatInfo.value.conversationID || "test1");
//
@ -703,7 +696,6 @@ onHide(() => {
stopIMMonitoring();
});
const sendCommonPhrase = (content) => {
if (chatInputRef.value) {
chatInputRef.value.sendTextMessageFromPhrase(content);
@ -721,35 +713,27 @@ const handleAcceptConsult = async () => {
title: "处理中...",
});
//
const customMessage = {
data: JSON.stringify({
type: "system_message",
messageType: "consult_accepted",
content: "医生已接诊",
timestamp: Date.now(),
}),
description: "系统消息标记",
extension: "",
};
const message = timChatManager.tim.createCustomMessage({
to: chatInfo.value.conversationID.replace("GROUP", ""),
conversationType: timChatManager.TIM.TYPES.CONV_GROUP,
payload: customMessage,
//
const result = await api("acceptConsultation", {
groupId: groupId.value,
adminAccount: account.value?.userId || "",
extraData: {
acceptedBy: account.value?.userId || "",
acceptedByName: account.value?.name || "医生",
},
});
const sendResult = await timChatManager.tim.sendMessage(message);
uni.hideLoading();
if (sendResult.code === 0) {
showConsultAccept.value = false;
uni.hideLoading();
if (result.success) {
//
await fetchGroupOrderStatus();
uni.showToast({
title: "已接受问诊",
icon: "success",
});
} else {
throw new Error(sendResult.message || "发送失败");
throw new Error(result.message || "操作失败");
}
} catch (error) {
console.error("接受问诊失败:", error);
@ -780,11 +764,11 @@ const handleRejectReasonConfirm = async (reason) => {
const memberName = account.value?.name || "医生";
// ID
const groupId = chatInfo.value.conversationID.replace("GROUP", "");
const currentGroupId = chatInfo.value.conversationID.replace("GROUP", "");
//
const result = await sendConsultRejectedMessage({
groupId,
const result = await api("sendConsultRejectedMessage", {
groupId: currentGroupId,
memberName,
reason,
});
@ -792,7 +776,8 @@ const handleRejectReasonConfirm = async (reason) => {
uni.hideLoading();
if (result.success) {
showConsultAccept.value = false;
//
await fetchGroupOrderStatus();
uni.showToast({
title: "已拒绝问诊",
icon: "success",
@ -821,7 +806,7 @@ const handleEndConsult = async () => {
title: "处理中...",
});
// groupId
const result = await endConsultation({
const result = await api("endConsultation", {
groupId: groupId.value,
adminAccount: account.value?.userId || "",
extraData: {
@ -862,7 +847,6 @@ onUnmounted(() => {
uni.$off("sendSurvey");
});
//
uni.$on("sendSurvey", async (data) => {
const { survey, corpId, userId, sendSurveyId } = data;
@ -885,8 +869,7 @@ uni.$on("sendSurvey", async (data) => {
const customerName = chatInfo.value.customerName || "";
//
const { createSurveyRecord } = await import("@/utils/api.js");
const recordRes = await createSurveyRecord({
const recordRes = await api("createSurveyRecord", {
corpId,
userId,
surveryId: survey._id,

View File

@ -95,7 +95,7 @@ const initIM = async () => {
uni.showLoading({
title: "连接中...",
});
const success = await initIMAfterLogin(openid.value);
const success = await initIMAfterLogin();
uni.hideLoading();
if (!success) {
@ -122,7 +122,7 @@ const initIM = async () => {
//
const loadConversationList = async () => {
if (loading.value) return;
// loading.value = true;
loading.value = true;
try {
console.log("开始加载群聊列表");
@ -224,8 +224,10 @@ const setupConversationListener = () => {
console.log("会话列表更新事件:", eventData);
//
if (eventData.reason === "NEW_MESSAGE_RECEIVED_IN_CURRENT_CONVERSATION" ||
eventData.reason === "NEW_MESSAGE_RECEIVED") {
if (
eventData.reason === "NEW_MESSAGE_RECEIVED_IN_CURRENT_CONVERSATION" ||
eventData.reason === "NEW_MESSAGE_RECEIVED"
) {
const conversation = eventData.conversation;
if (!conversation) return;
@ -237,8 +239,10 @@ const setupConversationListener = () => {
if (conversationIndex !== -1) {
//
const existingConversation = conversationList.value[conversationIndex];
existingConversation.lastMessage = conversation.lastMessage || "暂无消息";
existingConversation.lastMessageTime = conversation.lastMessageTime || Date.now();
existingConversation.lastMessage =
conversation.lastMessage || "暂无消息";
existingConversation.lastMessageTime =
conversation.lastMessageTime || Date.now();
existingConversation.unreadCount = conversation.unreadCount || 0;
//
@ -365,36 +369,36 @@ onLoad(() => {
});
//
// onShow(async () => {
// try {
// // IM
// const imReady = await initIM();
// if (!imReady) {
// console.error("IM");
// return;
// }
onShow(async () => {
try {
// IM
const imReady = await initIM();
if (!imReady) {
console.error("IM初始化失败");
return;
}
// //
// await loadConversationList();
//
await loadConversationList();
// //
// setupConversationListener();
// } catch (error) {
// console.error(":", error);
// uni.showToast({
// title: "",
// icon: "none",
// });
// }
// });
//
setupConversationListener();
} catch (error) {
console.error("页面初始化失败:", error);
uni.showToast({
title: "初始化失败,请重试",
icon: "none",
});
}
});
//
onHide(() => {
//
// if (globalTimChatManager) {
// globalTimChatManager.setCallback("onConversationListUpdated", null);
// globalTimChatManager.setCallback("onMessageReceived", null);
// }
if (globalTimChatManager) {
globalTimChatManager.setCallback("onConversationListUpdated", null);
globalTimChatManager.setCallback("onMessageReceived", null);
}
});
</script>

View File

@ -87,11 +87,7 @@
<script setup>
import { ref, onMounted } from "vue";
import {
getSurveyCateList,
getSurveyList,
createSurveyRecord,
} from "@/utils/api.js";
import api from "@/utils/api.js";
import useAccountStore from "@/store/account.js";
import EmptyData from "@/components/empty-data.vue";
@ -119,7 +115,7 @@ const emptyText = ref("");
//
const getCategoryList = async () => {
try {
const res = await getSurveyCateList({ corpId: corpId });
const res = await api("getSurveyCateList", { corpId: corpId });
if (res.success && res.list) {
const cates = res.list || [];
categoryList.value = [{ _id: "", label: "全部" }, ...cates];
@ -169,7 +165,7 @@ const loadSurveyList = async () => {
params.cateIds = [currentCateId.value];
}
const res = await getSurveyList(params);
const res = await api("getSurveyList", params);
if (res.success && res) {
const { list = [], total: count = 0 } = res;

View File

@ -52,15 +52,7 @@ export default defineStore("accountStore", () => {
account.value = res.data;
openid.value = res.data.openid;
// 登录成功后初始化腾讯IM
try {
console.log('开始初始化腾讯IMuserID:', res.data.openid);
await initGlobalTIM(res.data.openid);
isIMInitialized.value = true;
console.log('腾讯IM初始化成功');
} catch (imError) {
console.error('腾讯IM初始化失败:', imError);
// IM初始化失败不影响登录流程
}
await getDoctorInfo(openid.value);
return res.data
}
@ -79,18 +71,21 @@ export default defineStore("accountStore", () => {
weChatOpenId: account.value.openid,
});
doctorInfo.value = res?.data || null;
await initIMAfterLogin();
} catch (e) {
console.error('获取医生信息失败:', e);
}
}
async function initIMAfterLogin(userID) {
async function initIMAfterLogin() {
if (isIMInitialized.value) {
return true;
}
try {
const userID = doctorInfo.value.userid;
console.log('开始初始化腾讯IMuserID:', userID);
await initGlobalTIM(userID);
isIMInitialized.value = true;
console.log('腾讯IM初始化成功');
return true;
} catch (error) {
console.error('IM初始化失败:', error);

View File

@ -65,7 +65,9 @@ const urlsConfig = {
getChatRecordsByGroupId: "getChatRecordsByGroupId",
sendConsultRejectedMessage: "sendConsultRejectedMessage",
endConsultation: "endConsultation",
getGroupListByGroupId: "getGroupListByGroupId"
getGroupListByGroupId: "getGroupListByGroupId",
acceptConsultation: "acceptConsultation",
sendArticleMessage: "sendArticleMessage"
}
}
@ -99,76 +101,3 @@ export default async function api(urlId, data) {
})
}
// 宣教文章相关 API
export async function getArticleCateList(data) {
return api('getArticleCateList', data);
}
export async function getArticleList(data) {
return api('getArticleList', data);
}
export async function getArticle(data) {
return api('getArticle', data);
}
export async function addArticleSendRecord(data) {
return api('addArticleSendRecord', data);
}
// 问卷相关 API
export async function getSurveyCateList(data) {
return api('getSurveyCateList', data);
}
export async function getSurveyList(data) {
return api('getSurveyList', data);
}
export async function createSurveyRecord(data) {
return api('createSurveyRecord', data);
}
export async function getSurveyDetail(data) {
return api('getSurveyDetail', data);
}
// IM 系统消息相关 API
export async function sendConsultRejectedMessage(data) {
return request({
url: '/getYoucanData/im',
data: {
type: 'sendConsultRejectedMessage',
...data
}
});
}
// 发送宣教文章消息
export async function sendArticleMessage(data) {
return request({
url: '/getYoucanData/im',
data: {
type: 'sendArticleMessage',
...data
}
});
}
// 结束问诊接口
export async function endConsultation(data) {
return request({
url: '/getYoucanData/im',
data: {
type: 'endConsultation',
...data
}
});
}
// 根据群组ID获取群组记录
export async function getGroupListByGroupId(data) {
return api('getGroupListByGroupId', data);
}