Commit 9ea0283f authored by chenqikuai's avatar chenqikuai

fix: 修复

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