Commit 164941f0 authored by nick zheng's avatar nick zheng

Merge branch 'beta' into 'master'

Beta

See merge request !210
parents 28db76d1 1977fb61
...@@ -29,7 +29,7 @@ const emit = defineEmits<{ ...@@ -29,7 +29,7 @@ const emit = defineEmits<{
addAnswerMessageItem: [messageId: string, messageItem: MessageItemInterface, index: number] addAnswerMessageItem: [messageId: string, messageItem: MessageItemInterface, index: number]
updateMessageItem: [messageId: string, messageItem: Partial<MessageItemInterface>, index: number] updateMessageItem: [messageId: string, messageItem: Partial<MessageItemInterface>, index: number]
deleteMessageItem: [messageId: string, index: number] deleteMessageItem: [messageId: string, index: number]
messageListScrollToBottom: [] messageListScrollToBottom: [autoScrollBottom?: boolean]
clearAllMessage: [] clearAllMessage: []
}>() }>()
...@@ -69,14 +69,18 @@ const uploadFileIcon = (type: string) => { ...@@ -69,14 +69,18 @@ const uploadFileIcon = (type: string) => {
return `https://gsst-poe-sit.gz.bcebos.com/icon/${type}.svg` return `https://gsst-poe-sit.gz.bcebos.com/icon/${type}.svg`
} }
const messageListScrollToBottomThrottle = throttle(() => { const messageListScrollToBottomThrottle = throttle(
emit('messageListScrollToBottom') () => {
}, 300) emit('messageListScrollToBottom')
},
50,
{ leading: true, trailing: true },
)
watch( watch(
() => uploadImageList.value.length, () => uploadImageList.value.length,
() => { () => {
emit('messageListScrollToBottom') emit('messageListScrollToBottom', true)
}, },
) )
...@@ -123,7 +127,7 @@ function handleQuestionSubmit() { ...@@ -123,7 +127,7 @@ function handleQuestionSubmit() {
imageUrl: uploadImageList.value?.[0]?.url || '', imageUrl: uploadImageList.value?.[0]?.url || '',
}) })
emit('messageListScrollToBottom') emit('messageListScrollToBottom', true)
multiModelDialogueList.value.forEach((modelItem, modelIndex) => { multiModelDialogueList.value.forEach((modelItem, modelIndex) => {
const messages: QuestionMessageItem[] = [] const messages: QuestionMessageItem[] = []
...@@ -158,7 +162,10 @@ function handleQuestionSubmit() { ...@@ -158,7 +162,10 @@ function handleQuestionSubmit() {
{ ...messageItemFactory(), role: 'assistant', isTextContentLoading: true, isAnswerResponseLoading: true }, { ...messageItemFactory(), role: 'assistant', isTextContentLoading: true, isAnswerResponseLoading: true },
modelIndex, modelIndex,
) )
emit('messageListScrollToBottom')
setTimeout(() => {
emit('messageListScrollToBottom', true)
}, 200)
modelItem.controller = new AbortController() modelItem.controller = new AbortController()
...@@ -234,7 +241,10 @@ function handleQuestionSubmit() { ...@@ -234,7 +241,10 @@ function handleQuestionSubmit() {
modelItem.isAnswerResponseWait = false modelItem.isAnswerResponseWait = false
userStore.fetchUpdateEquityInfo() userStore.fetchUpdateEquityInfo()
emit('updateMessageItem', answerMessageId, { isAnswerResponseLoading: false }, modelIndex) emit('updateMessageItem', answerMessageId, { isAnswerResponseLoading: false }, modelIndex)
emit('messageListScrollToBottom')
setTimeout(() => {
emit('messageListScrollToBottom')
}, 100)
}, },
}) })
......
<script setup lang="ts"> <script setup lang="ts">
import { nextTick, useTemplateRef } from 'vue' import { useTemplateRef } from 'vue'
import { ScrollbarInst } from 'naive-ui' import { ScrollbarInst } from 'naive-ui'
import { useElementVisibility } from '@vueuse/core'
import MessageItem from './message-item.vue' import MessageItem from './message-item.vue'
import type { MessageItemInterface } from '../types' import type { MessageItemInterface } from '../types'
...@@ -14,25 +15,28 @@ const emit = defineEmits<{ ...@@ -14,25 +15,28 @@ const emit = defineEmits<{
showKnowledgeResult: [knowledgeContentResult: KnowledgeContentResultItem[]] showKnowledgeResult: [knowledgeContentResult: KnowledgeContentResultItem[]]
}>() }>()
defineExpose({
scrollToBottom,
})
const scrollbarRef = useTemplateRef<ScrollbarInst | null>('scrollbarRef') const scrollbarRef = useTemplateRef<ScrollbarInst | null>('scrollbarRef')
const backBottomBtnFlagRef = useTemplateRef<HTMLDivElement | null>('backBottomBtnFlagRef')
const isNotShowBackBottomBtn = useElementVisibility(backBottomBtnFlagRef)
function scrollToBottom() { function scrollToBottom() {
nextTick(() => { if (scrollbarRef.value) {
if (scrollbarRef.value) { scrollbarRef.value.scrollTo({ top: 999999999, behavior: 'smooth' })
scrollbarRef.value.scrollTo({ top: 999999999, behavior: 'smooth' }) }
}
})
} }
defineExpose({
scrollToBottom,
isNotShowBackBottomBtn,
})
</script> </script>
<template> <template>
<div class="relative flex-1 overflow-hidden overflow-y-auto py-[20px]"> <div class="relative flex-1 overflow-hidden overflow-y-auto py-[20px]">
<n-scrollbar ref="scrollbarRef" class="min-h-full" content-class="min-h-full flex"> <n-scrollbar ref="scrollbarRef" class="min-h-full" content-class="min-h-full flex">
<div class="flex flex-col-reverse overflow-hidden"> <div class="relative flex flex-col-reverse overflow-hidden">
<div class="pr-[10px]"> <div class="pr-[10px]">
<MessageItem <MessageItem
v-for="[key, messageItem] in messageList" v-for="[key, messageItem] in messageList"
...@@ -41,7 +45,37 @@ function scrollToBottom() { ...@@ -41,7 +45,37 @@ function scrollToBottom() {
@show-knowledge-result="emit('showKnowledgeResult', messageItem.knowledgeContentResult)" @show-knowledge-result="emit('showKnowledgeResult', messageItem.knowledgeContentResult)"
/> />
</div> </div>
<div ref="backBottomBtnFlagRef" class="-z-1 absolute bottom-0 h-[100px] w-full"></div>
</div> </div>
</n-scrollbar> </n-scrollbar>
<Transition name="back-bottom-btn" mode="out-in">
<div
v-show="!isNotShowBackBottomBtn"
class="absolute bottom-[30px] right-[30px] text-end"
style="translate: calc(-50% + 30px)"
>
<button
class="flex-center flex-center hover:text-theme-color inline-flex h-[26px] w-[26px] rounded-full border bg-white"
@click.stop="scrollToBottom"
>
<i class="iconfont icon-huidaodibu text-[12px]" />
</button>
</div>
</Transition>
</div> </div>
</template> </template>
<style lang="scss" scoped>
.back-bottom-btn-enter-active,
.back-bottom-btn-leave-active {
transition-timing-function: ease-in-out;
transition-duration: 0.2s;
transition-property: opacity;
}
.back-bottom-btn-enter-from,
.back-bottom-btn-leave-to {
opacity: 0;
}
</style>
...@@ -38,8 +38,13 @@ const modelDialogueRef = ref<HTMLElement | null>(null) ...@@ -38,8 +38,13 @@ const modelDialogueRef = ref<HTMLElement | null>(null)
const { height } = useElementSize(modelDialogueRef) const { height } = useElementSize(modelDialogueRef)
const isNotShowBackBottomBtn = computed(() => {
return messageListRef.value?.isNotShowBackBottomBtn || false
})
defineExpose({ defineExpose({
scrollToBottom, scrollToBottom,
isNotShowBackBottomBtn,
}) })
const isShowModelConfigMenu = ref(false) const isShowModelConfigMenu = ref(false)
......
...@@ -278,14 +278,16 @@ function handleClearAllMessage() { ...@@ -278,14 +278,16 @@ function handleClearAllMessage() {
} }
// 滚动页面 // 滚动页面
function handleMessageListScrollToBottom() { function handleMessageListScrollToBottom(autoScrollBottom?: boolean) {
if (modelDialogueListRef.value) { if (modelDialogueListRef.value) {
modelDialogueListRef.value.forEach((modelDialogueItemRef, index) => { modelDialogueListRef.value.forEach((modelDialogueItemRef, index) => {
if (!multiModelDialogueList.value?.[index]?.isAnswerResponseWait) { if (!multiModelDialogueList.value?.[index]?.isAnswerResponseWait) {
return return
} }
modelDialogueItemRef?.scrollToBottom && modelDialogueItemRef.scrollToBottom() if (modelDialogueItemRef?.scrollToBottom && (modelDialogueItemRef?.isNotShowBackBottomBtn || autoScrollBottom)) {
modelDialogueItemRef.scrollToBottom()
}
}) })
} }
} }
......
...@@ -80,10 +80,10 @@ function handleShowKnowledgeResult(knowledgeContentResult: KnowledgeContentResul ...@@ -80,10 +80,10 @@ function handleShowKnowledgeResult(knowledgeContentResult: KnowledgeContentResul
<div <div
v-show="visible" v-show="visible"
class="flex-center hover:text-theme-color absolute bottom-5 right-5 h-6 w-6 cursor-pointer rounded-full bg-white shadow-[0_0_0_1px_#ededed]" class="flex-center hover:text-theme-color absolute bottom-5 right-5 h-[26px] w-[26px] cursor-pointer rounded-full bg-white shadow-[0_0_0_1px_#ededed]"
@click.stop="clickBackBottom" @click.stop="clickBackBottom"
> >
<i class="iconfont icon-left rotate-270 text-sm" /> <i class="iconfont icon-huidaodibu text-[12px]" />
</div> </div>
<HitKnowledge <HitKnowledge
......
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