Commit e3e0d44c authored by CHENQIKUAI's avatar CHENQIKUAI

新增名称

parent 9a2b89f8
地址 对应的 用户信息会变吗? 是否会变将影响着前端是否存储相关数据以及存储有效期长度
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="flex justify-between mt-5"> <div class="flex justify-between mt-5">
<div <div
class="id whitespace-nowrap overflow-hidden overflow-ellipsis flex-grow flex-shrink" class="id whitespace-nowrap overflow-hidden overflow-ellipsis flex-grow flex-shrink"
>{{ id }}</div> >{{ displayName }}</div>
<div <div
class="txt whitespace-nowrap overflow-hidden overflow-ellipsis flex-shrink-0" class="txt whitespace-nowrap overflow-hidden overflow-ellipsis flex-shrink-0"
>{{ latest_msg_timeStamp && timestampFormat(latest_msg_timeStamp) }}</div> >{{ latest_msg_timeStamp && timestampFormat(latest_msg_timeStamp) }}</div>
...@@ -39,6 +39,7 @@ const props = defineProps({ ...@@ -39,6 +39,7 @@ const props = defineProps({
type: Number, type: Number,
default: 10 default: 10
}, },
displayName: String,
}) })
</script> </script>
......
import { iContact } from '@/service/UserService/types'
import { MyAppDatabase } from './index'
export default class ContactPersonService {
static instance: ContactPersonService
private contactPerson: Dexie.Table<iContact, number>
static getInstance() {
if (!ContactPersonService.instance) {
ContactPersonService.instance = new ContactPersonService()
}
return ContactPersonService.instance
}
constructor() {
const db = new MyAppDatabase()
this.contactPerson = db.contactPerson
}
save(list: iContact[]) {
return this.contactPerson.bulkAdd(list)
}
async findByList(addressList: string[]) {
const list = await this.contactPerson
.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 Dexie from 'dexie'
import { DisplayMessage } from '@/store/messagesStore' import { DisplayMessage } from '@/store/messagesStore'
import { iContact } from '@/service/UserService/types'
export interface iChatMessage extends DisplayMessage { export interface iChatMessage extends DisplayMessage {
masterId: string masterId: string
...@@ -15,6 +16,7 @@ export interface iChatListCard { ...@@ -15,6 +16,7 @@ export interface iChatListCard {
export class MyAppDatabase extends Dexie { export class MyAppDatabase extends Dexie {
chatMessage: Dexie.Table<iChatMessage, number> chatMessage: Dexie.Table<iChatMessage, number>
chatListCard: Dexie.Table<iChatListCard, number> chatListCard: Dexie.Table<iChatListCard, number>
contactPerson: Dexie.Table<iContact, number>
constructor() { constructor() {
super('MyAppDatabase') super('MyAppDatabase')
...@@ -23,9 +25,11 @@ export class MyAppDatabase extends Dexie { ...@@ -23,9 +25,11 @@ export class MyAppDatabase extends Dexie {
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',
contactPerson: '++id, addr, bank, phone, user_name',
}) })
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')
} }
} }
...@@ -18,10 +18,14 @@ class UserService { ...@@ -18,10 +18,14 @@ class UserService {
} }
staffInfo(data: { addrs: string[] }) { staffInfo(data: { addrs: string[] }) {
return baseAxios({ return baseAxios<{ total: number; item: iContact[] }>({
url: '/user/staff_info', url: '/user/staff_info',
method: 'get', method: 'get',
params: data, params: data,
paramsSerializer: (data: { addrs: string[] }) => {
console.log(data);
return `addrs=${data.addrs.toString()}`
},
}) })
} }
} }
......
import ContactPersonService from '@/db/ContactPersonService'
import UserService from '@/service/UserService'
import { iContact } from '@/service/UserService/types'
export const getDisplayNamesFromAddress = async (
addressList: string[],
): Promise<string[]> => {
/* 数据库查 有结果拿 没结果网上查且存 */
const {
foundList,
notFoundList,
} = await ContactPersonService.getInstance().findByList(addressList)
const fullList = foundList
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)
}
}
return addressList.map((item) => {
return fullList.find((i) => i?.addr === item)?.user_name || '未知用户'
})
}
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, nextTick, onMounted, watch } from "vue"; import { defineComponent, nextTick, onMounted, watch } from "vue";
import { target , getFromId} from "@/store/appCallerStore"; import { target, getFromId } from "@/store/appCallerStore";
import { DisplayMessage, messageStore } from "@/store/messagesStore"; import { DisplayMessage, messageStore } from "@/store/messagesStore";
import useScrollTo from "@/composables/useScrollTo"; import useScrollTo from "@/composables/useScrollTo";
import ChatContentMessageVue from "./ChatContentMessage.vue"; import ChatContentMessageVue from "./ChatContentMessage.vue";
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
:class="{ 'text-right': fromMyself }" :class="{ 'text-right': fromMyself }"
style="font-size: 12px;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #adadad; style="font-size: 12px;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #adadad;
" "
>15990184793</div> >159903</div>
<div <div
:class="[{ 'flex-row-reverse': fromMyself }]" :class="[{ 'flex-row-reverse': fromMyself }]"
class="flex items-center max-w-chat-msg-bubble" class="flex items-center max-w-chat-msg-bubble"
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<ChatListItem <ChatListItem
:unReadMsgNum="item.unreadMsgCount" :unReadMsgNum="item.unreadMsgCount"
:id="item.targetId" :id="item.targetId"
:displayName="item.displayName"
:latest_msg_content="item.content" :latest_msg_content="item.content"
></ChatListItem> ></ChatListItem>
</template> </template>
...@@ -24,7 +25,10 @@ ...@@ -24,7 +25,10 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="isChatListEmpty" class="empty text-center fixed w-full top-1/2 transform -translate-y-1/2 -mt-6"> <div
v-if="isChatListEmpty"
class="empty text-center fixed w-full top-1/2 transform -translate-y-1/2 -mt-6"
>
<img src="@/assets/img/empty.png" class="mb-5" alt /> <img src="@/assets/img/empty.png" class="mb-5" alt />
<div class="no-chat mb-2.5">暂无聊天</div> <div class="no-chat mb-2.5">暂无聊天</div>
<div v-if="userType === eRole.user" class="tip">咨询客户经理后,可以在这里快捷查看消息哦!</div> <div v-if="userType === eRole.user" class="tip">咨询客户经理后,可以在这里快捷查看消息哦!</div>
...@@ -43,15 +47,25 @@ import { getUserMsg } from "@/utils/userMsg"; ...@@ -43,15 +47,25 @@ import { getUserMsg } from "@/utils/userMsg";
import { eRole } from "@/types/roleType"; import { eRole } from "@/types/roleType";
import ChatMessageDB from "@/db/ChatMessageDB"; import ChatMessageDB from "@/db/ChatMessageDB";
import router from "@/router"; import router from "@/router";
import UserService from "@/service/UserService";
import { getDisplayNamesFromAddress } from "@/utils/displayName";
const cardList = ref<iChatListCard[]>([]); const cardList = ref<(iChatListCard & { displayName?: string })[]>([]);
const showList = ref<boolean[]>([]); const showList = ref<boolean[]>([]);
const selectedIndex = ref<number>() const selectedIndex = ref<number>()
const renderList = async () => { const renderList = async () => {
const list = await ChatListCardDB.getInstance().getCardList(getFromId() as string) const list = await ChatListCardDB.getInstance().getCardList(getFromId() as string)
const addressList = list.map(i => i.targetId);
cardList.value = list; cardList.value = list;
const displayNames = await getDisplayNamesFromAddress(addressList)
cardList.value = list.map((item, index) => {
return {
...item,
displayName: displayNames[index]
}
})
} }
onMounted(async () => { onMounted(async () => {
......
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