ykt-wxapp/pages/message/components/system-message.vue

160 lines
3.7 KiB
Vue
Raw Normal View History

2026-01-20 13:21:50 +08:00
<template>
2026-01-26 18:08:01 +08:00
<!-- <view v-if="notifyText" class="notify-bar">
2026-01-20 13:21:50 +08:00
<view class="notify-line"></view>
<view class="notify-text">{{ notifyText }}</view>
<view class="notify-line"></view>
2026-01-26 18:08:01 +08:00
</view> -->
2026-01-20 13:21:50 +08:00
<view class="system-message">
<view class="system-text">{{ text }}</view>
</view>
</template>
<script setup>
2026-02-06 17:33:42 +08:00
import { computed } from "vue";
2026-01-20 13:21:50 +08:00
const props = defineProps({
message: {
type: Object,
2026-02-06 17:33:42 +08:00
default: () => ({}),
},
2026-01-20 13:21:50 +08:00
});
const payload = computed(() => props.message?.payload || {});
2026-01-26 18:08:01 +08:00
// 解析系统消息内容
const systemMessageData = computed(() => {
try {
// 尝试从 payload.data 解析系统消息
if (payload.value.data) {
2026-02-06 17:33:42 +08:00
const data =
typeof payload.value.data === "string"
? JSON.parse(payload.value.data)
: payload.value.data;
if (data.type === "system_message") {
2026-01-26 18:08:01 +08:00
return data;
}
}
} catch (e) {
2026-02-06 17:33:42 +08:00
console.error("解析系统消息失败:", e);
2026-01-26 18:08:01 +08:00
}
return null;
});
// 解析扩展信息
2026-01-20 13:21:50 +08:00
const extension = computed(() => {
try {
2026-01-26 18:08:01 +08:00
if (payload.value.extension) {
2026-02-06 17:33:42 +08:00
return typeof payload.value.extension === "string"
2026-01-26 18:08:01 +08:00
? JSON.parse(payload.value.extension)
: payload.value.extension;
}
2026-01-20 13:21:50 +08:00
} catch (e) {
2026-02-06 17:33:42 +08:00
console.error("解析扩展信息失败:", e);
2026-01-26 18:08:01 +08:00
}
return {};
});
// 显示的文本内容
const text = computed(() => {
// 优先从系统消息数据中获取文本
if (systemMessageData.value?.text) {
return systemMessageData.value.text;
}
// 根据消息类型返回默认文本
if (systemMessageData.value?.messageType) {
const messageType = systemMessageData.value.messageType;
switch (messageType) {
2026-02-06 17:33:42 +08:00
case "consult_pending":
return "患者已发起咨询申请,请及时接诊";
case "consult_accepted":
return "医生已接诊";
case "consult_rejected":
return "医生暂时无法接诊";
case "consult_ended":
return "问诊已结束";
case "consult_timeout":
return "问诊已超时";
case "consult_reopened":
return "会话已重新开启";
2026-01-26 18:08:01 +08:00
default:
2026-02-06 17:33:42 +08:00
return systemMessageData.value.content || "[系统消息]";
2026-01-26 18:08:01 +08:00
}
}
// 兼容旧格式:从 extension 中获取
if (extension.value.patient) {
return extension.value.patient;
}
// 兼容旧格式:直接从 payload.data 获取
2026-02-06 17:33:42 +08:00
if (payload.value.data && typeof payload.value.data === "string") {
2026-01-26 18:08:01 +08:00
// 如果 data 不是 JSON 格式,直接显示
try {
JSON.parse(payload.value.data);
} catch {
return payload.value.data;
}
2026-01-20 13:21:50 +08:00
}
2026-01-26 18:08:01 +08:00
2026-02-06 17:33:42 +08:00
return "[系统消息]";
2026-01-20 13:21:50 +08:00
});
2026-01-26 18:08:01 +08:00
// 通知文本(红色提示)
const notifyText = computed(() => {
// 从扩展信息中获取通知文本
if (extension.value.notifyText) {
return extension.value.notifyText;
}
2026-01-20 13:21:50 +08:00
2026-01-26 18:08:01 +08:00
// 根据系统消息类型显示不同的通知
if (systemMessageData.value) {
const messageType = systemMessageData.value.messageType;
switch (messageType) {
2026-02-06 17:33:42 +08:00
case "consult_pending":
return "待接诊";
case "consult_rejected":
return "已拒绝";
case "consult_timeout":
return "已超时";
case "consult_accepted":
return "已接诊";
case "consult_ended":
return "已结束";
2026-01-26 18:08:01 +08:00
default:
2026-02-06 17:33:42 +08:00
return "";
2026-01-26 18:08:01 +08:00
}
}
2026-02-06 17:33:42 +08:00
return "";
2026-01-26 18:08:01 +08:00
});
2026-01-20 13:21:50 +08:00
</script>
<style scoped lang="scss">
@import "../chat.scss";
.notify-bar {
display: flex;
align-items: center;
padding: 0 30rpx;
}
.notify-line {
flex-grow: 1;
min-width: 30rpx;
height: 1px;
background: #ddd;
}
.notify-text {
margin: 0 20rpx;
font-size: 24rpx;
color: red;
white-space: nowrap;
flex-shrink: 0;
max-width: 80%;
text-overflow: ellipsis;
overflow: hidden;
}
</style>