|
@@ -4,7 +4,10 @@
|
|
|
<el-popover placement="top" width="400" trigger="click">
|
|
|
<div class="emojis">
|
|
|
<div v-for="item in emojiName" class="emoji" :key="item" @click="chooseEmoji(item)">
|
|
|
- <img :src="emojiUrl + emojiMap[item]" style="width:30px;height:30px" />
|
|
|
+ <!--<img :src="emojiUrl + emojiCharMap[item]" style="width:30px;height:30px" />-->
|
|
|
+ <span style="width:30px;height:30px">
|
|
|
+ {{emojiCharMap[item]}}
|
|
|
+ </span>
|
|
|
</div>
|
|
|
</div>
|
|
|
<i class="iconfont icon-smile" slot="reference" title="发表情"></i>
|
|
@@ -17,23 +20,25 @@
|
|
|
<!-- <i class="iconfont icon-diaocha" title="小调查" @click="surveyDialogVisible = true"></i> -->
|
|
|
<el-dropdown>
|
|
|
<span class="el-dropdown-link">
|
|
|
- <i class="el-icon-phone-outline" v-if="toAccount !== userID&&((imType==1&&orderType==2)||imType==2)" title="语音通话"></i>
|
|
|
+ <!--<i class="el-icon-phone-outline" v-if="toAccount !== userID&&((imType==1&&orderType==2)||imType==2)" title="语音通话"></i>-->
|
|
|
+ <i class="el-icon-phone-outline" title="语音通话"></i>
|
|
|
</span>
|
|
|
<el-dropdown-menu slot="dropdown">
|
|
|
<el-dropdown-item @click.native="trtcCalling('video')">视频通话</el-dropdown-item>
|
|
|
<el-dropdown-item @click.native="trtcCalling('audio')">语音通话</el-dropdown-item>
|
|
|
</el-dropdown-menu>
|
|
|
</el-dropdown>
|
|
|
- <div class="group-live-icon-box" v-if="currentConversationType === TIM.TYPES.CONV_GROUP && groupProfile.type !== 'AVChatRoom'" title="群直播" @click="groupLive">
|
|
|
+ <div class="group-live-icon-box" v-if="currentConversationType === 4&& groupProfile.type !== 'AVChatRoom'" title="群直播" @click="groupLive">
|
|
|
<i class="group-live-icon"></i>
|
|
|
<i class="group-live-icon-hover"></i>
|
|
|
</div>
|
|
|
- <i class="el-icon-s-order" v-if="imType==1" title="问诊订单" @click="handleInquiryOrder()"></i>
|
|
|
+
|
|
|
+ <i class="el-icon-s-order" title="问诊订单" @click="handleInquiryOrder()"></i>
|
|
|
<i class="el-icon-document" v-if="imType==1" title="诊断报告" @click="handleInquiryReport()"></i>
|
|
|
<i class="el-icon-edit-outline" v-if="imType==1" title="开处方" @click="handlePrescribe()"></i>
|
|
|
<i class="el-icon-circle-close" v-if="imType==1" title="结束问诊" @click="handleFinishInquiry()"></i>
|
|
|
<i class="el-icon-finished" v-if="imType==2" title="随访单" @click="handleFollow()"></i>
|
|
|
- <i class="el-icon-tickets" title="药品订单" @click="handleStoreOrder()"></i>
|
|
|
+ <i class="el-icon-tickets" v-if="this.$store.state.conversation.currentConversation.conversationID.includes('U')" title="药品订单" @click="handleStoreOrder()"></i>
|
|
|
<i class="el-icon-edit-outline" v-if="imType==2" title="开报告" @click="handleDrugReport()"></i>
|
|
|
<i class="el-icon-circle-close" v-if="imType==2" title="结束咨询" @click="handleFinishDrugReport()"></i>
|
|
|
<i class="el-icon-chat-dot-square" title="常用语" @click="handleDoctorWords()"></i>
|
|
@@ -114,7 +119,7 @@
|
|
|
/>
|
|
|
<input type="file" id="filePicker" ref="filePicker" @change="sendFile" style="display:none" />
|
|
|
<input type="file" id="videoPicker" ref="videoPicker" @change="sendVideo" style="display:none" accept=".mp4"/>
|
|
|
- <div class="calling-member-list" v-if="currentConversationType === TIM.TYPES.CONV_GROUP && showCallingMember">
|
|
|
+ <div class="calling-member-list" v-if="currentConversationType === 3 && showCallingMember">
|
|
|
<calling-member-list @getList="getList" :type="listTpye"></calling-member-list>
|
|
|
<div class="calling-list-btn">
|
|
|
<span class="calling-btn" @click="cancelCalling">取消</span>
|
|
@@ -158,7 +163,8 @@ import {
|
|
|
Tooltip,
|
|
|
Rate
|
|
|
} from 'element-ui'
|
|
|
-import { emojiMap, emojiName, emojiUrl } from '../../utils/emojiMap'
|
|
|
+import { getOpenIM } from '@/utils/openIM';
|
|
|
+import { emojiMap, emojiName, emojiUrl,emojiCharMap } from '../../utils/emojiMap'
|
|
|
|
|
|
export default {
|
|
|
name: 'message-send-box',
|
|
@@ -209,6 +215,7 @@ export default {
|
|
|
file: '',
|
|
|
emojiMap: emojiMap,
|
|
|
emojiName: emojiName,
|
|
|
+ emojiCharMap:emojiCharMap,
|
|
|
emojiUrl: emojiUrl,
|
|
|
showAtGroupMember: false,
|
|
|
atUserID: '',
|
|
@@ -255,6 +262,12 @@ export default {
|
|
|
beforeDestroy() {
|
|
|
this.$refs['text-input'].removeEventListener('paste', this.handlePaste)
|
|
|
},
|
|
|
+ created() {
|
|
|
+ if (!this.OpenIM) {
|
|
|
+ this.OpenIM = getOpenIM()
|
|
|
+ console.log("OpenIM SDK 初始化完成");
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
sendWords(msg){
|
|
|
console.log(msg)
|
|
@@ -314,7 +327,11 @@ export default {
|
|
|
this.show.type=2;
|
|
|
this.show.open=true;
|
|
|
this.show.title="药品订单"
|
|
|
- var userId=this.$store.state.conversation.currentConversation.conversationID.split("-")[1];
|
|
|
+ console.log(this.$store.state.conversation.currentConversation.conversationID)
|
|
|
+ const conversationID = this.$store.state.conversation.currentConversation.conversationID;
|
|
|
+ const match = conversationID.match(/U(\d+)/);
|
|
|
+ const userId = match ? Number(match[1]) : null;
|
|
|
+ console.log("this.$store.state.conversation.currentConversation.conversationID.",userId)
|
|
|
setTimeout(() => {
|
|
|
that.$refs.storeOrderList.getData(userId);
|
|
|
}, 500);
|
|
@@ -325,8 +342,11 @@ export default {
|
|
|
var that=this;
|
|
|
this.show.type=1;
|
|
|
this.show.open=true;
|
|
|
- var userId=this.$store.state.conversation.currentConversation.conversationID.split("-")[1];
|
|
|
- console.log(userId)
|
|
|
+ const userId = this.$store.state.conversation.currentConversation.conversationID
|
|
|
+ .split("_")
|
|
|
+ .filter(id => id.includes("U"))
|
|
|
+ .map(id => id.replace("U", ""));
|
|
|
+ //console.log(userID,"yonghh")
|
|
|
this.show.title="问诊订单"
|
|
|
setTimeout(() => {
|
|
|
|
|
@@ -362,6 +382,7 @@ export default {
|
|
|
cancelButtonText: '取消',
|
|
|
type: 'warning'
|
|
|
}).then(() => {
|
|
|
+ console.log(that.$store.state.conversation)
|
|
|
var data={orderId:that.$store.state.conversation.orderId}
|
|
|
finishOrder(data).then(res => {
|
|
|
if(res.code==200){
|
|
@@ -410,7 +431,7 @@ export default {
|
|
|
if (this.listTpye === 'calling') {
|
|
|
let callingData = {
|
|
|
memberList:this.callingList,
|
|
|
- type:this.TIM.TYPES.CONV_GROUP
|
|
|
+ type:3
|
|
|
}
|
|
|
this.$store.commit('setCallingList',callingData)
|
|
|
if (this.callingType === 'video') {
|
|
@@ -424,28 +445,90 @@ export default {
|
|
|
|
|
|
},
|
|
|
trtcCalling(type) {
|
|
|
+ console.log(`尝试发起${type === 'video' ? '视频' : '语音'}通话`)
|
|
|
+
|
|
|
+ // 1. 检查OpenIM是否初始化
|
|
|
+ /*if (!this.OpenIM) {
|
|
|
+ console.error('OpenIM未初始化')
|
|
|
+ this.$message.error('IM服务未就绪')
|
|
|
+ return
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // 2. 设置通话类型
|
|
|
this.listTpye = 'calling'
|
|
|
- if (type === 'video') {
|
|
|
- this.callingType = 'video'
|
|
|
- }
|
|
|
- if (type === 'audio') {
|
|
|
- this.callingType = 'audio'
|
|
|
+ this.callingType = type
|
|
|
+
|
|
|
+ // 3. 处理不同类型的会话
|
|
|
+ if (this.currentConversationType === 1) {
|
|
|
+ // 单聊
|
|
|
+ this.startSingleCall(type)
|
|
|
+ } else if (this.currentConversationType === 3) {
|
|
|
+ // 群聊 - 显示成员选择
|
|
|
+ this.showCallingMember = true
|
|
|
+ } else {
|
|
|
+ console.error('不支持的会话类型')
|
|
|
+ this.$message.error('当前会话不支持通话')
|
|
|
}
|
|
|
- // 呼叫方设置
|
|
|
- if(this.currentConversationType === 'C2C') {
|
|
|
- let member = [this.toAccount]
|
|
|
- let callingData = {
|
|
|
- memberList:member,
|
|
|
- type:'C2C'
|
|
|
+ },
|
|
|
+
|
|
|
+ // 发起单聊通话
|
|
|
+ async startSingleCall(type) {
|
|
|
+ try {
|
|
|
+ const member = [this.toAccount]
|
|
|
+ const callingData = {
|
|
|
+ memberList: member,
|
|
|
+ type: 1 // 单聊
|
|
|
}
|
|
|
- this.$store.commit('setCallingList',callingData)
|
|
|
+
|
|
|
+ // 1. 存储通话信息
|
|
|
+ this.$store.commit('setCallingList', callingData)
|
|
|
+ console.log("通话信息",callingData)
|
|
|
+ // 2. 触发通话事件
|
|
|
this.$bus.$emit(`${type}-call`)
|
|
|
+
|
|
|
+ // 3. 日志记录
|
|
|
+ console.log(`已触发${type}-call事件`, {
|
|
|
+ targetUser: this.toAccount,
|
|
|
+ conversationType: this.currentConversationType
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('发起通话失败:', error)
|
|
|
+ this.$message.error('发起通话失败')
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 群聊确定按钮处理
|
|
|
+ callingHandler() {
|
|
|
+ if (this.callingList.length < 1) {
|
|
|
+ this.$message.warning('请选择成员')
|
|
|
return
|
|
|
}
|
|
|
- if(this.currentConversationType === this.TIM.TYPES.CONV_GROUP) {
|
|
|
- this.showCallingMember = true
|
|
|
+
|
|
|
+ if (this.listTpye === 'groupAt') {
|
|
|
+ // @成员处理...(原有逻辑)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.listTpye === 'calling') {
|
|
|
+ const callingData = {
|
|
|
+ memberList: this.callingList,
|
|
|
+ type: 3 // 群聊
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 存储通话信息
|
|
|
+ this.$store.commit('setCallingList', callingData)
|
|
|
+
|
|
|
+ // 2. 根据类型触发不同事件
|
|
|
+ if (this.callingType === 'video') {
|
|
|
+ console.log("发起群视频通话,成员:", this.callingList)
|
|
|
+ this.$bus.$emit('video-call')
|
|
|
+ } else {
|
|
|
+ console.log("发起群语音通话,成员:", this.callingList)
|
|
|
+ this.$bus.$emit('audio-call')
|
|
|
+ }
|
|
|
+
|
|
|
+ this.showCallingMember = false
|
|
|
}
|
|
|
- // this.$store.commit('pushCurrentMessageList', true)
|
|
|
},
|
|
|
handleEmojiShow () {
|
|
|
this.emojiShow = true
|
|
@@ -461,7 +544,7 @@ export default {
|
|
|
},
|
|
|
chooseBigEmoji(item) {
|
|
|
this.popoverVisible = false
|
|
|
- let message = this.tim.createFaceMessage({
|
|
|
+ let message = this.OpenIM.createFaceMessage({
|
|
|
to: this.toAccount,
|
|
|
conversationType: this.currentConversationType,
|
|
|
payload: {
|
|
@@ -469,9 +552,18 @@ export default {
|
|
|
data: `${item}@2x`
|
|
|
}
|
|
|
})
|
|
|
+ let offlinePushInfo = {
|
|
|
+ title:"芳华未来",
|
|
|
+ desc:"表情消息",
|
|
|
+ iOSPushSound:"",
|
|
|
+ iOSBadgeCount:true,
|
|
|
+ operatorUserID:"",
|
|
|
+ ex:""
|
|
|
+ }
|
|
|
this.$store.commit('pushCurrentMessageList', message)
|
|
|
+ this.updateConversationList()
|
|
|
this.$bus.$emit('scroll-bottom')
|
|
|
- this.tim.sendMessage(message).catch(error => {
|
|
|
+ this.OpenIM.sendMessage(message,offlinePushInfo).catch(error => {
|
|
|
this.$store.commit('showMessage', {
|
|
|
type: 'error',
|
|
|
message: error.message
|
|
@@ -503,7 +595,7 @@ export default {
|
|
|
this.sendTextMessage()
|
|
|
},
|
|
|
inputChange(value) {
|
|
|
- if (this.currentConversationType === this.TIM.TYPES.CONV_GROUP && value.data === '@') {
|
|
|
+ if (this.currentConversationType === 3 && value.data === '@') {
|
|
|
this.groupAt = true
|
|
|
this.listTpye = 'groupAt'
|
|
|
this.showCallingMember = true
|
|
@@ -532,7 +624,7 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
// 1. 创建消息实例,接口返回的实例可以上屏
|
|
|
- let message = this.tim.createImageMessage({
|
|
|
+ let message = this.OpenIM.createImageMessageFromFullPath({
|
|
|
to: this.toAccount,
|
|
|
conversationType: this.currentConversationType,
|
|
|
payload: {
|
|
@@ -543,9 +635,9 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
this.$store.commit('pushCurrentMessageList', message)
|
|
|
-
|
|
|
+ this.updateConversationList()
|
|
|
// 2. 发送消息
|
|
|
- let promise = this.tim.sendMessage(message)
|
|
|
+ let promise = this.OpenIM.sendMessage(message)
|
|
|
promise.catch(error => {
|
|
|
this.$store.commit('showMessage', {
|
|
|
type: 'error',
|
|
@@ -558,7 +650,7 @@ export default {
|
|
|
let file = e.dataTransfer.files[0]
|
|
|
let message = {}
|
|
|
if (file.type === 'video/mp4') {
|
|
|
- message = this.tim.createVideoMessage({
|
|
|
+ message = this.OpenIM.createVideoMessage({
|
|
|
to: this.toAccount,
|
|
|
conversationType: this.currentConversationType,
|
|
|
payload: {
|
|
@@ -569,7 +661,7 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
- message = this.tim.createFileMessage({
|
|
|
+ message = this.OpenIM.createFileMessage({
|
|
|
to: this.toAccount,
|
|
|
conversationType: this.currentConversationType,
|
|
|
payload: {
|
|
@@ -581,7 +673,8 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
this.$store.commit('pushCurrentMessageList', message)
|
|
|
- this.tim
|
|
|
+ this.updateConversationList()
|
|
|
+ this.OpenIM
|
|
|
.sendMessage(message)
|
|
|
.then(() => {
|
|
|
this.$refs.videoPicker.value = null
|
|
@@ -612,20 +705,22 @@ export default {
|
|
|
followId:this.$store.state.conversation.followId,
|
|
|
orderType:this.$store.state.conversation.orderType
|
|
|
}
|
|
|
- if (this.currentConversationType === this.TIM.TYPES.CONV_GROUP && this.groupAt) {
|
|
|
+ if (this.currentConversationType === 3 && this.groupAt) {
|
|
|
|
|
|
- let message = this.tim.createTextAtMessage({
|
|
|
+ let message = this.OpenIM.createTextAtMessage({
|
|
|
cloudCustomData:JSON.stringify(customData),
|
|
|
to: this.toAccount,
|
|
|
- conversationType: this.TIM.TYPES.CONV_GROUP,
|
|
|
+ conversationType: 3,
|
|
|
payload: {
|
|
|
text: this.messageContent,
|
|
|
atUserList: this.callingList // 'denny' 'lucy' 都是 userID,而非昵称
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
this.$store.commit('pushCurrentMessageList', message)
|
|
|
+ this.updateConversationList()
|
|
|
this.$bus.$emit('scroll-bottom')
|
|
|
- this.tim.sendMessage(message).catch(error => {
|
|
|
+ this.OpenIM.sendMessage(message).catch(error => {
|
|
|
this.$store.commit('showMessage', {
|
|
|
type: 'error',
|
|
|
message: error.message
|
|
@@ -635,21 +730,68 @@ export default {
|
|
|
this.groupAt = false
|
|
|
return
|
|
|
}
|
|
|
- const message = this.tim.createTextMessage({
|
|
|
- cloudCustomData:JSON.stringify(customData),
|
|
|
- to: this.toAccount,
|
|
|
- conversationType: this.currentConversationType,
|
|
|
- payload: { text: this.messageContent }
|
|
|
- })
|
|
|
- this.$store.commit('pushCurrentMessageList', message)
|
|
|
- this.$bus.$emit('scroll-bottom')
|
|
|
- this.tim.sendMessage(message).catch(error => {
|
|
|
- this.$store.commit('showMessage', {
|
|
|
- type: 'error',
|
|
|
- message: error.message
|
|
|
+ console.log("this.messageContent",this.messageContent)
|
|
|
+ this.OpenIM.createTextMessage(this.messageContent).then(({ data }) => {
|
|
|
+ console.log("创建文本消息返回参数")
|
|
|
+ console.log(data)
|
|
|
+ console.log("接受哦人id"+ this.$store.getters.toAccount)
|
|
|
+ // 调用成功
|
|
|
+ //console.log("customData",customData)
|
|
|
+ data.ex = JSON.stringify(customData)
|
|
|
+ const sendText={
|
|
|
+ message:data,
|
|
|
+ recvID:this.$store.getters.toAccount,
|
|
|
+ groupID:"",
|
|
|
+ offlinePushInfo : {
|
|
|
+ title:data.senderNickname,
|
|
|
+ desc:this.messageContent,
|
|
|
+ iOSPushSound:"",
|
|
|
+ iOSBadgeCount:true,
|
|
|
+ operatorUserID:"",
|
|
|
+ ex:""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log("发送消息参数",sendText)
|
|
|
+ console.log("发送消息参数",this.OpenIM)
|
|
|
+ console.log("发送消息参数",this.OpenIM.isLogin)
|
|
|
+ /*if (!this.OpenIM || !this.OpenIM.isLogin) {
|
|
|
+ console.warn('⚠️ OpenIM SDK 尚未登录完成,无法发起邀请');
|
|
|
+ return;
|
|
|
+ }*/
|
|
|
+ this.OpenIM.sendMessage(sendText).then(({ data }) => {
|
|
|
+ console.log("发送消息返回参数",data)
|
|
|
+ // 调用成功
|
|
|
+ console.log("customData",customData)
|
|
|
+ const msgList = Array.isArray(data) ? data : [data];
|
|
|
+ this.$store.commit('pushCurrentMessageList', msgList)
|
|
|
+ this.updateConversationList()
|
|
|
+ this.$bus.$emit('scroll-bottom')
|
|
|
+ }).catch(({ errCode, errMsg }) => {
|
|
|
+ // 调用失败
|
|
|
+ });
|
|
|
+ this.messageContent = ''
|
|
|
+ }).catch(({ errCode, errMsg }) => {
|
|
|
+ // 调用失败
|
|
|
+ });
|
|
|
+ /*{
|
|
|
+ cloudCustomData:JSON.stringify(customData),
|
|
|
+ to: this.toAccount,
|
|
|
+ conversationType: this.currentConversationType,
|
|
|
+ payload: { text: this.messageContent }
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ updateConversationList(){
|
|
|
+ this.OpenIM.getAllConversationList()
|
|
|
+ .then(({ data }) => {
|
|
|
+ // 调用成功
|
|
|
+ console.log(data,"147852")
|
|
|
+ this.$store.commit('updateConversationList', data)
|
|
|
+ })
|
|
|
+ .catch(({ errCode, errMsg }) => {
|
|
|
+ // 调用失败
|
|
|
})
|
|
|
- })
|
|
|
- this.messageContent = ''
|
|
|
},
|
|
|
sendCustomMessage() {
|
|
|
if (
|
|
@@ -670,7 +812,20 @@ export default {
|
|
|
followId:this.$store.state.conversation.followId,
|
|
|
orderType:this.$store.state.conversation.orderType
|
|
|
}
|
|
|
- const message = this.tim.createCustomMessage({
|
|
|
+ const customMessageData = {
|
|
|
+ data:this.form.data,
|
|
|
+ description: this.form.description,
|
|
|
+ extension: this.form.extension
|
|
|
+ }
|
|
|
+ console.log("customMessageData",customMessageData)
|
|
|
+ this.OpenIM.createCustomMessage(customMessageData)
|
|
|
+ .then(({ data }) => {
|
|
|
+ // 调用成功
|
|
|
+ })
|
|
|
+ .catch(({ errCode, errMsg }) => {
|
|
|
+ // 调用失败
|
|
|
+ });
|
|
|
+ /*const message = this.OpenIM.createCustomMessage({
|
|
|
cloudCustomData:JSON.stringify(customData),
|
|
|
to: this.toAccount,
|
|
|
conversationType: this.currentConversationType,
|
|
@@ -679,9 +834,9 @@ export default {
|
|
|
description: this.form.description,
|
|
|
extension: this.form.extension
|
|
|
}
|
|
|
- })
|
|
|
+ })*/
|
|
|
this.$store.commit('pushCurrentMessageList', message)
|
|
|
- this.tim.sendMessage(message).catch(error => {
|
|
|
+ this.OpenIM.sendMessage(message).catch(error => {
|
|
|
this.$store.commit('showMessage', {
|
|
|
type: 'error',
|
|
|
message: error.message
|
|
@@ -705,7 +860,8 @@ export default {
|
|
|
followId:this.$store.state.conversation.followId,
|
|
|
orderType:this.$store.state.conversation.orderType
|
|
|
}
|
|
|
- const message = this.tim.createCustomMessage({
|
|
|
+ console.log("创建自定义消息")
|
|
|
+ const message = this.OpenIM.createCustomMessage({
|
|
|
cloudCustomData:JSON.stringify(customData),
|
|
|
to: this.toAccount,
|
|
|
conversationType: this.currentConversationType,
|
|
@@ -721,9 +877,10 @@ export default {
|
|
|
description: '',
|
|
|
extension: ''
|
|
|
})
|
|
|
- this.tim
|
|
|
+ this.OpenIM
|
|
|
.sendMessage(message)
|
|
|
.then(() => {
|
|
|
+ console.log("发送自定义消息")
|
|
|
Object.assign(this, {
|
|
|
rate: 5,
|
|
|
suggestion: ''
|
|
@@ -738,7 +895,9 @@ export default {
|
|
|
this.surveyDialogVisible = false
|
|
|
},
|
|
|
chooseEmoji(item) {
|
|
|
- this.messageContent += item
|
|
|
+ const emojiChar = this.emojiCharMap[item] || item;
|
|
|
+ console.log("emojiChar",emojiChar)
|
|
|
+ this.messageContent += emojiChar;
|
|
|
},
|
|
|
handleSendImageClick() {
|
|
|
this.$refs.imagePicker.click()
|
|
@@ -756,102 +915,224 @@ export default {
|
|
|
})
|
|
|
this.$bus.$emit('open-group-live', { channel: 1 })
|
|
|
},
|
|
|
- sendImage() {
|
|
|
- var customData={
|
|
|
- type:this.$store.state.conversation.type,
|
|
|
- imType:this.$store.state.conversation.imType,
|
|
|
- orderId:this.$store.state.conversation.orderId,
|
|
|
- followId:this.$store.state.conversation.followId,
|
|
|
- orderType:this.$store.state.conversation.orderType
|
|
|
- }
|
|
|
- const message = this.tim.createImageMessage({
|
|
|
- cloudCustomData:JSON.stringify(customData),
|
|
|
- to: this.toAccount,
|
|
|
- conversationType: this.currentConversationType,
|
|
|
- payload: {
|
|
|
- file: document.getElementById('imagePicker') // 或者用event.target
|
|
|
- },
|
|
|
- onProgress: percent => {
|
|
|
- this.$set(message, 'progress', percent) // 手动给message 实例加个响应式属性: progress
|
|
|
- }
|
|
|
+ generateUUID() {
|
|
|
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
|
+ var r = (Math.random() * 16) | 0,
|
|
|
+ v = c == 'x' ? r : (r & 0x3) | 0x8
|
|
|
+ return v.toString(16)
|
|
|
})
|
|
|
- this.$store.commit('pushCurrentMessageList', message)
|
|
|
- this.tim
|
|
|
- .sendMessage(message)
|
|
|
- .then(() => {
|
|
|
- this.$refs.imagePicker.value = null
|
|
|
- })
|
|
|
- .catch(imError => {
|
|
|
- this.$store.commit('showMessage', {
|
|
|
- message: imError.message,
|
|
|
- type: 'error'
|
|
|
+ },
|
|
|
+ sendImage() {
|
|
|
+ const input = document.getElementById('imagePicker');
|
|
|
+ const imageFile = input?.files?.[0];
|
|
|
+ if (!imageFile) return;
|
|
|
+
|
|
|
+ const picBaseInfo = {
|
|
|
+ uuid: this.generateUUID(),
|
|
|
+ type: imageFile.type,
|
|
|
+ size: imageFile.size,
|
|
|
+ width: 0,
|
|
|
+ height: 0,
|
|
|
+ url: '',
|
|
|
+ };
|
|
|
+
|
|
|
+ const setImageDimensions = (file, callback) => {
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onload = (e) => {
|
|
|
+ const img = new Image();
|
|
|
+ img.onload = () => {
|
|
|
+ callback({ width: img.width, height: img.height });
|
|
|
+ };
|
|
|
+ img.src = e.target.result;
|
|
|
+ };
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ };
|
|
|
+
|
|
|
+ setImageDimensions(imageFile, ({ width, height }) => {
|
|
|
+ // 创建图片对象
|
|
|
+ const updatedPicInfo = {
|
|
|
+ ...picBaseInfo,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ };
|
|
|
+
|
|
|
+ const messageData = {
|
|
|
+ sourcePicture: { ...updatedPicInfo },
|
|
|
+ bigPicture: { ...updatedPicInfo },
|
|
|
+ snapshotPicture: { ...updatedPicInfo },
|
|
|
+ file: imageFile,
|
|
|
+ sourcePath: imageFile.name,
|
|
|
+ onProgress: percent => {
|
|
|
+ this.$set(updatedPicInfo, 'progress', percent);
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ this.OpenIM.createImageMessageByFile(messageData)
|
|
|
+ .then(({ data: message }) => {
|
|
|
+ const isGroup = this.currentConversationType === 3;
|
|
|
+ return this.OpenIM.sendMessage({
|
|
|
+ message,
|
|
|
+ recvID: isGroup ? '' : this.$store.getters.toAccount,
|
|
|
+ groupID: isGroup ? this.$store.getters.toAccount : '',
|
|
|
+ offlinePushInfo : {
|
|
|
+ title:message.senderNickname,
|
|
|
+ desc:"[图片]",
|
|
|
+ iOSPushSound:"",
|
|
|
+ iOSBadgeCount:true,
|
|
|
+ operatorUserID:"",
|
|
|
+ ex:""
|
|
|
+ }
|
|
|
+ });
|
|
|
})
|
|
|
- })
|
|
|
+ .then(({ data }) => {
|
|
|
+ console.log('发送图片成功', data);
|
|
|
+ const msgList = Array.isArray(data) ? data : [data];
|
|
|
+ this.$store.commit('pushCurrentMessageList', msgList);
|
|
|
+ this.updateConversationList()
|
|
|
+ this.$bus.$emit('scroll-bottom');
|
|
|
+ this.$refs.imagePicker.value = null;
|
|
|
+ })
|
|
|
+ .catch(({ errCode, errMsg }) => {
|
|
|
+ console.error('发送图片失败', errCode, errMsg);
|
|
|
+ this.$store.commit('showMessage', {
|
|
|
+ message: errMsg,
|
|
|
+ type: 'error',
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
+
|
|
|
sendFile() {
|
|
|
- var customData={
|
|
|
- type:this.$store.state.conversation.type,
|
|
|
- imType:this.$store.state.conversation.imType,
|
|
|
- orderId:this.$store.state.conversation.orderId,
|
|
|
- followId:this.$store.state.conversation.followId,
|
|
|
- orderType:this.$store.state.conversation.orderType
|
|
|
- }
|
|
|
- const message = this.tim.createFileMessage({
|
|
|
- cloudCustomData:JSON.stringify(customData),
|
|
|
- to: this.toAccount,
|
|
|
- conversationType: this.currentConversationType,
|
|
|
- payload: {
|
|
|
- file: document.getElementById('filePicker') // 或者用event.target
|
|
|
- },
|
|
|
+ const input = document.getElementById('filePicker');
|
|
|
+ const file = input.files[0];
|
|
|
+ if (!file) return;
|
|
|
+
|
|
|
+ const customData = {
|
|
|
+ type: this.$store.state.conversation.type,
|
|
|
+ imType: this.$store.state.conversation.imType,
|
|
|
+ orderId: this.$store.state.conversation.orderId,
|
|
|
+ followId: this.$store.state.conversation.followId,
|
|
|
+ orderType: this.$store.state.conversation.orderType
|
|
|
+ };
|
|
|
+
|
|
|
+ // 1. 创建文件消息
|
|
|
+ this.OpenIM.createFileMessageByFile({
|
|
|
+ filePath: file.name,
|
|
|
+ fileName: file.name,
|
|
|
+ uuid: this.generateUUID(),
|
|
|
+ sourceUrl: '',
|
|
|
+ fileSize: file.size,
|
|
|
+ fileType: file.type,
|
|
|
+ file,
|
|
|
+ cloudCustomData: JSON.stringify(customData),
|
|
|
onProgress: percent => {
|
|
|
- this.$set(message, 'progress', percent) // 手动给message 实例加个响应式属性: progress
|
|
|
+ this.$set(file, 'progress', percent);
|
|
|
}
|
|
|
- })
|
|
|
- this.$store.commit('pushCurrentMessageList', message)
|
|
|
- this.tim
|
|
|
- .sendMessage(message)
|
|
|
- .then(() => {
|
|
|
- this.$refs.filePicker.value = null
|
|
|
- })
|
|
|
- .catch(imError => {
|
|
|
- this.$store.commit('showMessage', {
|
|
|
- message: imError.message,
|
|
|
- type: 'error'
|
|
|
- })
|
|
|
- })
|
|
|
+ }).then(({ data }) => {
|
|
|
+ // 2. 发送文件消息
|
|
|
+ const sendFile = {
|
|
|
+ message: data,
|
|
|
+ recvID: this.$store.getters.toAccount,
|
|
|
+ groupID: this.currentConversationType === 3 ? this.toAccount : "",
|
|
|
+ offlinePushInfo : {
|
|
|
+ title:data.senderNickname,
|
|
|
+ desc:"[文件]",
|
|
|
+ iOSPushSound:"",
|
|
|
+ iOSBadgeCount:true,
|
|
|
+ operatorUserID:"",
|
|
|
+ ex:""
|
|
|
+ }
|
|
|
+ };
|
|
|
+ console.error("创建文件消息返回", data);
|
|
|
+ console.error("发送文件消息参数", sendFile);
|
|
|
+ return this.OpenIM.sendMessage(sendFile);
|
|
|
+ }).then(({ data }) => {
|
|
|
+ const msgList = Array.isArray(data) ? data : [data];
|
|
|
+ this.$store.commit('pushCurrentMessageList', msgList);
|
|
|
+ this.updateConversationList()
|
|
|
+ this.$bus.$emit('scroll-bottom');
|
|
|
+ this.$refs.filePicker.value = null;
|
|
|
+ }).catch(({ errCode, errMsg }) => {
|
|
|
+ console.error("发送文件失败", errCode, errMsg);
|
|
|
+ this.$store.commit('showMessage', {
|
|
|
+ message: errMsg,
|
|
|
+ type: 'error'
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
sendVideo() {
|
|
|
- var customData={
|
|
|
- type:this.$store.state.conversation.type,
|
|
|
- imType:this.$store.state.conversation.imType,
|
|
|
- orderId:this.$store.state.conversation.orderId,
|
|
|
- followId:this.$store.state.conversation.followId,
|
|
|
- orderType:this.$store.state.conversation.orderType
|
|
|
- }
|
|
|
- const message = this.tim.createVideoMessage({
|
|
|
- cloudCustomData:JSON.stringify(customData),
|
|
|
- to: this.toAccount,
|
|
|
- conversationType: this.currentConversationType,
|
|
|
- payload: {
|
|
|
- file: document.getElementById('videoPicker') // 或者用event.target
|
|
|
- },
|
|
|
- onProgress: percent => {
|
|
|
- this.$set(message, 'progress', percent) // 手动给message 实例加个响应式属性: progress
|
|
|
- }
|
|
|
- })
|
|
|
- this.$store.commit('pushCurrentMessageList', message)
|
|
|
- this.tim
|
|
|
- .sendMessage(message)
|
|
|
- .then(() => {
|
|
|
- this.$refs.videoPicker.value = null
|
|
|
- })
|
|
|
- .catch(imError => {
|
|
|
- this.$store.commit('showMessage', {
|
|
|
- message: imError.message,
|
|
|
- type: 'error'
|
|
|
- })
|
|
|
- })
|
|
|
+ const videoInput = document.getElementById('videoPicker');
|
|
|
+ const file = videoInput.files[0];
|
|
|
+ if (!file) return;
|
|
|
+
|
|
|
+ const snapshotFile = new File([new Blob()], 'snapshot.png', { type: 'image/png' });
|
|
|
+
|
|
|
+ const customData = {
|
|
|
+ type: this.$store.state.conversation.type,
|
|
|
+ imType: this.$store.state.conversation.imType,
|
|
|
+ orderId: this.$store.state.conversation.orderId,
|
|
|
+ followId: this.$store.state.conversation.followId,
|
|
|
+ orderType: this.$store.state.conversation.orderType,
|
|
|
+ };
|
|
|
+
|
|
|
+ const videoURL = URL.createObjectURL(file);
|
|
|
+ const video = document.createElement('video');
|
|
|
+ video.preload = 'metadata';
|
|
|
+ video.src = videoURL;
|
|
|
+
|
|
|
+ video.onloadedmetadata = () => {
|
|
|
+ URL.revokeObjectURL(videoURL); // 清理临时URL
|
|
|
+ const duration = Math.ceil(video.duration); // 视频时长,取整
|
|
|
+
|
|
|
+ // 创建视频消息
|
|
|
+ this.OpenIM.createVideoMessageByFile({
|
|
|
+ cloudCustomData: JSON.stringify(customData),
|
|
|
+ videoPath: file.name,
|
|
|
+ duration,
|
|
|
+ videoType: file.type,
|
|
|
+ snapshotPath: snapshotFile.name,
|
|
|
+ videoUUID: '',
|
|
|
+ videoUrl: '',
|
|
|
+ videoSize: file.size,
|
|
|
+ snapshotUUID: '',
|
|
|
+ snapshotSize: snapshotFile.size,
|
|
|
+ snapshotUrl: '',
|
|
|
+ snapshotWidth: 1024,
|
|
|
+ snapshotHeight: 1024,
|
|
|
+ snapShotType: snapshotFile.type,
|
|
|
+ videoFile: file,
|
|
|
+ snapshotFile,
|
|
|
+ onProgress: percent => {
|
|
|
+ this.$set(this, 'videoProgress', percent);
|
|
|
+ }
|
|
|
+ }).then(({ data }) => {
|
|
|
+ const sendVideo = {
|
|
|
+ message: data,
|
|
|
+ recvID: this.$store.getters.toAccount,
|
|
|
+ groupID: this.currentConversationType === 3 ? this.toAccount : "",
|
|
|
+ offlinePushInfo : {
|
|
|
+ title:data.senderNickname,
|
|
|
+ desc:"[视频]",
|
|
|
+ iOSPushSound:"",
|
|
|
+ iOSBadgeCount:true,
|
|
|
+ operatorUserID:"",
|
|
|
+ ex:""
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ this.OpenIM.sendMessage(sendVideo).then(({ data }) => {
|
|
|
+ const msgList = Array.isArray(data) ? data : [data];
|
|
|
+ this.$store.commit('pushCurrentMessageList', msgList);
|
|
|
+ this.updateConversationList()
|
|
|
+ this.$bus.$emit('scroll-bottom');
|
|
|
+ this.$refs.videoPicker.value = null;
|
|
|
+ }).catch(({ errCode, errMsg }) => {
|
|
|
+ console.error("发送视频失败", errCode, errMsg);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
</script>
|