解决发送问卷的问题
This commit is contained in:
parent
2b86ffd1bb
commit
b6fe4e9877
@ -5,38 +5,45 @@
|
|||||||
<text v-if="required" class="required">*</text>
|
<text v-if="required" class="required">*</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="right">
|
<view class="right">
|
||||||
<view class="value" :class="{ muted: !displayText }">{{ displayText || placeholder }}</view>
|
<view class="value" :class="{ muted: !displayText }">{{
|
||||||
|
displayText || placeholder
|
||||||
|
}}</view>
|
||||||
<uni-icons type="arrowright" size="16" color="#999" />
|
<uni-icons type="arrowright" size="16" color="#999" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onUnmounted, ref } from 'vue';
|
import { computed, onUnmounted, ref } from "vue";
|
||||||
|
|
||||||
const emits = defineEmits(['change']);
|
const emits = defineEmits(["change"]);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
form: { type: Object, default: () => ({}) },
|
form: { type: Object, default: () => ({}) },
|
||||||
name: { default: '' },
|
name: { default: "" },
|
||||||
required: { type: Boolean, default: false },
|
required: { type: Boolean, default: false },
|
||||||
title: { default: '' },
|
title: { default: "" },
|
||||||
disableChange: { type: Boolean, default: false },
|
disableChange: { type: Boolean, default: false },
|
||||||
placeholder: { default: '' },
|
placeholder: { default: "" },
|
||||||
mult: { type: Boolean, default: false },
|
mult: { type: Boolean, default: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const placeholder = computed(() => (props.placeholder ? String(props.placeholder) : `请选择${props.name || ''}`));
|
const placeholder = computed(() =>
|
||||||
|
props.placeholder ? String(props.placeholder) : `请选择${props.name || ""}`
|
||||||
|
);
|
||||||
const rawValue = computed(() => props.form?.[props.title]);
|
const rawValue = computed(() => props.form?.[props.title]);
|
||||||
const displayText = computed(() => {
|
const displayText = computed(() => {
|
||||||
const v = rawValue.value;
|
const v = rawValue.value;
|
||||||
if (Array.isArray(v)) return v.filter((i) => i !== null && i !== undefined && String(i).trim()).join(',');
|
if (Array.isArray(v))
|
||||||
return v ? String(v) : '';
|
return v
|
||||||
|
.filter((i) => i !== null && i !== undefined && String(i).trim())
|
||||||
|
.join(",");
|
||||||
|
return v ? String(v) : "";
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeEventName = ref('');
|
const activeEventName = ref("");
|
||||||
function clearListener() {
|
function clearListener() {
|
||||||
if (activeEventName.value) uni.$off(activeEventName.value);
|
if (activeEventName.value) uni.$off(activeEventName.value);
|
||||||
activeEventName.value = '';
|
activeEventName.value = "";
|
||||||
}
|
}
|
||||||
onUnmounted(clearListener);
|
onUnmounted(clearListener);
|
||||||
|
|
||||||
@ -45,16 +52,20 @@ function open() {
|
|||||||
clearListener();
|
clearListener();
|
||||||
activeEventName.value = `diagnosis-change_${Date.now()}`;
|
activeEventName.value = `diagnosis-change_${Date.now()}`;
|
||||||
uni.$on(activeEventName.value, (data) => {
|
uni.$on(activeEventName.value, (data) => {
|
||||||
emits('change', { title: props.title, value: data });
|
emits("change", { title: props.title, value: data });
|
||||||
});
|
});
|
||||||
|
|
||||||
if (props.mult) {
|
if (props.mult) {
|
||||||
const cur = Array.isArray(rawValue.value) ? rawValue.value : [];
|
const cur = Array.isArray(rawValue.value) ? rawValue.value : [];
|
||||||
uni.setStorageSync('diagnosis-list-selection', cur);
|
uni.setStorageSync("diagnosis-list-selection", cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/library/diagnosis-list?eventName=${encodeURIComponent(activeEventName.value)}&mult=${props.mult ? 'YES' : 'NO'}&value=${encodeURIComponent(displayText.value || '')}`,
|
url: `/pages/library/diagnosis-list?eventName=${encodeURIComponent(
|
||||||
|
activeEventName.value
|
||||||
|
)}&mult=${props.mult ? "YES" : "NO"}&value=${encodeURIComponent(
|
||||||
|
displayText.value || ""
|
||||||
|
)}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -174,7 +174,7 @@ import { ref, onUnmounted, nextTick, watch, computed } from "vue";
|
|||||||
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import useAccountStore from "@/store/account.js";
|
import useAccountStore from "@/store/account.js";
|
||||||
import { globalTimChatManager } from "@/utils/tim-chat.js";
|
import { globalTimChatManager, TIM } from "@/utils/tim-chat.js";
|
||||||
import {
|
import {
|
||||||
startIMMonitoring,
|
startIMMonitoring,
|
||||||
stopIMMonitoring,
|
stopIMMonitoring,
|
||||||
@ -966,9 +966,8 @@ uni.$on("sendSurvey", async (data) => {
|
|||||||
const surveyUrl = env.VITE_SURVEY_URL || "";
|
const surveyUrl = env.VITE_SURVEY_URL || "";
|
||||||
|
|
||||||
// 获取客户信息
|
// 获取客户信息
|
||||||
const customerId = chatInfo.value.userID || "";
|
const customerId = patientId.value || "";
|
||||||
const customerName = chatInfo.value.customerName || "";
|
const customerName = patientInfo.value.name || "";
|
||||||
|
|
||||||
// 创建问卷记录
|
// 创建问卷记录
|
||||||
const recordRes = await api("createSurveyRecord", {
|
const recordRes = await api("createSurveyRecord", {
|
||||||
corpId,
|
corpId,
|
||||||
@ -998,7 +997,6 @@ uni.$on("sendSurvey", async (data) => {
|
|||||||
customerName
|
customerName
|
||||||
)}`;
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建自定义消息
|
// 创建自定义消息
|
||||||
const customMessage = {
|
const customMessage = {
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
@ -1012,23 +1010,18 @@ uni.$on("sendSurvey", async (data) => {
|
|||||||
description: "SURVEY",
|
description: "SURVEY",
|
||||||
extension: "",
|
extension: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 使用 timChatManager 的 sendCustomMessage 方法发送自定义消息
|
||||||
|
const result = await timChatManager.sendCustomMessage(customMessage, "SURVEY");
|
||||||
|
|
||||||
// 发送自定义消息
|
if (result.success) {
|
||||||
const message = timChatManager.tim.createCustomMessage({
|
// 消息已通过 sendCustomMessage 方法添加到列表并显示
|
||||||
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) {
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "发送成功",
|
title: "发送成功",
|
||||||
icon: "success",
|
icon: "success",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error(sendResult.message || "发送失败");
|
throw new Error(result.error || "发送失败");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("发送问卷失败:", error);
|
console.error("发送问卷失败:", error);
|
||||||
|
|||||||
@ -2170,6 +2170,93 @@ class TimChatManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送自定义消息
|
||||||
|
async sendCustomMessage(customPayload, description = '') {
|
||||||
|
if (!this.tim) {
|
||||||
|
this.triggerCallback('onError', 'IM未初始化')
|
||||||
|
return { success: false, error: 'IM未初始化' }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
if (!this.isLoggedIn) {
|
||||||
|
console.error('IM未登录,无法发送消息');
|
||||||
|
this.triggerCallback('onError', 'IM未登录,请稍后重试')
|
||||||
|
return { success: false, error: 'IM未登录' }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 优先使用 currentConversationID,如果没有则尝试从 conversation 获取
|
||||||
|
let conversationID = this.currentConversationID;
|
||||||
|
if (!conversationID && this.conversation) {
|
||||||
|
conversationID = this.conversation.conversationID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!conversationID) {
|
||||||
|
console.error('会话ID不存在');
|
||||||
|
this.triggerCallback('onError', '会话不存在,请重新进入聊天')
|
||||||
|
return { success: false, error: '会话ID不存在' }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从 conversationID 提取 groupID
|
||||||
|
let groupID = null;
|
||||||
|
if (conversationID.startsWith('GROUP')) {
|
||||||
|
groupID = conversationID.replace('GROUP', '');
|
||||||
|
} else if (this.conversation?.groupProfile?.groupID) {
|
||||||
|
groupID = this.conversation.groupProfile.groupID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!groupID) {
|
||||||
|
console.error('无法获取群聊ID,conversationID:', conversationID);
|
||||||
|
this.triggerCallback('onError', '无法获取群聊ID')
|
||||||
|
return { success: false, error: '无法获取群聊ID' }
|
||||||
|
}
|
||||||
|
|
||||||
|
// customPayload 已经是完整的 payload 对象 { data, description, extension }
|
||||||
|
// 直接使用,不需要再包装
|
||||||
|
const payload = customPayload;
|
||||||
|
|
||||||
|
const localMessage = {
|
||||||
|
ID: `local_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
||||||
|
flow: 'out',
|
||||||
|
type: 'TIMCustomElem',
|
||||||
|
payload: payload,
|
||||||
|
lastTime: Math.floor(Date.now() / 1000),
|
||||||
|
status: 'sending',
|
||||||
|
avatar: '/static/center/user-avatar.png',
|
||||||
|
conversationID: conversationID,
|
||||||
|
from: this.currentUserID
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('发送自定义消息,本地消息对象:', localMessage);
|
||||||
|
|
||||||
|
// 触发本地消息回调,立即显示在聊天列表中
|
||||||
|
this.triggerCallback('onMessageReceived', localMessage)
|
||||||
|
|
||||||
|
const message = this.tim.createCustomMessage({
|
||||||
|
to: groupID,
|
||||||
|
conversationType: TIM.TYPES.CONV_GROUP,
|
||||||
|
payload: payload
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.tim.sendMessage(message)
|
||||||
|
localMessage.status = 'success'
|
||||||
|
console.log('自定义消息发送成功');
|
||||||
|
return { success: true, message: localMessage }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('自定义消息发送失败:', error)
|
||||||
|
localMessage.status = 'failed'
|
||||||
|
|
||||||
|
// 如果是因为未登录导致的失败,尝试重连
|
||||||
|
if (error.message && (error.message.includes('not login') || error.message.includes('sdk not ready'))) {
|
||||||
|
console.log('检测到未登录错误,尝试重连...');
|
||||||
|
this.isLoggedIn = false;
|
||||||
|
this.ensureIMConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: false, error }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 发送图片消息
|
// 发送图片消息
|
||||||
async sendImageMessage(imageFile) {
|
async sendImageMessage(imageFile) {
|
||||||
if (!this.tim) {
|
if (!this.tim) {
|
||||||
@ -2325,95 +2412,6 @@ class TimChatManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送自定义消息
|
|
||||||
async sendCustomMessage(messageData) {
|
|
||||||
if (!this.tim) {
|
|
||||||
this.triggerCallback('onError', 'IM未初始化')
|
|
||||||
return { success: false, error: 'IM未初始化' }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查登录状态
|
|
||||||
if (!this.isLoggedIn) {
|
|
||||||
console.error('IM未登录,无法发送消息');
|
|
||||||
this.triggerCallback('onError', 'IM未登录,请稍后重试')
|
|
||||||
return { success: false, error: 'IM未登录' }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 优先使用 currentConversationID,如果没有则尝试从 conversation 获取
|
|
||||||
let conversationID = this.currentConversationID;
|
|
||||||
if (!conversationID && this.conversation) {
|
|
||||||
conversationID = this.conversation.conversationID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!conversationID) {
|
|
||||||
console.error('会话ID不存在');
|
|
||||||
this.triggerCallback('onError', '会话不存在,请重新进入聊天')
|
|
||||||
return { success: false, error: '会话ID不存在' }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从 conversationID 提取 groupID
|
|
||||||
let groupID = null;
|
|
||||||
if (conversationID.startsWith('GROUP')) {
|
|
||||||
groupID = conversationID.replace('GROUP', '');
|
|
||||||
} else if (this.conversation?.groupProfile?.groupID) {
|
|
||||||
groupID = this.conversation.groupProfile.groupID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!groupID) {
|
|
||||||
console.error('无法获取群聊ID,conversationID:', conversationID);
|
|
||||||
this.triggerCallback('onError', '无法获取群聊ID')
|
|
||||||
return { success: false, error: '无法获取群聊ID' }
|
|
||||||
}
|
|
||||||
|
|
||||||
const localMessage = {
|
|
||||||
ID: `local_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
||||||
flow: 'out',
|
|
||||||
type: 'TIMCustomElem',
|
|
||||||
payload: {
|
|
||||||
data: JSON.stringify(messageData),
|
|
||||||
description: messageData.content || '自定义消息',
|
|
||||||
extension: messageData.messageType || 'custom'
|
|
||||||
},
|
|
||||||
lastTime: Date.now(),
|
|
||||||
status: 'sending',
|
|
||||||
avatar: '/static/center/user-avatar.png',
|
|
||||||
conversationID: conversationID,
|
|
||||||
from: this.currentUserID
|
|
||||||
}
|
|
||||||
|
|
||||||
// 缓存功能已移除
|
|
||||||
|
|
||||||
this.triggerCallback('onMessageReceived', localMessage)
|
|
||||||
|
|
||||||
const message = this.tim.createCustomMessage({
|
|
||||||
to: groupID,
|
|
||||||
conversationType: TIM.TYPES.CONV_GROUP,
|
|
||||||
payload: {
|
|
||||||
data: JSON.stringify(messageData),
|
|
||||||
description: messageData.content || '自定义消息',
|
|
||||||
extension: messageData.messageType || 'custom'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.tim.sendMessage(message)
|
|
||||||
localMessage.status = 'success'
|
|
||||||
return { success: true, message: localMessage }
|
|
||||||
} catch (error) {
|
|
||||||
console.error('自定义消息发送失败:', error)
|
|
||||||
localMessage.status = 'failed'
|
|
||||||
|
|
||||||
// 如果是因为未登录导致的失败,尝试重连
|
|
||||||
if (error.message && (error.message.includes('not login') || error.message.includes('sdk not ready'))) {
|
|
||||||
console.log('检测到未登录错误,尝试重连...');
|
|
||||||
this.isLoggedIn = false;
|
|
||||||
this.ensureIMConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: false, error }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 工具方法
|
// 工具方法
|
||||||
// 判断是否为系统消息
|
// 判断是否为系统消息
|
||||||
isSystemMessage(message) {
|
isSystemMessage(message) {
|
||||||
@ -2883,7 +2881,8 @@ export {
|
|||||||
setGlobalIMCallback,
|
setGlobalIMCallback,
|
||||||
getGroupList,
|
getGroupList,
|
||||||
clearConversationCache,
|
clearConversationCache,
|
||||||
clearAllMessageCache
|
clearAllMessageCache,
|
||||||
|
TIM
|
||||||
}
|
}
|
||||||
|
|
||||||
export default globalTimChatManager
|
export default globalTimChatManager
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user