【解决todo】AI Chat stream 增加默认头像

This commit is contained in:
cherishsince
2024-05-22 10:58:54 +08:00
parent 431ae7b01b
commit 4466c5b4ec
2 changed files with 11 additions and 3 deletions

View File

@ -109,6 +109,7 @@ const conversationInProgress = ref(false) // 对话进行中
const conversationInAbortController = ref<any>() // 对话进行中 abort 控制器(控制 stream 对话)
const inputTimeout = ref<any>() // 处理输入中回车的定时器
const prompt = ref<string>() // prompt
const userInfo = ref<ProfileVO>() // 用户信息
const fullText = ref('');
const displayedText = ref('');
@ -124,6 +125,9 @@ const listLoadingTime = ref<any>() // time定时器如果加载速度很快
const messageRef = ref()
const isComposing = ref(false) // 判断用户是否在输入
// 默认 role 头像
const defaultRoleAvatar = 'http://test.yudao.iocoder.cn/eaef5f41acb911dd718429a0702dcc3c61160d16e57ba1d543132fab58934f9f.png'
// =========== 自提滚动效果
const textRoll = async () => {
@ -300,6 +304,7 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
conversationId: activeConversationId.value,
type: 'user',
content: userMessage.content,
userAvatar: userInfo.value?.avatar,
createTime: new Date()
} as ChatMessageVO)
list.value.push({
@ -307,6 +312,7 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
conversationId: activeConversationId.value,
type: 'system',
content: '思考中...',
roleAvatar: defaultRoleAvatar,
createTime: new Date()
} as ChatMessageVO)
// 滚动到最下面
@ -388,12 +394,11 @@ const getMessageList = async () => {
// 获取列表数据
const messageListRes = await ChatMessageApi.messageList(activeConversationId.value)
// 设置用户头像
const user = await getUserProfile()
messageListRes.map(item => {
item.userAvatar = user?.avatar
// 设置 role 默认头像
item.roleAvatar = item.roleAvatar ? item.roleAvatar : defaultRoleAvatar
})
list.value = messageListRes
console.log("设置头像成功", messageListRes)
// 滚动到最下面
await nextTick(() => {
// 滚动到最后
@ -524,6 +529,8 @@ onMounted(async () => {
// 获取列表数据
listLoading.value = true
await getMessageList()
// 获取用户信息
userInfo.value = await getUserProfile()
})
</script>