diff --git a/yunkes/src/api/index.ts b/yunkes/src/api/index.ts index 4c4924c..04d9419 100644 --- a/yunkes/src/api/index.ts +++ b/yunkes/src/api/index.ts @@ -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_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, diff --git a/yunkes/src/views/ChatTimeline.vue b/yunkes/src/views/ChatTimeline.vue index 26d7acf..38474b6 100644 --- a/yunkes/src/views/ChatTimeline.vue +++ b/yunkes/src/views/ChatTimeline.vue @@ -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(null) + +async function loadTalkerName(): Promise { + 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() +})