Skip to content

Commit

Permalink
fix: scrollbar caton pause, close #35 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
l1m2e committed Mar 21, 2023
1 parent 9a47bc7 commit 391839d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/components/Session/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ const { uuid } = storeToRefs(useSettingsStore())
const { sessionDataList } = storeToRefs(useSessionStore())
const { currentRole } = storeToRefs(useRoleStore())
/** 自动滚动到底部 */
const sessionElement = ref<HTMLDivElement | null>(null)
const scrollHeight = ref<number | undefined>(0)
const autoscrollBottom = () => {
if (scrollHeight.value !== sessionElement.value?.scrollHeight) {
sessionElement.value?.scroll({
top: sessionElement.value.scrollHeight,
behavior: 'smooth'
})
scrollHeight.value = sessionElement.value?.scrollHeight
}
}
const localTime = (time: string) =>
dayjs.utc(time).local().format('YYYY-MM-DD HH:mm:ss')
watchEffect(() => {
if (!sessionElement.value) return
if (sessionDataList.value.at(-1)?.message?.content) {
sessionElement.value.scrollTo({
top: sessionElement.value.offsetHeight
})
}
onUpdated(() => {
autoscrollBottom()
})
</script>

Expand Down

0 comments on commit 391839d

Please sign in to comment.