|
|
|
@ -16,6 +16,7 @@ interface IMessageItem {
@@ -16,6 +16,7 @@ interface IMessageItem {
|
|
|
|
|
hospitalName: string; |
|
|
|
|
showTime?: boolean; |
|
|
|
|
isPlay?: boolean; |
|
|
|
|
uniqueCode?: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Page({ |
|
|
|
@ -43,7 +44,8 @@ Page({
@@ -43,7 +44,8 @@ Page({
|
|
|
|
|
|
|
|
|
|
userInfo: {} as any, |
|
|
|
|
|
|
|
|
|
sendMessage: [], |
|
|
|
|
sendMessage: "", |
|
|
|
|
videoUrl: "", |
|
|
|
|
}, |
|
|
|
|
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null, |
|
|
|
|
videoContext: null as WechatMiniprogram.VideoContext | null, |
|
|
|
@ -52,12 +54,14 @@ Page({
@@ -52,12 +54,14 @@ Page({
|
|
|
|
|
id: options.id, |
|
|
|
|
}); |
|
|
|
|
this.videoContext = wx.createVideoContext("video"); |
|
|
|
|
this.innerAudioContext = wx.createInnerAudioContext({ |
|
|
|
|
useWebAudioImplement: true, |
|
|
|
|
}); |
|
|
|
|
app.waitLogin().then(() => { |
|
|
|
|
// this.getAgree();
|
|
|
|
|
|
|
|
|
|
this.getMessageList(); |
|
|
|
|
this.getDetail(); |
|
|
|
|
this.listenMessage(); |
|
|
|
|
app.getUserInfo(this); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
@ -66,6 +70,9 @@ Page({
@@ -66,6 +70,9 @@ Page({
|
|
|
|
|
if (this.innerAudioContext) { |
|
|
|
|
this.innerAudioContext.stop(); |
|
|
|
|
} |
|
|
|
|
if (this.videoContext) { |
|
|
|
|
this.videoContext.stop(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
getAgree() { |
|
|
|
|
wx.ajax({ |
|
|
|
@ -117,22 +124,17 @@ Page({
@@ -117,22 +124,17 @@ Page({
|
|
|
|
|
url: `/module1/pages/chatRoomInfo/index?id=${this.data.id}&cid=${this.data.case.caseId}`, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleCaseDetail() { |
|
|
|
|
wx.navigateTo({ |
|
|
|
|
url: `/module1/pages/casesDetail/index?id=${this.data.case.caseId}`, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleView(index = -1) { |
|
|
|
|
this.setData({ |
|
|
|
|
scrollIntoView: index > -1 ? `view${index}` : `place`, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
listenMessage() { |
|
|
|
|
wx.WebIM.conn.addEventHandler("room", { |
|
|
|
|
onConnected: (message) => { |
|
|
|
|
console.log("message: ", message); |
|
|
|
|
}, |
|
|
|
|
onTextMessage: (meessage) => { |
|
|
|
|
console.log("meessage1: ", meessage); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
getMessageList() { |
|
|
|
|
if (this.data.isLoad || this.data.isFinish) return; |
|
|
|
|
this.setData({ |
|
|
|
@ -154,11 +156,7 @@ Page({
@@ -154,11 +156,7 @@ Page({
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
res.map((item) => { |
|
|
|
|
//消息内容类型,1-文本,2-语音,3-图片,4-视频,5-提示信息
|
|
|
|
|
if (["2", "3", "4"].includes(item.contentType)) { |
|
|
|
|
item.msgContent = JSON.parse(item.msgContent); |
|
|
|
|
} |
|
|
|
|
return item; |
|
|
|
|
return this.formatMessage(item); |
|
|
|
|
}); |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [...res.reverse(), ...this.data.messageList], |
|
|
|
@ -166,9 +164,7 @@ Page({
@@ -166,9 +164,7 @@ Page({
|
|
|
|
|
isLoad: false, |
|
|
|
|
}); |
|
|
|
|
this.filterCreateTime(); |
|
|
|
|
if (!lastMsgId) { |
|
|
|
|
this.handleView(); |
|
|
|
|
} |
|
|
|
|
this.handleView(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
scrolltoupper(e) { |
|
|
|
@ -176,13 +172,6 @@ Page({
@@ -176,13 +172,6 @@ Page({
|
|
|
|
|
this.getMessageList(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
WebIMLogin() { |
|
|
|
|
const { chatDoctor } = this.data; |
|
|
|
|
wx.WebIM.conn.open({ |
|
|
|
|
user: chatDoctor.chatUserId, |
|
|
|
|
pwd: chatDoctor.chatUserPwd, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleSendMessage() { |
|
|
|
|
const { sendMessage, userInfo } = this.data; |
|
|
|
|
if (!sendMessage) { |
|
|
|
@ -199,13 +188,100 @@ Page({
@@ -199,13 +188,100 @@ Page({
|
|
|
|
|
fromDoctorId: userInfo.DoctorId, |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
isSelf: 1, |
|
|
|
|
isRead: 1, |
|
|
|
|
isRead: 2, |
|
|
|
|
doctorImg: userInfo.Img, |
|
|
|
|
doctorName: userInfo.Name, |
|
|
|
|
hospitalName: userInfo.HospitalName, |
|
|
|
|
}; |
|
|
|
|
this.setData({ |
|
|
|
|
sendMessage: "", |
|
|
|
|
}); |
|
|
|
|
this.WebIMSendMessage(message); |
|
|
|
|
}, |
|
|
|
|
handleSendAudio(e) { |
|
|
|
|
const { userInfo } = this.data; |
|
|
|
|
const contentStr = JSON.stringify({ |
|
|
|
|
url: e.detail.fileUrl, |
|
|
|
|
duration: e.detail.duration, |
|
|
|
|
}); |
|
|
|
|
const message: IMessageItem = { |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "2", |
|
|
|
|
content: contentStr, |
|
|
|
|
fromDoctorId: userInfo.DoctorId, |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
isSelf: 1, |
|
|
|
|
isRead: 2, |
|
|
|
|
doctorImg: userInfo.Img, |
|
|
|
|
doctorName: userInfo.Name, |
|
|
|
|
hospitalName: userInfo.HospitalName, |
|
|
|
|
}; |
|
|
|
|
this.WebIMSendMessage(message); |
|
|
|
|
}, |
|
|
|
|
handleSendPhoto(e) { |
|
|
|
|
const { userInfo } = this.data; |
|
|
|
|
const contentStr = JSON.stringify({ |
|
|
|
|
url: e.detail.fileUrl, |
|
|
|
|
}); |
|
|
|
|
const message: IMessageItem = { |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "3", |
|
|
|
|
content: contentStr, |
|
|
|
|
fromDoctorId: userInfo.DoctorId, |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
isSelf: 1, |
|
|
|
|
isRead: 2, |
|
|
|
|
doctorImg: userInfo.Img, |
|
|
|
|
doctorName: userInfo.Name, |
|
|
|
|
hospitalName: userInfo.HospitalName, |
|
|
|
|
}; |
|
|
|
|
this.WebIMSendMessage(message); |
|
|
|
|
}, |
|
|
|
|
handleSendVideo(e) { |
|
|
|
|
const { userInfo } = this.data; |
|
|
|
|
const contentStr = JSON.stringify({ |
|
|
|
|
url: e.detail.fileUrl, |
|
|
|
|
imgUrl: e.detail.imgUrl, |
|
|
|
|
}); |
|
|
|
|
const message: IMessageItem = { |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "4", |
|
|
|
|
content: contentStr, |
|
|
|
|
fromDoctorId: userInfo.DoctorId, |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
isSelf: 1, |
|
|
|
|
isRead: 2, |
|
|
|
|
doctorImg: userInfo.Img, |
|
|
|
|
doctorName: userInfo.Name, |
|
|
|
|
hospitalName: userInfo.HospitalName, |
|
|
|
|
}; |
|
|
|
|
this.WebIMSendMessage(message); |
|
|
|
|
}, |
|
|
|
|
sendMessage({ uniqueCode, ...message }) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "POST", |
|
|
|
|
url: "?r=takeda/chat/send-message", |
|
|
|
|
data: { |
|
|
|
|
roomId: this.data.id, |
|
|
|
|
message: { |
|
|
|
|
contentType: message.contentType, |
|
|
|
|
content: message.content, |
|
|
|
|
uniqueCode, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
WebIMLogin() { |
|
|
|
|
const { chatDoctor } = this.data; |
|
|
|
|
wx.WebIM.conn |
|
|
|
|
.open({ |
|
|
|
|
user: chatDoctor.chatUserId, |
|
|
|
|
pwd: chatDoctor.chatUserPwd, |
|
|
|
|
}) |
|
|
|
|
.then(() => { |
|
|
|
|
this.listenMessage(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
WebIMSendMessage(message: IMessageItem) { |
|
|
|
|
const { chatGroupInfo } = this.data; |
|
|
|
|
const option = { |
|
|
|
@ -223,8 +299,9 @@ Page({
@@ -223,8 +299,9 @@ Page({
|
|
|
|
|
.then((res) => { |
|
|
|
|
this.sendMessage({ ...message, uniqueCode: res.serverMsgId }); |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [...this.data.messageList, message], |
|
|
|
|
messageList: [...this.data.messageList, this.formatMessage(message)], |
|
|
|
|
}); |
|
|
|
|
this.handleView(); |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
@ -233,40 +310,35 @@ Page({
@@ -233,40 +310,35 @@ Page({
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
sendMessage({ uniqueCode, ...message }) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "POST", |
|
|
|
|
url: "?r=takeda/chat/send-message", |
|
|
|
|
data: { |
|
|
|
|
roomId: this.data.id, |
|
|
|
|
message: { |
|
|
|
|
contentType: message.contentType, |
|
|
|
|
content: message.content, |
|
|
|
|
uniqueCode, |
|
|
|
|
}, |
|
|
|
|
listenMessage() { |
|
|
|
|
const { chatGroupInfo } = this.data; |
|
|
|
|
wx.WebIM.conn.addEventHandler("room", { |
|
|
|
|
onTextMessage: (message) => { |
|
|
|
|
if (message.error) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (message.to === chatGroupInfo.ChatGroupId) { |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [ |
|
|
|
|
...this.data.messageList, |
|
|
|
|
this.formatMessage({ |
|
|
|
|
...message.ext, |
|
|
|
|
isSelf: 2, |
|
|
|
|
}), |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
this.handleReadAll(); |
|
|
|
|
this.handleView(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleHot(e) { |
|
|
|
|
const { index, mindex } = e.currentTarget.dataset; |
|
|
|
|
const { messageList } = this.data; |
|
|
|
|
const hotList = messageList[mindex].welcomeMsg?.hotQuestion; |
|
|
|
|
const hot = hotList?.[index]; |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [ |
|
|
|
|
...messageList, |
|
|
|
|
{ |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "1", |
|
|
|
|
msgContent: hot?.question, |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
this.handleView(); |
|
|
|
|
this.sendQuestion(hot?.questionId); |
|
|
|
|
formatMessage(message: IMessageItem) { |
|
|
|
|
//消息内容类型,1-文本,2-语音,3-图片,4-视频,5-提示信息
|
|
|
|
|
if (["2", "3", "4"].includes(message.contentType)) { |
|
|
|
|
message.content = JSON.parse(message.content); |
|
|
|
|
} |
|
|
|
|
return message; |
|
|
|
|
}, |
|
|
|
|
formatTime(date: string) { |
|
|
|
|
let createTimeName = ""; |
|
|
|
@ -308,7 +380,7 @@ Page({
@@ -308,7 +380,7 @@ Page({
|
|
|
|
|
this.setData({ |
|
|
|
|
fold: !this.data.fold, |
|
|
|
|
}); |
|
|
|
|
if (this.data.fold) { |
|
|
|
|
if (!this.data.fold) { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
this.handleView(); |
|
|
|
|
}, 300); |
|
|
|
@ -318,7 +390,7 @@ Page({
@@ -318,7 +390,7 @@ Page({
|
|
|
|
|
const { index } = e.currentTarget.dataset; |
|
|
|
|
const { messageList } = this.data; |
|
|
|
|
const messageItem = messageList[index]; |
|
|
|
|
const { url } = messageItem.content[0]; |
|
|
|
|
const { url } = messageItem.content; |
|
|
|
|
if (this.innerAudioContext) { |
|
|
|
|
if (messageItem.isPlay) { |
|
|
|
|
this.innerAudioContext.stop(); |
|
|
|
@ -332,6 +404,13 @@ Page({
@@ -332,6 +404,13 @@ Page({
|
|
|
|
|
this.innerAudioContext.src = url; |
|
|
|
|
this.innerAudioContext.play(); |
|
|
|
|
messageItem.isPlay = true; |
|
|
|
|
if (messageItem.isRead === 2 && messageItem.isSelf === 2) { |
|
|
|
|
messageItem.isRead = 1; |
|
|
|
|
this.handleReadAudio({ |
|
|
|
|
msgId: messageItem.msgId, |
|
|
|
|
uniqueCode: messageItem.uniqueCode, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
this.innerAudioContext.onEnded(() => { |
|
|
|
|
messageItem.isPlay = false; |
|
|
|
|
this.setData({ |
|
|
|
@ -343,16 +422,39 @@ Page({
@@ -343,16 +422,39 @@ Page({
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
handleReadAudio({ msgId, uniqueCode }) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "POST", |
|
|
|
|
url: "?r=takeda/chat/read-message", |
|
|
|
|
data: { |
|
|
|
|
roomId: this.data.id, |
|
|
|
|
msgId, |
|
|
|
|
uniqueCode, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handlePreview(e) { |
|
|
|
|
const { url } = e.currentTarget.dataset; |
|
|
|
|
wx.previewImage({ |
|
|
|
|
urls: [url], |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleVideo() { |
|
|
|
|
handleVideo(e) { |
|
|
|
|
const { url } = e.currentTarget.dataset; |
|
|
|
|
if (this.videoContext) { |
|
|
|
|
this.setData({ |
|
|
|
|
videoUrl: url, |
|
|
|
|
}); |
|
|
|
|
this.videoContext.play(); |
|
|
|
|
this.videoContext.requestFullScreen({}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleReadAll() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "POST", |
|
|
|
|
url: "?r=takeda/chat/read-all-message", |
|
|
|
|
data: { roomId: this.data.id }, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|