From c2da3c00afaa95c80cff42ac3693e3f7bca6f764 Mon Sep 17 00:00:00 2001
From: wangdongbo <949818794@qq.com>
Date: Tue, 3 Feb 2026 14:17:37 +0800
Subject: [PATCH] no message
---
.env.development | 2 +
.env.ip | 3 +-
.env.localhost | 2 +
pages/message/components/chat-input.vue | 58 ++++------
pages/message/hooks/use-group-chat.js | 2 +-
pages/message/index.vue | 87 +-------------
pages/message/survey-list.vue | 147 ++++++++++++++++++++----
store/team.js | 10 +-
utils/api.js | 4 +-
9 files changed, 158 insertions(+), 157 deletions(-)
diff --git a/.env.development b/.env.development
index 9d227fb..cce72c5 100644
--- a/.env.development
+++ b/.env.development
@@ -5,3 +5,5 @@ MP_WX_APP_ID=wx1d8337a40c11d66c
MP_CORP_ID=wwe3fb2faa52cf9dfb
MP_TIM_SDK_APP_ID=1600123876
MP_INVITE_TEAMMATE_QRCODE=https://patient.youcan365.com/invite-teammate
+MP_PATIENT_PAGE_BASE_URL= 'https://www.youcan365.com/patientDeploy/#/'
+MP_SURVEY_URL= 'https://www.youcan365.com/surveyDev/#/pages/survey/survey'
\ No newline at end of file
diff --git a/.env.ip b/.env.ip
index 943dbe3..93481d6 100644
--- a/.env.ip
+++ b/.env.ip
@@ -5,4 +5,5 @@ MP_WX_APP_ID=wx93af55767423938e
MP_CORP_ID=wwe3fb2faa52cf9dfb
MP_TIM_SDK_APP_ID=1600123876
MP_INVITE_TEAMMATE_QRCODE=https://patient.youcan365.com/invite-teammate
-
+MP_PATIENT_PAGE_BASE_URL= 'https://www.youcan365.com/patientDeploy/#/'
+MP_SURVEY_URL= 'https://www.youcan365.com/surveyDev/#/pages/survey/survey'
diff --git a/.env.localhost b/.env.localhost
index 40eeb46..3d46ace 100644
--- a/.env.localhost
+++ b/.env.localhost
@@ -5,3 +5,5 @@ MP_WX_APP_ID=wx1d8337a40c11d66c
MP_CORP_ID=wwe3fb2faa52cf9dfb
MP_TIM_SDK_APP_ID=1600123876
MP_INVITE_TEAMMATE_QRCODE=https://patient.youcan365.com/invite-teammate
+MP_PATIENT_PAGE_BASE_URL= 'https://www.youcan365.com/patientDeploy/#/'
+MP_SURVEY_URL= 'https://www.youcan365.com/surveyDev/#/pages/survey/survey'
\ No newline at end of file
diff --git a/pages/message/components/chat-input.vue b/pages/message/components/chat-input.vue
index 2ef7f6c..c48da5e 100644
--- a/pages/message/components/chat-input.vue
+++ b/pages/message/components/chat-input.vue
@@ -6,9 +6,10 @@
-
+ :auto-height="true" :show-confirm-bar="false" :adjust-position="true"
+ placeholder-style="line-height: 80rpx;" />
@@ -73,10 +74,10 @@ const props = defineProps({
patientInfo: { type: Object, default: () => ({}) },
chatRoomBusiness: { type: Object, default: () => ({}) },
formatTime: { type: Function, required: true },
- groupId: { type: String, default: '' },
- userId: { type: String, default: '' },
- patientId: { type: String, default: '' },
- corpId: { type: String, default: '' },
+ groupId: { type: String, default: "" },
+ userId: { type: String, default: "" },
+ patientId: { type: String, default: "" },
+ corpId: { type: String, default: "" },
});
// Emits
@@ -162,9 +163,9 @@ const sendTextMessage = async () => {
// 从常用语发送文本消息
const sendTextMessageFromPhrase = async (content) => {
if (!content.trim()) return;
-
+
await sendMessage("text", content);
-
+
// 发送成功后滚动到底部
nextTick(() => {
emit("scrollToBottom");
@@ -178,7 +179,7 @@ const setInputText = (text) => {
// 清空输入框
const clearInputText = () => {
- inputText.value = '';
+ inputText.value = "";
};
// 暴露方法给父组件调用
@@ -186,7 +187,7 @@ defineExpose({
sendTextMessageFromPhrase,
appendStreamText,
setInputText,
- clearInputText
+ clearInputText,
});
// 发送图片消息
@@ -357,61 +358,42 @@ const cancelRecord = () => {
stopRecordUtil(recorderManager);
};
-// 发送问卷调查消息
-const sendSurveyMessage = async () => {
- const surveyMessage = createCustomMessage(
- "survey",
- {
- content: "医生发送了问卷调查",
- surveyTitle: "治疗效果评估",
- surveyDescription: "您好,为了帮助了解您的病情变化,请您如实填写问卷。",
- surveyMessage: "慢性病患者生活质量评估问卷",
- estimatedTime: "约3-5分钟",
- reward: "积分奖励10分",
- note: "问卷内容涉及您的症状变化、用药情况等,请根据实际情况填写。",
- },
- props.formatTime
- );
-
- await sendCustomMessage(surveyMessage);
-};
-
// 跳转到常用语页面
const goToCommonPhrases = () => {
uni.navigateTo({
- url: '/pages/message/common-phrases'
+ url: "/pages/message/common-phrases",
});
};
// 跳转到宣教文章页面
const goToArticleList = () => {
uni.navigateTo({
- url: `/pages/message/article-list?groupId=${props.groupId}&patientId=${props.patientId}&corpId=${props.corpId}`
+ url: `/pages/message/article-list?groupId=${props.groupId}&patientId=${props.patientId}&corpId=${props.corpId}`,
});
};
// 跳转到问卷列表页面
const goToSurveyList = () => {
uni.navigateTo({
- url: '/pages/message/survey-list'
+ url: `/pages/message/survey-list?groupId=${props.groupId}&patientId=${props.patientId}&corpId=${props.corpId}&customerName=${props.patientInfo.name}`,
});
};
// 结束问诊
const handleEndConsult = () => {
uni.showModal({
- title: '确认结束问诊',
- content: '确定要结束本次问诊吗?结束后将无法继续对话。',
- confirmText: '确定结束',
- cancelText: '取消',
+ title: "确认结束问诊",
+ content: "确定要结束本次问诊吗?结束后将无法继续对话。",
+ confirmText: "确定结束",
+ cancelText: "取消",
success: (res) => {
if (res.confirm) {
// 关闭功能面板
showMorePanel.value = false;
// 触发父组件的结束问诊事件
- emit('endConsult');
+ emit("endConsult");
}
- }
+ },
});
};
diff --git a/pages/message/hooks/use-group-chat.js b/pages/message/hooks/use-group-chat.js
index 73d7a8e..a9b59e5 100644
--- a/pages/message/hooks/use-group-chat.js
+++ b/pages/message/hooks/use-group-chat.js
@@ -68,7 +68,7 @@ export default function useGroupChat(groupID) {
// 2. 如果有teamId,获取团队成员头像
if (groupResult.data.teamId) {
- const avatarMap = await teamStore.getTeamMemberAvatars(groupResult.data.teamId)
+ const avatarMap = await teamStore.getTeamMemberAvatarsAndName(groupResult.data.teamId)
// 3. 存储团队成员ID列表
teamMemberIds.value = Object.keys(avatarMap)
diff --git a/pages/message/index.vue b/pages/message/index.vue
index 3b06be5..9bffc38 100644
--- a/pages/message/index.vue
+++ b/pages/message/index.vue
@@ -162,6 +162,7 @@
:userId="openid"
:patientId="patientId"
:corpId="corpId"
+ :patientInfo="patientInfo"
@scrollToBottom="() => scrollToBottom(true)"
@messageSent="() => scrollToBottom(true)"
@endConsult="handleEndConsult"
@@ -944,92 +945,6 @@ onUnmounted(() => {
timChatManager.setCallback("onMessageReceived", null);
timChatManager.setCallback("onMessageListLoaded", null);
timChatManager.setCallback("onError", null);
- // 移除问卷发送监听
- uni.$off("sendSurvey");
-});
-
-// 监听问卷发送事件
-uni.$on("sendSurvey", async (data) => {
- const { survey, corpId, userId, sendSurveyId } = data;
-
- if (!survey || !survey._id) {
- uni.showToast({
- title: "问卷信息不完整",
- icon: "none",
- });
- return;
- }
- try {
- // 获取环境变量
- const env = __VITE_ENV__;
- const baseUrl = env.VITE_PATIENT_PAGE_BASE_URL || "";
- const surveyUrl = env.VITE_SURVEY_URL || "";
-
- // 获取客户信息
- const customerId = patientId.value || "";
- const customerName = patientInfo.value.name || "";
- // 创建问卷记录
- const recordRes = await api("createSurveyRecord", {
- corpId,
- userId,
- surveryId: survey._id,
- memberId: customerId,
- customer: customerName,
- sendSurveyId,
- });
-
- if (!recordRes.success) {
- throw new Error(recordRes.message || "创建问卷记录失败");
- }
-
- const answerId = recordRes.data?.id || "";
-
- // 构建问卷链接
- let surveyLink = "";
- if (survey.createBy === "system") {
- // 系统问卷
- surveyLink = `${surveyUrl}?corpId=${corpId}&surveyId=${survey.surveyId}&memberId=${customerId}&sendSurveyId=${sendSurveyId}&userId=${userId}`;
- } else {
- // 自定义问卷
- surveyLink = `${baseUrl}pages/survery/fill?corpId=${corpId}&surveryId=${
- survey._id
- }&memberId=${customerId}&answerId=${answerId}&name=${encodeURIComponent(
- customerName
- )}`;
- }
- // 创建自定义消息
- const customMessage = {
- data: JSON.stringify({
- type: "survey",
- title: survey.name || "填写问卷",
- desc: "请填写问卷",
- url: surveyLink,
- imgUrl:
- "https://796f-youcan-clouddev-1-8ewcqf31dbb2b5-1317294507.tcb.qcloud.la/other/19-%E9%97%AE%E5%8D%B7.png?sign=55a4cd77c418b2c548b65792a2cf6bce&t=1701328694",
- }),
- description: "SURVEY",
- extension: "",
- };
-
- // 使用 timChatManager 的 sendCustomMessage 方法发送自定义消息
- const result = await timChatManager.sendCustomMessage(customMessage, "SURVEY");
-
- if (result.success) {
- // 消息已通过 sendCustomMessage 方法添加到列表并显示
- uni.showToast({
- title: "发送成功",
- icon: "success",
- });
- } else {
- throw new Error(result.error || "发送失败");
- }
- } catch (error) {
- console.error("发送问卷失败:", error);
- uni.showToast({
- title: error.message || "发送失败",
- icon: "none",
- });
- }
});
diff --git a/pages/message/survey-list.vue b/pages/message/survey-list.vue
index a3e4bfc..c681815 100644
--- a/pages/message/survey-list.vue
+++ b/pages/message/survey-list.vue
@@ -89,12 +89,18 @@
import { ref, onMounted } from "vue";
import api from "@/utils/api.js";
import useAccountStore from "@/store/account.js";
+import { globalTimChatManager } from "@/utils/tim-chat.js";
import EmptyData from "@/components/empty-data.vue";
-
+import { onLoad } from "@dcloudio/uni-app";
const env = __VITE_ENV__;
const accountStore = useAccountStore();
const corpId = env.MP_CORP_ID;
const userId = ref("");
+const timChatManager = globalTimChatManager;
+
+// 从上一页传递的客户信息
+const customerId = ref("");
+const customerName = ref("");
// 搜索关键词
const searchName = ref("");
@@ -112,6 +118,14 @@ const pageSize = 30;
const total = ref(0);
const emptyText = ref("");
+// 页面加载时接收参数
+onLoad((options) => {
+ customerId.value = options?.patientId || "";
+ customerName.value = options?.customerName || "";
+ getCategoryList();
+ loadSurveyList();
+});
+
// 获取分类列表
const getCategoryList = async () => {
try {
@@ -204,19 +218,34 @@ const loadMore = () => {
// 预览问卷
const previewSurvey = (survey) => {
+ if (!survey.surveryId) {
+ uni.showToast({
+ title: "问卷ID不存在",
+ icon: "none",
+ });
+ return;
+ }
+
const timestamp = Date.now();
- const previewUrl = `https://www.youcan365.com/surveyDev/#/pages/survey/survey?surveyId=${survey.surveyId}&t=${timestamp}`;
-
+ const previewUrl = `https://www.youcan365.com/surveyDev/#/pages/survey/survey?surveryId=${survey.surveryId}&t=${timestamp}`;
+
// #ifdef H5
- window.open(previewUrl, '_blank');
+ window.open(previewUrl, "_blank");
// #endif
-
+
// #ifdef MP-WEIXIN
uni.navigateTo({
- url: `/pages/webview/webview?url=${encodeURIComponent(previewUrl)}`
+ url: `/pages/webview/webview?url=${encodeURIComponent(previewUrl)}`,
+ fail: (err) => {
+ console.error("导航失败:", err);
+ uni.showToast({
+ title: "打开失败,请重试",
+ icon: "none",
+ });
+ },
});
// #endif
-
+
// #ifdef APP-PLUS
plus.runtime.openURL(previewUrl);
// #endif
@@ -233,6 +262,48 @@ const generateRandomString = (length) => {
return result;
};
+// 生成发送链接
+const generateSendLink = (
+ survey,
+ answerId,
+ customerId,
+ customerName,
+ sendSurveyId
+) => {
+ const isSystem = survey.createBy === "system";
+ let url = "";
+
+ if (isSystem) {
+ // 系统问卷:使用 VITE_SURVEY_URL
+ url = `${env.MP_SURVEY_URL}?corpId=${corpId}&surveryId=${survey.surveryId}&memberId=${customerId}&sendSurveyId=${sendSurveyId}&userId=${userId.value}`;
+ } else {
+ url = `${
+ env.MP_PATIENT_PAGE_BASE_URL
+ }pages/survery/fill?corpId=${corpId}&surveryId=${
+ survey._id
+ }&memberId=${customerId}&unionid=unionid&answerId=${answerId}&name=${
+ customerName || ""
+ }`;
+ }
+ return url;
+};
+
+// 构建问卷自定义消息
+const buildSurveyMessage = (survey, surveyLink) => {
+ return {
+ data: JSON.stringify({
+ type: "survey",
+ title: survey.name || "填写问卷",
+ desc: "请填写问卷",
+ url: surveyLink,
+ imgUrl:
+ "https://796f-youcan-clouddev-1-8ewcqf31dbb2b5-1317294507.tcb.qcloud.la/other/19-%E9%97%AE%E5%8D%B7.png?sign=55a4cd77c418b2c548b65792a2cf6bce&t=1701328694",
+ }),
+ description: "SURVEY",
+ extension: "",
+ };
+};
+
// 发送问卷
const sendSurvey = async (survey) => {
if (loading.value) return;
@@ -242,33 +313,61 @@ const sendSurvey = async (survey) => {
// 获取医生信息
const doctorInfo = accountStore.doctorInfo;
- userId.value = doctorInfo?.userid || accountStore.openid;
+ userId.value = doctorInfo?.userid;
// 生成发送ID
const sendSurveyId = generateRandomString(10);
- // 获取当前聊天的客户信息(从上一页传递)
- const pages = getCurrentPages();
- const prevPage = pages[pages.length - 2];
-
- // 这里需要从聊天页面获取客户信息
- // 暂时使用事件传递方式
- uni.$emit("sendSurvey", {
- survey: survey,
+ // 创建问卷记录
+ const createRecordRes = await api("createSurveyRecord", {
corpId: corpId,
userId: userId.value,
+ surveryId: survey._id,
+ memberId: customerId.value,
+ customer: customerName.value,
sendSurveyId: sendSurveyId,
});
- uni.showToast({
- title: "已选择问卷",
- icon: "success",
- });
+ if (!createRecordRes.success) {
+ uni.showToast({
+ title: createRecordRes.message || "创建问卷记录失败",
+ icon: "none",
+ });
+ loading.value = false;
+ return;
+ }
- // 延迟返回
- setTimeout(() => {
- uni.navigateBack();
- }, 500);
+ const answerId = createRecordRes?.id || "";
+
+ // 生成发送链接
+ const sendLink = generateSendLink(
+ survey,
+ answerId,
+ customerId.value,
+ customerName.value,
+ sendSurveyId
+ );
+
+ // 构建自定义消息
+ const customMessage = buildSurveyMessage(survey, sendLink);
+
+ // 发送自定义消息到IM
+ const result = await timChatManager.sendCustomMessage(
+ customMessage,
+ "SURVEY"
+ );
+ if (result.success) {
+ uni.showToast({
+ title: "发送成功",
+ icon: "success",
+ });
+ // 延迟返回
+ setTimeout(() => {
+ uni.navigateBack();
+ }, 500);
+ } else {
+ throw new Error(result.error || "发送失败");
+ }
} catch (error) {
console.error("发送问卷失败:", error);
uni.showToast({
diff --git a/store/team.js b/store/team.js
index df47e1a..e5dde76 100644
--- a/store/team.js
+++ b/store/team.js
@@ -35,11 +35,11 @@ export default defineStore("teamStore", () => {
}
// 获取团队成员头像映射
- async function getTeamMemberAvatars(teamId) {
+ async function getTeamMemberAvatarsAndName(teamId) {
if (!teamId || !account.value?.corpId) return {};
- const res = await api('getTeamMemberAvatars', {
- teamId,
- corpId: account.value.corpId
+ const res = await api('getTeamMemberAvatarsAndName', {
+ teamId,
+ corpId: account.value.corpId
});
if (res && res.success && res.data) {
return res.data; // 返回 { userId: avatar } 的映射对象
@@ -47,5 +47,5 @@ export default defineStore("teamStore", () => {
return {};
}
- return { teams, chargeTeams, getTeam, getTeams, getTeamMemberAvatars }
+ return { teams, chargeTeams, getTeam, getTeams, getTeamMemberAvatarsAndName }
})
\ No newline at end of file
diff --git a/utils/api.js b/utils/api.js
index be64c46..618ee68 100644
--- a/utils/api.js
+++ b/utils/api.js
@@ -26,7 +26,7 @@ const urlsConfig = {
removeTeammate: "removeTeammate",
toggleTeamLeaderRole: "toggleTeamLeaderRole",
joinTheInvitedTeam: 'joinTheInvitedTeam',
- getTeamMemberAvatars: 'getTeamMemberAvatars'
+ getTeamMemberAvatarsAndName: 'getTeamMemberAvatarsAndName'
},
knowledgeBase: {
@@ -123,7 +123,7 @@ const urlsConfig = {
customerTransferRecord: 'customerTransferRecord',
// sendConsultRejectedMessage: "sendConsultRejectedMessage"
getTeamTodos: 'getTeamTodos',
- updateTaskTodo:'updateTaskTodo'
+ updateTaskTodo: 'updateTaskTodo'
}
}