Commit 9ea0283f authored by chenqikuai's avatar chenqikuai

fix: 修复

parent a5adf7e1
export const TRANSFER_HUMAN_1 = '客服经理已接入会话,我们预计3分钟内联系您' export const TRANSFER_HUMAN_1 = '客服经理已接入会话,我们预计3分钟内联系您'
export const TRANSFER_HUMAN_2 = '客户已接入会话,请尽快联系客户' export const TRANSFER_HUMAN_2 = '客户已接入会话,请尽快联系客户'
\ No newline at end of file
export const CONST_START_CHAT = {
user: { id: '1', value: '客服经理已接入会话,我们预计3分钟内联系您' },
staff: { id: '2', value: '客户已接入会话,请尽快联系客户' },
}
export const CONST_END_CHAT = {
user: { id: '3', value: '会话已结束' },
staff: { id: '4', value: '会话已结束' },
}
export const CHAT_CONST_LIST = [CONST_START_CHAT, CONST_END_CHAT]
import { DisplayMessage } from '@/store/messagesStore' import { DisplayMessage } from '@/store/messagesStore'
import { ChatMessageTypes } from '@/types/chatMessageTypes'
import { eRole } from '@/types/roleType'
import ChatDataService from '@/utils/ChatDataService'
import { import {
getMasterIdFromDisplayMsg, getMasterIdFromDisplayMsg,
getTargetIdFromDisplayMsg, getTargetIdFromDisplayMsg,
} from '@/utils/chatutils' } from '@/utils/chatutils'
import { getUserMsg } from '@/utils/userMsg'
import { iChatListCard, MyAppDatabase } from './index' import { iChatListCard, MyAppDatabase } from './index'
export default class ChatListCardDB extends MyAppDatabase { export default class ChatListCardDB extends MyAppDatabase {
...@@ -72,7 +76,17 @@ export default class ChatListCardDB extends MyAppDatabase { ...@@ -72,7 +76,17 @@ export default class ChatListCardDB extends MyAppDatabase {
}) })
.first() .first()
const content = msg.content?.content || '[新消息]' let content: string
if (msg.type === ChatMessageTypes.Card) {
content =
ChatDataService.getInstance().extractCommonMsgContentFromMsg(
msg,
getUserMsg()?.role as eRole,
) || ''
} else {
content = msg.content?.content || '[新消息]'
}
const unreadMsgCount = cardItem?.unreadMsgCount || 0 const unreadMsgCount = cardItem?.unreadMsgCount || 0
this.updateCard( this.updateCard(
...@@ -90,13 +104,14 @@ export default class ChatListCardDB extends MyAppDatabase { ...@@ -90,13 +104,14 @@ export default class ChatListCardDB extends MyAppDatabase {
const content = data.msg.content?.content || '[新消息]' const content = data.msg.content?.content || '[新消息]'
const masterId = getMasterIdFromDisplayMsg(data.msg) const masterId = getMasterIdFromDisplayMsg(data.msg)
const targetId = getTargetIdFromDisplayMsg(data.msg) const targetId = getTargetIdFromDisplayMsg(data.msg)
console.log(data.msg, "in addNewCard"); console.log(data.msg, 'in addNewCard')
this.saveCard({ this.saveCard({
masterId, masterId,
targetId: targetId, targetId: targetId,
unreadMsgCount: data.isChattingWithTargetId ? 0 : 1, unreadMsgCount: data.isChattingWithTargetId ? 0 : 1,
content, content,
inChat: false,
}) })
} }
...@@ -109,4 +124,24 @@ export default class ChatListCardDB extends MyAppDatabase { ...@@ -109,4 +124,24 @@ export default class ChatListCardDB extends MyAppDatabase {
item.unreadMsgCount = 0 item.unreadMsgCount = 0
}) })
} }
setChatStatus(masterId: string, targetId: string, isChat: boolean) {
return this.chatListCard
.filter((item) => {
return item.targetId === targetId && item.masterId === masterId
})
.modify((item) => {
item.inChat = isChat
})
}
async getChatStatus(masterId: string, targetId: string) {
const ret = await this.chatListCard
.filter((item) => {
return item.targetId === targetId && item.masterId === masterId
})
.first()
return ret?.inChat
}
} }
...@@ -11,6 +11,7 @@ export interface iChatListCard { ...@@ -11,6 +11,7 @@ export interface iChatListCard {
targetId: string targetId: string
unreadMsgCount: number unreadMsgCount: number
content: string content: string
inChat: boolean // 会话状态,会话中?
} }
export class MyAppDatabase extends Dexie { export class MyAppDatabase extends Dexie {
...@@ -25,12 +26,11 @@ export class MyAppDatabase extends Dexie { ...@@ -25,12 +26,11 @@ export class MyAppDatabase extends Dexie {
this.version(1.2).stores({ this.version(1.2).stores({
chatMessage: chatMessage:
'++id, content, from, uuid, state, uploadProgress, type, datetime, hideDatetime, logid, masterId, readed', '++id, content, from, uuid, state, uploadProgress, type, datetime, hideDatetime, logid, masterId, readed',
chatListCard: '++id, masterId, targetId, unreadMsgCount, content', chatListCard: '++id, masterId, targetId, unreadMsgCount, content, inChat',
contactPerson: '++id, addr, bank, phone, user_name', contactPerson: '++id, addr, bank, phone, user_name',
userInfo: '++id, created_at, phone, remark, user_name, uuid, addr', userInfo: '++id, created_at, phone, remark, user_name, uuid, addr',
}) })
this.chatMessage = this.table('chatMessage') this.chatMessage = this.table('chatMessage')
this.chatListCard = this.table('chatListCard') this.chatListCard = this.table('chatListCard')
this.contactPerson = this.table('contactPerson') this.contactPerson = this.table('contactPerson')
......
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
import { MessageContent } from '@/types/chat-message' import { MessageContent } from '@/types/chat-message'
import { reactive, Ref, ref } from '@vue/reactivity' import { reactive, Ref, ref } from '@vue/reactivity'
import { import { target as __target, getFromId } from '@/store/appCallerStore'
target as __target,
getFromId
} from '@/store/appCallerStore'
import { ChatMessageTypes } from '@/types/chatMessageTypes' import { ChatMessageTypes } from '@/types/chatMessageTypes'
import encodeChatMessage from '@/utils/fzm-message-protocol-chat/encodeChatMessage' import encodeChatMessage from '@/utils/fzm-message-protocol-chat/encodeChatMessage'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
...@@ -26,6 +23,8 @@ import { ...@@ -26,6 +23,8 @@ import {
getTargetIdFromDisplayMsg, getTargetIdFromDisplayMsg,
} from '@/utils/chatutils' } from '@/utils/chatutils'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import ChatListCardDB from '@/db/ChatListCardDB'
import { CONST_END_CHAT, CONST_START_CHAT } from '@/config/chat'
/** 多媒体消息的上传进度 */ /** 多媒体消息的上传进度 */
export interface UploadProgress { export interface UploadProgress {
...@@ -116,7 +115,6 @@ class MessageStore { ...@@ -116,7 +115,6 @@ class MessageStore {
target: string target: string
uuid?: string uuid?: string
}) { }) {
const _uuid = uuid || uuidv4() const _uuid = uuid || uuidv4()
/** 聊天界面显示的消息 */ /** 聊天界面显示的消息 */
...@@ -189,17 +187,17 @@ class MessageStore { ...@@ -189,17 +187,17 @@ class MessageStore {
} }
// 文本类消息,不需要上传 OSS,直接发送 // 文本类消息,不需要上传 OSS,直接发送
else { else {
ChatDBService.getInstance().handleEveryReceive({ ChatDBService.getInstance().handleEveryReceive({
msg: message, msg: message,
masterId: getMasterIdFromDisplayMsg(message), masterId: getMasterIdFromDisplayMsg(message),
isChattingWithTargetId: isChattingWith( isChattingWithTargetId: isChattingWith(
getMasterIdFromDisplayMsg(message), getMasterIdFromDisplayMsg(message),
getTargetIdFromDisplayMsg(message), getTargetIdFromDisplayMsg(message),
target target,
), ),
}).then(()=>{
this.send(type, content, _uuid, message, target as string)
}) })
this.send(type, content, _uuid, message, target as string)
} }
} }
...@@ -228,11 +226,8 @@ class MessageStore { ...@@ -228,11 +226,8 @@ class MessageStore {
// hideDatetime: false, // hideDatetime: false,
// logid: record.log_id, // logid: record.log_id,
// } // }
// if (this.isMessageDuplicated(message)) return // if (this.isMessageDuplicated(message)) return
// this.messages.unshift(message) // this.messages.unshift(message)
// // 新插入的消息和下面那条消息比较时间,小于两分钟就隐藏下面那条消息的时间 // // 新插入的消息和下面那条消息比较时间,小于两分钟就隐藏下面那条消息的时间
// const underMessage = this.messages[1] // const underMessage = this.messages[1]
// if (underMessage) { // if (underMessage) {
...@@ -307,6 +302,23 @@ class MessageStore { ...@@ -307,6 +302,23 @@ class MessageStore {
}, },
{ state: message.state }, { state: message.state },
) )
if (type === ChatMessageTypes.Card) {
if (content.bank === CONST_START_CHAT.user.id)
ChatListCardDB.getInstance().setChatStatus(
getFromId() as string,
target,
true,
)
else if (content.bank === CONST_END_CHAT.user.id) {
ChatListCardDB.getInstance().setChatStatus(
getFromId() as string,
target,
false,
)
}
}
/* 存数据库...... */ /* 存数据库...... */
}) })
.catch(() => { .catch(() => {
......
import { CHAT_CONST_LIST } from '@/config/chat'
import { DisplayMessage } from '@/store/messagesStore'
import { eRole } from '@/types/roleType'
export default class ChatDataService {
static instance: ChatDataService
static getInstance() {
if (!ChatDataService.instance)
ChatDataService.instance = new ChatDataService()
return ChatDataService.instance
}
extractCommonMsgContentFromMsg(msg: DisplayMessage, role: eRole) {
const userId = msg.content.bank
const CONST = CHAT_CONST_LIST.find((i) => i.user.id === userId)
return eRole.user === role ? CONST?.user.value : CONST?.staff.value
}
}
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
/> />
<ChatOptionItemVue :selected="false" value="电话联系" @click="handleClickCall" /> <ChatOptionItemVue :selected="false" value="电话联系" @click="handleClickCall" />
</ChatOption> </ChatOption>
<ChatInputVue /> <ChatInputVue :serviceShowValue="serviceShowValue"/>
<CommonUseSentence <CommonUseSentence
class="transition-all h-0" class="transition-all h-0"
:class="{ 'h-40': showShortSentences }" :class="{ 'h-40': showShortSentences }"
...@@ -54,7 +54,7 @@ import { useRoute } from "vue-router"; ...@@ -54,7 +54,7 @@ import { useRoute } from "vue-router";
import { queryFaqAnswer, queryFaqList } from "@/service/FaqService"; import { queryFaqAnswer, queryFaqList } from "@/service/FaqService";
import { getDisplayNamesFromAddress, getMsgFromAddress } from "@/utils/displayName"; import { getDisplayNamesFromAddress, getMsgFromAddress } from "@/utils/displayName";
import { MessageContent } from "@/types/chat-message"; import { MessageContent } from "@/types/chat-message";
import { TRANSFER_HUMAN_1, TRANSFER_HUMAN_2 } from "@/config/chat"; import { CONST_END_CHAT, CONST_START_CHAT } from "@/config/chat";
import ChatOptionItemVue from "@/components/ChatOptions/ChatOptionItem.vue"; import ChatOptionItemVue from "@/components/ChatOptions/ChatOptionItem.vue";
import ShowCall from "@/components/showCall/index.vue" import ShowCall from "@/components/showCall/index.vue"
import { getUserMsg } from "@/utils/userMsg"; import { getUserMsg } from "@/utils/userMsg";
...@@ -102,8 +102,8 @@ export default defineComponent({ ...@@ -102,8 +102,8 @@ export default defineComponent({
sendChatMessage({ sendChatMessage({
type: ChatMessageTypes.Card, type: ChatMessageTypes.Card,
content: { content: {
bank: TRANSFER_HUMAN_1, bank: CONST_START_CHAT.user.id,
name: TRANSFER_HUMAN_2, name: CONST_START_CHAT.staff.id,
account: '', account: '',
} as MessageContent } as MessageContent
}) })
...@@ -113,14 +113,20 @@ export default defineComponent({ ...@@ -113,14 +113,20 @@ export default defineComponent({
sendChatMessage({ sendChatMessage({
type: ChatMessageTypes.Card, type: ChatMessageTypes.Card,
content: { content: {
bank: '本次服务已结束', bank: CONST_END_CHAT.user.id,
name: '本次服务已结束', name: CONST_END_CHAT.staff.id,
account: '', account: '',
} as MessageContent } as MessageContent
}) })
// showServiceRating.value = true; // showServiceRating.value = true;
} }
} }
onMounted(async () => {
const inChat = await ChatListCardDB.getInstance().getChatStatus(getFromId() as string, target)
serviceShowValue.value = inChat ? '结束服务' : '人工服务'
})
const initError = ref(false); const initError = ref(false);
const showServiceRating = ref(false); const showServiceRating = ref(false);
......
<template> <template>
<div class="w-full rounded-md font-medium flex items-center"> <div class="w-full rounded-md font-medium flex items-center">
<div class="flex-grow border-b mr-1 ml-2"></div> <div class="flex-grow border-b mr-1 ml-2"></div>
<div class="text-center" v-if="isUser">{{ content?.bank }}</div> <div class="text-center" v-if="isUser">{{ sentence?.user.value }}</div>
<div class="text-center" v-else>{{ content?.name }}</div> <div class="text-center" v-else>{{ sentence?.staff.value }}</div>
<div class="flex-grow border-b ml-1 mr-2"></div> <div class="flex-grow border-b ml-1 mr-2"></div>
</div> </div>
</template> </template>
...@@ -12,15 +12,21 @@ import { defineComponent, PropType } from 'vue' ...@@ -12,15 +12,21 @@ import { defineComponent, PropType } from 'vue'
import iconUrl from '@/assets/message_bank_card.png' import iconUrl from '@/assets/message_bank_card.png'
import { getUserMsg } from '@/utils/userMsg' import { getUserMsg } from '@/utils/userMsg'
import { eRole } from '@/types/roleType' import { eRole } from '@/types/roleType'
import { CHAT_CONST_LIST } from '@/config/chat'
export default defineComponent({ export default defineComponent({
props: { props: {
fromMyself: Boolean, fromMyself: Boolean,
content: Object as PropType<{ bank: string, name: string, account: string }> content: {
required: true,
type: Object as PropType<{ bank: string, name: string, account: string }>,
}
}, },
setup() { setup(props) {
const isUser = getUserMsg()?.role === eRole.user const isUser = getUserMsg()?.role === eRole.user
return { iconUrl, isUser } const sentence = CHAT_CONST_LIST.find(i => i.user.id === props?.content.bank)
return { iconUrl, isUser, sentence, CHAT_CONST_LIST }
}, },
}) })
</script> </script>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<ChatInputTextVue <ChatInputTextVue
v-if="inputType === 1" v-if="inputType === 1"
@send="sendChatMessage" @send="handleSend"
@click="showMenu = false" @click="showMenu = false"
class="pl-5" class="pl-5"
/> />
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<!-- 有输入文字,显示 `发送` 按钮 --> <!-- 有输入文字,显示 `发送` 按钮 -->
<button <button
v-else v-else
@click="inputText.trim().length !== 0 && sendChatMessage({ type: 1, content: { content: inputText } })" @click="inputText.trim().length !== 0 && handleSend()"
class="mx-2.5 px-4 py-1.5 flex items-center rounded-md text-center select-none focus:outline-none text-app-white" class="mx-2.5 px-4 py-1.5 flex items-center rounded-md text-center select-none focus:outline-none text-app-white"
style="background: rgb(7, 193, 99)" style="background: rgb(7, 193, 99)"
>发送</button> >发送</button>
...@@ -51,13 +51,16 @@ import { MessageContent } from "@/types/chat-message"; ...@@ -51,13 +51,16 @@ import { MessageContent } from "@/types/chat-message";
import ChatInputTextVue from "./ChatInputText.vue"; import ChatInputTextVue from "./ChatInputText.vue";
import ChatInputAlbumVue from "./ChatInputAlbum.vue"; import ChatInputAlbumVue from "./ChatInputAlbum.vue";
import ChatInputCameraVue from "./ChatInputCamera.vue"; import ChatInputCameraVue from "./ChatInputCamera.vue";
import { target } from "@/store/appCallerStore"; import { getFromId, target } from "@/store/appCallerStore";
// import { from } from "@/store/appCallerStore";
import { textInputStore } from "@/store/textInputStore"; import { textInputStore } from "@/store/textInputStore";
import { v4 as uuidv4 } from 'uuid'
import Icon from "@/components/common/Icon.vue"; import Icon from "@/components/common/Icon.vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
export default defineComponent({ export default defineComponent({
props: {
serviceShowValue: String,
},
components: { components: {
ChatInputTextVue, ChatInputTextVue,
ChatInputAlbumVue, ChatInputAlbumVue,
...@@ -65,7 +68,7 @@ export default defineComponent({ ...@@ -65,7 +68,7 @@ export default defineComponent({
Icon, Icon,
}, },
setup() { setup(props) {
const route = useRoute(); const route = useRoute();
const enum InputType { const enum InputType {
text = 1, text = 1,
...@@ -108,11 +111,33 @@ export default defineComponent({ ...@@ -108,11 +111,33 @@ export default defineComponent({
// } // }
// }) // })
const handleSend = () => {
console.log('handle send');
if (props.serviceShowValue === "人工服务") {
messageStore.displayNewMessage({
content: {
content: inputText.value
},
from: getFromId() as string,
target: target,
uuid: uuidv4(),
state: 'success',
datetime: new Date().getTime(),
type: ChatMessageTypes.robot,
})
textInputStore.clearTextMessage();
} else {
sendChatMessage({ type: 1, content: { content: inputText.value } })
}
}
return { return {
inputType, inputType,
inputText, inputText,
showMenu, showMenu,
sendChatMessage, sendChatMessage,
handleSend
// showReceiptInput, // showReceiptInput,
}; };
}, },
......
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