Files
xk-doctor-wx/config/chat.js
2026-03-06 13:59:22 +08:00

75 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 聊天室配置文件
* 统一管理聊天室相关配置
*/
/**
* 聊天室配置
*/
export const chatConfig = {
/**
* 消息类型映射
* 将消息类型名称映射到数字类型
*/
messageTypes: {
text: 0, // 文本消息
image: 1, // 图片消息
audio: 2, // 语音消息
video: 3, // 视频消息
prescription: 4, // 处方消息
file: 5, // 文件消息
register: 10, // 挂号消息
'patient-experience': 11, // 患者体验消息
'product-card': 12, // 产品卡片消息
'end-consultation': 13 // 结束问诊消息
},
/**
* 根据消息类型名称获取数字类型
* @param {string} typeName - 消息类型名称
* @returns {number} 消息类型数字
*/
getMessageType(typeName) {
return this.messageTypes[typeName] || 0;
},
/**
* 根据数字类型获取消息类型名称
* @param {number} type - 消息类型数字
* @returns {string} 消息类型名称
*/
getMessageTypeName(type) {
const entries = Object.entries(this.messageTypes);
const found = entries.find(([name, value]) => value === type);
return found ? found[0] : 'text';
},
/**
* 房间配置
*/
room: {
messagePageSize: 20, // 每页消息数量
maxCacheSize: 100 // 最大缓存消息数
},
/**
* 未读数配置
*/
unread: {
maxCount: 99 // 最大未读数显示超过显示99+
},
/**
* 格式化未读数显示
* @param {number} count - 未读数
* @returns {string} 格式化后的未读数
*/
formatUnreadCount(count) {
if (count <= 0) return '';
if (count > this.unread.maxCount) {
return `${this.unread.maxCount}+`;
}
return count.toString();
}
};