Commit 2582fd23 authored by xhx's avatar xhx

Merge branch 'dev' of https://gitlab.33.cn/chenqikuai/fns_front_2 into dev

parents bd003f2b f1ef057b
<template>
<van-config-provider :theme-vars="themeVars">
<van-config-provider :theme-vars="{ skeletonRowBackgroundColor: '#bfbfbf', }">
<div id="nav" class="bg-app-bg min-h-screen">
<router-view />
</div>
......@@ -124,9 +124,6 @@ export default defineComponent({
connectionState.connection?.disconnect();
});
return {
themeVars: {
skeletonRowBackgroundColor: '#bfbfbf',
},
}
}
})
......
import { DisplayMessage, messageStore } from '@/store/messagesStore'
import { getTargetIdFromDisplayMsg } from '@/utils/chatutils'
import { MyAppDatabase } from './index'
export default class ChatMessageDB extends MyAppDatabase {
......@@ -28,11 +29,32 @@ export default class ChatMessageDB extends MyAppDatabase {
})
}
deleteMsg({ uuid, logid }: { uuid?: string; logid?: string }) {
async deleteMsg({ uuid, logid }: { uuid?: string; logid?: string }) {
const updateChatList = async (masterId: string, target: string) => {
const latestedMsg = await this.getLatestedMessage(masterId, target)
if (latestedMsg) {
/* 如果和target还有聊天消息 */
// latestedMsg.content.content
this.chatListCard
.filter((i) => i.masterId === masterId && i.targetId === target)
.modify((i) => (i.content = latestedMsg.content.content as string))
} else {
/* 如果和target没有聊天消息 */
this.chatListCard
.filter((i) => i.masterId === masterId && i.targetId === target)
.modify((i) => (i.content = ''))
}
}
if (uuid) {
return this.chatMessage.where('uuid').equals(uuid).delete()
const item = await this.chatMessage.where('uuid').equals(uuid).first()
await this.chatMessage.where('uuid').equals(uuid).delete()
item && updateChatList(item?.masterId, getTargetIdFromDisplayMsg(item))
} else if (logid) {
return this.chatMessage.where('logid').equals(logid).delete()
const item = await this.chatMessage.where('logid').equals(logid).first()
await this.chatMessage.where('logid').equals(logid).delete()
item && updateChatList(item?.masterId, getTargetIdFromDisplayMsg(item))
} else {
throw new Error('没有uuid或者logid')
}
......@@ -63,6 +85,30 @@ export default class ChatMessageDB extends MyAppDatabase {
.toArray()
}
/* wo获取和ta之间最新的消息 */
async getLatestedMessage(from: string, target: string) {
const ret = await this.chatMessage
.filter((item) => {
return (
item.masterId === from &&
((item.state === null && target === item.from) ||
(item.state !== null && target === item.target))
)
})
.count()
console.log(ret, 'show count')
return this.chatMessage
.filter((item) => {
return (
item.masterId === from &&
((item.state === null && target === item.from) ||
(item.state !== null && target === item.target))
)
})
.last()
}
deleteMsgGroup(masterId: string, targetId: string) {
this.chatMessage
.filter((item) => {
......
import { iUserinfo } from '@/service/UserService/types'
import { MyAppDatabase } from './index'
export default class UserInfoDBService {
static instance: UserInfoDBService
private userInfo: Dexie.Table<iUserinfo, number>
static getInstance() {
if (!UserInfoDBService.instance) {
UserInfoDBService.instance = new UserInfoDBService()
}
return UserInfoDBService.instance
}
constructor() {
const db = new MyAppDatabase()
this.userInfo = db.userInfo
}
save(list: iUserinfo[]) {
return this.userInfo.bulkAdd(list)
}
async findByList(addressList: string[]) {
const list = await this.userInfo
.filter((i) => {
return addressList.includes(i.addr)
})
.toArray()
const notFoundList = addressList.filter(
(i) => list.findIndex((item) => item?.addr === i) === -1,
)
return {
foundList: list,
notFoundList,
}
}
}
import Dexie from 'dexie'
import { DisplayMessage } from '@/store/messagesStore'
import { iContact } from '@/service/UserService/types'
import { iContact, iUserinfo } from '@/service/UserService/types'
export interface iChatMessage extends DisplayMessage {
masterId: string
masterId: string // 这条消息展示在谁的页面上
}
export interface iChatListCard {
......@@ -17,19 +17,23 @@ export class MyAppDatabase extends Dexie {
chatMessage: Dexie.Table<iChatMessage, number>
chatListCard: Dexie.Table<iChatListCard, number>
contactPerson: Dexie.Table<iContact, number>
userInfo: Dexie.Table<iUserinfo, number>
constructor() {
super('MyAppDatabase')
this.version(1).stores({
this.version(1.2).stores({
chatMessage:
'++id, content, from, uuid, state, uploadProgress, type, datetime, hideDatetime, logid, masterId, readed',
chatListCard: '++id, masterId, targetId, unreadMsgCount, content',
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')
this.userInfo = this.table('userInfo')
}
}
import baseAxios from '../index'
import { iContact } from './types'
import { iContact, iUserinfo } from './types'
class UserService {
static instance: UserService
static getInstance() {
......@@ -23,7 +23,19 @@ class UserService {
method: 'get',
params: data,
paramsSerializer: (data: { addrs: string[] }) => {
console.log(data);
console.log(data)
return `addrs=${data.addrs.toString()}`
},
})
}
userInfo(data: { addrs: string[] }) {
return baseAxios<iUserinfo[]>({
url: '/user/user_info',
method: 'get',
params: data,
paramsSerializer: (data: { addrs: string[] }) => {
console.log(data)
return `addrs=${data.addrs.toString()}`
},
})
......
......@@ -4,3 +4,12 @@ export interface iContact {
phone: string
user_name: string
}
export interface iUserinfo {
addr: string
created_at: number
phone: string
remark: string
user_name: string
uuid: string
}
import ContactPersonService from '@/db/ContactPersonService'
import UserInfoDBService from '@/db/UserInfoService'
import UserService from '@/service/UserService'
import { iContact } from '@/service/UserService/types'
import { eRole } from '@/types/roleType'
import { getUserMsg } from './userMsg'
export const getDisplayNamesFromAddress = async (
addressList: string[],
): Promise<string[]> => {
/* 数据库查 有结果拿 没结果网上查且存 */
const user = getUserMsg()
const {
foundList,
notFoundList,
} = await ContactPersonService.getInstance().findByList(addressList)
let foundList = [] as any[]
let notFoundList = [] as any[]
const fullList = foundList
if (user?.role === eRole.user) {
const ret = await ContactPersonService.getInstance().findByList(addressList)
foundList = ret.foundList
notFoundList = ret.notFoundList
} else if (user?.role === eRole.staff) {
const ret = await UserInfoDBService.getInstance().findByList(addressList)
foundList = ret.foundList
notFoundList = ret.notFoundList
}
const fullList = (foundList as unknown) as any
if (notFoundList.length !== 0) {
const ret = await UserService.getInstance().staffInfo({
addrs: notFoundList,
})
if (ret.code === 200) {
const theoseNotFoundList = ret.data.item
ContactPersonService.getInstance().save(theoseNotFoundList)
fullList.push(...theoseNotFoundList)
if (user?.role === eRole.user) {
const ret = await UserService.getInstance().staffInfo({
addrs: notFoundList,
})
if (ret.code === 200) {
const theoseNotFoundList = ret.data.item
ContactPersonService.getInstance().save(theoseNotFoundList)
fullList.push(...theoseNotFoundList)
}
} else if (user?.role === eRole.staff) {
const ret = await UserService.getInstance().userInfo({
addrs: notFoundList,
})
if (ret.code === 200) {
const theoseNotFoundList = ret.data
UserInfoDBService.getInstance().save(theoseNotFoundList)
fullList.push(...theoseNotFoundList)
}
}
}
return addressList.map((item) => {
return fullList.find((i) => i?.addr === item)?.user_name || '未知用户'
const msg = fullList.find((i: any) => i?.addr === item)
return msg?.user_name || msg?.phone
})
}
......@@ -69,6 +69,8 @@ export default defineComponent({
const optionList = [
{ name: '常用问题', id: 1 },
{ name: '人工服务', id: 2 },
{ name: '电话咨询', id: 3 },
];
const setShowSentences = (show: boolean) =>
......@@ -92,6 +94,10 @@ export default defineComponent({
} else {
setShowSentences(false)
}
if (selectedChatOption.value === 3) {
}
})
const useSentence = (content: string) => {
......@@ -150,8 +156,6 @@ export default defineComponent({
})
return {
connectionState,
selected,
......
......@@ -12,11 +12,7 @@
<!-- 消息气泡 -->
<div :class="[{ 'flex-row-reverse': fromMyself }]">
<div
:class="{ 'text-right': fromMyself }"
style="font-size: 12px;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #adadad;
"
></div>
<div :class="{ 'text-right': fromMyself }" class="message_"></div>
<div
:class="[{ 'flex-row-reverse': fromMyself }]"
class="flex items-center max-w-chat-msg-bubble"
......@@ -157,7 +153,7 @@ export default defineComponent({
const textMsgActions = [
{
text: '删除', cb(data: { content: any, uuid: string, logid?: string }) {
text: '删除', cb(data: { content: any, uuid: string, logid?: string, }) {
ChatMessageDB.getInstance().deleteMsg({ uuid: data.uuid, logid: data.logid });
const index = messageStore.messages.findIndex(i => {
return i.uuid === data.uuid
......@@ -201,4 +197,12 @@ export default defineComponent({
},
});
</script>
\ No newline at end of file
</script>
<style scoped>
.message_ {
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
color: #adadad;
font-weight: 400;
}
</style>
\ No newline at end of file
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