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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,7 +65,9 @@ const urlsConfig = {
getChatRecordsByGroupId: "getChatRecordsByGroupId", getChatRecordsByGroupId: "getChatRecordsByGroupId",
sendConsultRejectedMessage: "sendConsultRejectedMessage", sendConsultRejectedMessage: "sendConsultRejectedMessage",
endConsultation: "endConsultation", 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);
}