feat(chat): 聊天标题显示昵称(客户→昵称,群→群名,替代原始ID)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-15 10:54:21 +08:00
parent edd6a27371
commit 661ecfc8c9
2 changed files with 40 additions and 4 deletions
+2
View File
@@ -40,6 +40,7 @@ export interface CustomerQuery {
page?: number
page_size?: number
owner_account_id?: string
friend_id?: string
user_id?: string
department_id?: string
add_time_since?: number
@@ -54,6 +55,7 @@ export function getCustomers(query: CustomerQuery = {}): Promise<Page<Customer>>
page_size: query.page_size ?? 20,
channel: query.channel === 'all' ? undefined : query.channel,
owner_account_id: query.owner_account_id,
friend_id: query.friend_id,
user_id: query.user_id,
department_id: query.department_id,
add_time_since: query.add_time_since,
+38 -4
View File
@@ -3,7 +3,7 @@ import { computed, nextTick, onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { ArrowLeft } from '@element-plus/icons-vue'
import { getMessages } from '@/api'
import { getCustomers, getGroups, getMessages } from '@/api'
import { downloadBlob } from '@/api/client'
import type { Channel, Message } from '@/api/types'
import MessageBubble from '@/components/MessageBubble.vue'
@@ -68,12 +68,42 @@ const visibleMessages = computed(() => {
return messages.value.filter((m) => (m.text ?? '').includes(k))
})
/** 当前会话对方的显示名(客户昵称或群名)— fetch 后替换标题中的原始 ID。 */
const talkerName = ref<string | null>(null)
async function loadTalkerName(): Promise<void> {
talkerName.value = null
if (!hasActive.value) return
try {
if (isGroup.value && props.roomId) {
// 群名
const res = await getGroups({ channel: channelTyped.value, owner_account_id: props.ownerId, page: 1, page_size: 200 })
const g = res.items.find(g => g.room_id === props.roomId)
talkerName.value = g?.room_name || null
} else if (props.talkerId) {
// 客户昵称
const res = await getCustomers({
channel: channelTyped.value,
owner_account_id: props.ownerId,
friend_id: props.talkerId,
page: 1,
page_size: 1,
})
const c = res.items[0]
talkerName.value = c?.friend_nickname || c?.friend_remark || null
}
} catch {
// 静默降级:显示原始 ID
}
}
const conversationTitle = computed(() => {
const displayName = talkerName.value || (isGroup.value ? props.roomId : props.talkerId)
if (isGroup.value) {
return `群聊记录 · ${props.roomId}`
return `群聊记录 · ${displayName}`
}
if (props.talkerId) {
return `与 ${props.talkerId} 的聊天记录`
return `与 ${displayName} 的聊天记录`
}
// 账号级入口(无具体会话):仅展示渠道级标题,避免出现 "与 undefined 的聊天记录"。
return '聊天记录'
@@ -272,10 +302,14 @@ watch(
() => [props.channel, props.ownerId, props.talkerId, props.roomId] as const,
() => {
loadInitial()
loadTalkerName()
},
)
onMounted(loadInitial)
onMounted(() => {
loadInitial()
loadTalkerName()
})
</script>
<template>