| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- /** 消息类别的code */
- export const msgTypeEnum = {
- //#region 在线互动
- 文本消息: 1000,
- 图片消息: 1001,
- 文本消息: 1000,
- 图片消息: 1001,
- 文件消息: 1002,
- 视频消息: 1003,
- 患教资料: 1004,
- 问卷量表: 1005,
- 患教已读: 1104,
- 问卷已填写: 1105,
- 申请: 2000,
- 申请通过: 2001,
- 申请拒绝: 2002,
- 申请取消: 2003,
- 申请超时: 2004,
- 结束服务: 3000,
- //#endregion
- //#region 随访消息
- 随访群发消息: 0,
- 随访问卷通知: 1,
- 随访文章通知: 2,
- 随访复诊提醒: 3,
- 随访用药提醒: 4,
- 随访换药提醒: 5,
- 随访手术提醒: 6,
- 随访注意事项: 7,
- 随访检查预约提醒: 8,
- 随访报告已出提醒: 9,
- 随访体征上传提醒: 10,
- //#endregion
- };
- /** 列表显示的消息 */
- class ContentExtractFactory {
- //#region 在线互动
- [msgTypeEnum.文本消息](content) {
- const obj = this.parse(content);
- return decodeURI(obj.content);
- }
- [msgTypeEnum.图片消息]() {
- return '[图片消息]';
- }
- [msgTypeEnum.视频消息]() {
- return '[视频通话]';
- }
- [msgTypeEnum.患教资料]() {
- return '[健康宣教]';
- }
- [msgTypeEnum.问卷量表]() {
- return '[问卷量表]';
- }
- [msgTypeEnum.申请]() {
- return '[申请交流互动]';
- }
- [msgTypeEnum.申请通过](content) {
- const obj = this.parse(content);
- return `[申请通过]:${obj.content}`;
- }
- [msgTypeEnum.申请拒绝](content) {
- const obj = this.parse(content);
- return `[申请被拒绝]:您好,您的互动申请暂未通过,${obj.content}`;
- }
- [msgTypeEnum.申请取消](content) {
- const obj = this.parse(content);
- return `[申请取消]:${obj.content}`;
- }
- [msgTypeEnum.申请超时](content) {
- const obj = this.parse(content);
- return `[申请超时]:${obj.content}`;
- }
- [msgTypeEnum.结束服务](content) {
- const obj = this.parse(content);
- return `[系统]:${obj.content}`;
- }
- [msgTypeEnum.问卷已填写](content) {
- const obj = this.parse(content);
- return obj.content;
- }
- [msgTypeEnum.患教已读]() {
- return '[健康宣教]';
- }
- //#endregion
- //#region 随访消息
- [msgTypeEnum.随访群发消息](content) {
- const obj = this.parse(content);
- return `[通知]:${obj.txt}`;
- }
- [msgTypeEnum.随访问卷通知]() {
- return `[问卷量表]`;
- }
- [msgTypeEnum.随访文章通知]() {
- return `[健康宣教]`;
- }
- [msgTypeEnum.随访复诊提醒](content) {
- const obj = this.parse(content);
- return `[复诊提醒]:${obj.txt}`;
- }
- [msgTypeEnum.随访用药提醒](content) {
- const obj = this.parse(content);
- return `[用药提醒]:${obj.txt}`;
- }
- [msgTypeEnum.随访换药提醒](content) {
- const obj = this.parse(content);
- return `[换药提醒]:${obj.txt}`;
- }
- [msgTypeEnum.随访手术提醒](content) {
- const obj = this.parse(content);
- return `[手术提醒]:${obj.txt}`;
- }
- [msgTypeEnum.随访注意事项](content) {
- const obj = this.parse(content);
- return `[注意事项]:${obj.txt}`;
- }
- [msgTypeEnum.随访检查预约提醒](content) {
- const obj = this.parse(content);
- return `[检查预约提醒]:${obj.txt}`;
- }
- [msgTypeEnum.随访报告已出提醒](content) {
- const obj = this.parse(content);
- return `[报告已出提醒]:${obj.txt}`;
- }
- [msgTypeEnum.随访体征上传提醒](content) {
- const obj = this.parse(content);
- return `[体征上传提醒]:${obj.txt}`;
- }
- //#endregion
- parse(content) {
- if (typeof content == 'string') {
- try {
- const data = JSON.parse(content);
- return data;
- } catch (error) {
- return content;
- }
- }
- }
- }
- /** 消息内容提取 */
- export const lastMsgContentExtract = (msg) => {
- const factory = new ContentExtractFactory();
- return factory[msg.contentType] ? factory[msg.contentType](msg.content) : '';
- };
- /** 消息内容组件 */
- export const ContentComponents = {
- //#region 在线互动
- [msgTypeEnum['文本消息']]: 'textMsg',
- [msgTypeEnum['图片消息']]: 'imgMsg',
- [msgTypeEnum['视频消息']]: 'videoCallMsg',
- [msgTypeEnum['患教资料']]: 'articleMsg',
- [msgTypeEnum['问卷量表']]: 'questionnaireMsg',
- [msgTypeEnum['申请']]: 'applyMsg',
- [msgTypeEnum['申请通过']]: 'textMsg',
- [msgTypeEnum['申请拒绝']]: 'textMsg',
- [msgTypeEnum['申请取消']]: 'systemMsg',
- [msgTypeEnum['申请超时']]: 'systemMsg',
- [msgTypeEnum['结束服务']]: 'systemMsg',
- [msgTypeEnum['患教已读']]: 'articleMsg',
- [msgTypeEnum['问卷已填写']]: 'questionnaireMsg',
- //#endregion
- //#region 随访消息
- [msgTypeEnum['随访群发消息']]: 'textMsg',
- [msgTypeEnum['随访问卷通知']]: 'questionnaireMsg',
- [msgTypeEnum['随访文章通知']]: 'articleMsg',
- [msgTypeEnum['随访复诊提醒']]: 'textMsg',
- [msgTypeEnum['随访用药提醒']]: 'textMsg',
- [msgTypeEnum['随访换药提醒']]: 'textMsg',
- [msgTypeEnum['随访手术提醒']]: 'textMsg',
- [msgTypeEnum['随访注意事项']]: 'textMsg',
- [msgTypeEnum['随访检查预约提醒']]: 'textMsg',
- [msgTypeEnum['随访报告已出提醒']]: 'textMsg',
- [msgTypeEnum['随访体征上传提醒']]: 'textMsg',
- //#endregion
- };
- /** 消息内容组件内容prop */
- const ContentProps = {
- //#region 在线互动
- [msgTypeEnum['文本消息']]: {
- content: 'Content.content',
- },
- [msgTypeEnum['图片消息']]: {
- content: 'Content.content',
- },
- [msgTypeEnum['视频消息']]: {
- content: 'Content.content',
- },
- [msgTypeEnum['患教资料']]: {
- title: 'Content.title',
- id: 'Content.id',
- read: 'Content.read',
- subTaskId: 'Content.subTaskId',
- },
- [msgTypeEnum['患教已读']]: {
- title: 'Content.title',
- id: 'Content.id',
- read: 'Content.read',
- subTaskId: 'Content.subTaskId',
- },
- [msgTypeEnum['问卷量表']]: {
- title: 'Content.title',
- id: 'Content.subjectId',
- subTaskId: 'Content.subTaskId',
- },
- [msgTypeEnum['问卷已填写']]: {
- id: 'Content.subjectId',
- title: 'Content.title',
- content: 'Content.content',
- sampleId: 'Content.sampleId',
- recordId: 'Content.recordId',
- subTaskId: 'Content.subTaskId',
- },
- [msgTypeEnum['申请']]: {
- content: 'Content.content',
- imgList: 'Content.imgList',
- id: 'Id',
- },
- [msgTypeEnum['申请通过']]: {
- content: 'Content.content',
- },
- [msgTypeEnum['申请拒绝']]: {
- content: 'Content.content',
- format(obj) {
- return `您好,您的互动申请暂未通过,${obj.content}`;
- },
- },
- [msgTypeEnum['申请超时']]: {
- content: 'Content.content',
- },
- [msgTypeEnum['申请取消']]: {
- content: 'Content.content',
- },
- [msgTypeEnum['结束服务']]: {
- content: 'Content.content',
- },
- //#endregion
- //#region 随访消息
- [msgTypeEnum['随访群发消息']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访问卷通知']]: {
- title: 'Content.txt',
- id: 'Content.id',
- subTaskId: 'Content.subTaskId',
- },
- [msgTypeEnum['随访文章通知']]: {
- title: 'Content.txt',
- id: 'Content.id',
- msgId: 'Content.msgId',
- subTaskId: 'Content.subTaskId',
- },
- [msgTypeEnum['随访复诊提醒']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访用药提醒']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访换药提醒']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访手术提醒']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访注意事项']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访检查预约提醒']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访报告已出提醒']]: {
- content: 'Content.txt',
- },
- [msgTypeEnum['随访体征上传提醒']]: {
- content: 'Content.txt',
- },
- //#endregion
- };
- /** 转换消息 */
- export const parseMessageEntry = (message, type) => {
- const obj = {};
- const props = ContentProps[type];
- if (!props) return;
- let hasFormat = typeof props['format'] == 'function';
- Object.keys(props).map((key) => {
- if (key != 'format') {
- const path = props[key].split('.');
- if (path.length <= 1) {
- obj[key] = message[path];
- } else {
- obj[key] = path.reduce((item, p) => {
- if (item instanceof Array) {
- const [v] = item.filter((i) => i.key == p);
- return v?.value;
- } else {
- try {
- if (typeof item[p] == 'string') {
- const value = JSON.parse(item[p]);
- typeof value == 'object' && (item[p] = value);
- }
- return item[p];
- } catch (error) {
- return item[p];
- }
- }
- }, message);
- }
- }
- });
- hasFormat && (obj['content'] = props['format'](obj));
- return obj;
- };
- /** 会话记录排序*/
- export const msgListSort = (
- list,
- props = {
- sendTime: 'CreateTime',
- }
- ) => {
- // 时间排序 从小到大 最新的在后面
- list.sort((a, b) => {
- return new Date(a[props.sendTime]).getTime() - new Date(b[props.sendTime]).getTime();
- });
- return list;
- };
- /** 判断消息是否显示时间 */
- export const msgJudgeTime = (
- list,
- lastMsg = null,
- props = {
- sendTime: 'CreateTime',
- }
- ) => {
- for (let i = 0; i < list.length; i++) {
- if (i == 0) {
- list[i].showSendTime = lastMsg
- ? compareTime(list[i][props.sendTime], lastMsg[props.sendTime])
- : true;
- } else {
- list[i].showSendTime = compareTime(list[i][props.sendTime], list[i - 1][props.sendTime]);
- }
- list[i].isNew = !!lastMsg;
- }
- return list;
- };
- /** 对比时间 */
- export const compareTime = (startTime, endTime) => {
- const times = new Date(startTime).getTime();
- const preTimes = new Date(endTime).getTime();
- return times - preTimes >= 5 * 60 * 1000;
- };
|