Commit 95964f25 authored by yaya's avatar yaya

聊天消息添加时间展示

parent f0098244
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
* Created by jiachenpan on 16/11/18. * Created by jiachenpan on 16/11/18.
*/ */
export function genID(length = 15) {
return Number(Math.random().toString().substr(3, length) + Date.now()).toString(36)
}
export function parseTime(time, cFormat) { export function parseTime(time, cFormat) {
if (arguments.length === 0) { if (arguments.length === 0) {
return null return null
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
<div class="hash" /> <div class="hash" />
</div> </div>
<div class="chat-message-input"> <div class="chat-message-input">
<el-input v-model="messageContent" :rows="4" type="textarea" placeholder="请输入聊天内容" style="border: none" /> <el-input v-model="messageContent" :rows="4" type="textarea" placeholder="请输入聊天内容" style="border: none" @keyup.enter.native="sendMessage"/>
<div class="chat-message-input__send"> <div class="chat-message-input__send">
<el-button :disabled="sendDisabled" type="primary" @click="sendMessage">发送</el-button> <el-button :disabled="sendDisabled" type="primary" @click="sendMessage">发送</el-button>
</div> </div>
...@@ -76,8 +76,8 @@ ...@@ -76,8 +76,8 @@
</div> </div>
</el-main> </el-main>
<el-aside style="width: 25%;background-color: white;padding: 10px"> <el-aside style="width: 25%;background-color: white;padding: 10px">
<div v-if="chatUserInfo && chatUserInfo.user" class="info-title">对话信息</div> <div v-if="chatUserInfo && chatUserInfo.aiAssistant" class="info-title">对话信息</div>
<ChatUserInfo v-if="chatUserInfo && chatUserInfo.user" :chat-user-info="chatUserInfo"/> <ChatUserInfo v-if="chatUserInfo && chatUserInfo.aiAssistant" :chat-user-info="chatUserInfo"/>
</el-aside> </el-aside>
</el-container> </el-container>
</div> </div>
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
import { getUserSig, getUserList, sendChatMsg, findChatUserInfo, setHumanIntervene, stopHumanIntervene } from '@/api/business/chat' import { getUserSig, getUserList, sendChatMsg, findChatUserInfo, setHumanIntervene, stopHumanIntervene } from '@/api/business/chat'
import chat from '@/utils/chat' import chat from '@/utils/chat'
import { formatTime, parseTime } from '@/utils/index' import { formatTime, parseTime, genID } from '@/utils/index'
import TencentCloudChat from '@tencentcloud/chat' import TencentCloudChat from '@tencentcloud/chat'
import ChatMessageItem from './components/chatMessageItem' import ChatMessageItem from './components/chatMessageItem'
import store from '../../store' import store from '../../store'
...@@ -333,10 +333,8 @@ export default { ...@@ -333,10 +333,8 @@ export default {
*/ */
handleImLoin(userId, userSign) { handleImLoin(userId, userSign) {
console.log('====用户信息===', userId, userSign) // 登录成功 console.log('====用户信息===', userId, userSign) // 登录成功
this.closeLoading()
const promise = chat.login({ userID: this.envText + userId, userSig: userSign }) const promise = chat.login({ userID: this.envText + userId, userSig: userSign })
promise.then((imResponse) => { promise.then((imResponse) => {
this.closeLoading()
console.log('====登录成功===', imResponse.data) // 登录成功 console.log('====登录成功===', imResponse.data) // 登录成功
chat.on(TencentCloudChat.EVENT.SDK_READY, this.onSdkReady) chat.on(TencentCloudChat.EVENT.SDK_READY, this.onSdkReady)
chat.on(TencentCloudChat.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, this.onTotalUnreadMessageCountUpdated) chat.on(TencentCloudChat.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, this.onTotalUnreadMessageCountUpdated)
...@@ -379,7 +377,9 @@ export default { ...@@ -379,7 +377,9 @@ export default {
fromUserId: message.from, fromUserId: message.from,
toAccount: message.to, toAccount: message.to,
avatar: message.avatar, avatar: message.avatar,
msgType: message.from === this.envText + userID ? 1 : 2 msgType: message.from === this.envText + userID ? 1 : 2,
time: parseTime(message.time),
reqId: this.handleGetReqId(message.cloudCustomData)
} }
this.messageList.push(object) this.messageList.push(object)
...@@ -406,6 +406,18 @@ export default { ...@@ -406,6 +406,18 @@ export default {
}*/ }*/
}) })
}, },
handleGetReqId(jsonStr) {
if (jsonStr) {
const jsonObj = JSON.parse(jsonStr)
if (jsonObj && jsonObj.reqId) {
return jsonObj.reqId
} else {
return genID()
}
} else {
return genID()
}
},
/** /**
* 会话未读总数变更通知 * 会话未读总数变更通知
...@@ -423,7 +435,9 @@ export default { ...@@ -423,7 +435,9 @@ export default {
// 全量的会话列表,用该列表覆盖原有的会话列表 // 全量的会话列表,用该列表覆盖原有的会话列表
const conversationList = imResponse.data.conversationList const conversationList = imResponse.data.conversationList
this.setConversationList(conversationList) this.setConversationList(conversationList)
this.closeLoading()
}).catch((imError) => { }).catch((imError) => {
this.closeLoading()
// 获取会话列表失败的相关信息 // 获取会话列表失败的相关信息
console.warn('getConversationList error:', imError) console.warn('getConversationList error:', imError)
}) })
...@@ -432,6 +446,7 @@ export default { ...@@ -432,6 +446,7 @@ export default {
* 会话列表更改监听 * 会话列表更改监听
* */ * */
onConversationListUpdated(event) { onConversationListUpdated(event) {
this.closeLoading()
console.log('====会话列表更新--', event.data) // 包含 Conversation 实例的数组 console.log('====会话列表更新--', event.data) // 包含 Conversation 实例的数组
this.setConversationList(event.data) this.setConversationList(event.data)
if (this.currentConversationItem && this.currentConversationItem.conversationID) { if (this.currentConversationItem && this.currentConversationItem.conversationID) {
...@@ -524,7 +539,8 @@ export default { ...@@ -524,7 +539,8 @@ export default {
toAccount: item.to, toAccount: item.to,
avatar: item.avatar, avatar: item.avatar,
msgType: item.from === this.envText + userID ? 1 : 2, msgType: item.from === this.envText + userID ? 1 : 2,
time: parseTime(item.time) time: parseTime(item.time),
reqId: this.handleGetReqId(item.cloudCustomData)
} }
topList.push(object) topList.push(object)
}) })
...@@ -560,13 +576,19 @@ export default { ...@@ -560,13 +576,19 @@ export default {
* 发送消息 * 发送消息
* */ * */
sendMessage() { sendMessage() {
let reqId = genID()
if (this.messageList && this.messageList.length > 0) {
reqId = this.messageList[this.messageList.length - 1].reqId || genID()
}
const params = { const params = {
fromAccount: this.customerList[this.currentCustomerIndex].code, fromAccount: this.customerList[this.currentCustomerIndex].code,
toAccount: this.currentConversationItem.fromAccount, toAccount: this.currentConversationItem.fromAccount,
isRealPersonAnswer: 1, isRealPersonAnswer: 1,
msgType: 1, msgType: 1,
realPersonId: this.userId, realPersonId: this.userId,
msgContent: this.messageContent msgContent: this.messageContent,
reqId: reqId
} }
sendChatMsg(params).then(response => { sendChatMsg(params).then(response => {
const object = { const object = {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<div class="filter-container"> <div class="filter-container">
<el-date-picker <el-date-picker
v-model="value2" v-model="value2"
:picker-options="pickerOptions"
size="mini" size="mini"
class="filter-item" class="filter-item"
style="width: 400px; " style="width: 400px; "
...@@ -68,6 +69,11 @@ export default { ...@@ -68,6 +69,11 @@ export default {
}, },
value2: '', value2: '',
messageList: [], messageList: [],
pickerOptions: {
disabledDate(date) {
return date.getTime() > Date.now() // 禁用大于今天的日期
}
},
isHasNextPage: false isHasNextPage: false
} }
}, },
...@@ -110,7 +116,8 @@ export default { ...@@ -110,7 +116,8 @@ export default {
fromUserId: item.fromAccount, fromUserId: item.fromAccount,
toAccount: item.toAccount, toAccount: item.toAccount,
avatar: item.fromAccountIcon, avatar: item.fromAccountIcon,
msgType: item.fromAccount === this.toAccount ? 1 : 2 msgType: item.fromAccount === this.toAccount ? 1 : 2,
time: item.msgTime
} }
list.push(messageItem) list.push(messageItem)
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment