1
1
<script setup lang="ts">
2
2
import MarkdownIt from ' markdown-it'
3
3
import MarkdownItHighlight from ' markdown-it-highlightjs'
4
- import { IconImage } from ' @arco-design/web-vue/es/icon'
4
+ import { IconImage , IconCaretUp } from ' @arco-design/web-vue/es/icon'
5
5
import dayjs from ' dayjs'
6
6
import utc from ' dayjs/plugin/utc'
7
7
import { copyText , copyCode , saveImage , saveMarkdown } from ' @/utils'
8
8
import { useSettingsStore , useSessionStore , useRoleStore } from ' @/stores'
9
+ import { listen } from ' @tauri-apps/api/event'
9
10
10
11
dayjs .extend (utc )
11
12
@@ -23,20 +24,45 @@ const getLocalTime = (time: string) =>
23
24
dayjs .utc (time ).local ().format (' YYYY-MM-DD HH:mm:ss' )
24
25
25
26
const sessionElement = ref <HTMLDivElement | null >(null )
27
+ const isAutoScroll = ref (true )
26
28
27
- /**
28
- * 自动滚动到底部
29
- */
30
- const autoScrollBottom = () => {
31
- if (! sessionElement .value ) return
29
+ /** 自动滚动到底部 */
30
+ const autoScroll = (isAuto = false ) => {
31
+ if (! sessionElement .value || ! isAutoScroll .value ) return
32
32
33
33
sessionElement .value .scroll ({
34
- top: sessionElement .value .scrollHeight
34
+ top: sessionElement .value .scrollHeight ,
35
+ behavior: isAuto ? ' smooth' : ' auto'
36
+ })
37
+ }
38
+
39
+ onMounted (() => {
40
+ listen (' scroll-to-bottom' , () => {
41
+ isAutoScroll .value = true
42
+ autoScroll (true )
35
43
})
44
+ })
45
+
46
+ // 用户滚轮操作滚动条
47
+ const handleWheel = (event : WheelEvent ) => {
48
+ if (event .deltaY < 0 ) {
49
+ isAutoScroll .value = false
50
+ }
51
+ }
52
+
53
+ // 监听消息页面滚动
54
+ const handleScroll = () => {
55
+ if (! sessionElement .value ) return
56
+
57
+ const { scrollTop, clientHeight, scrollHeight } = sessionElement .value
58
+
59
+ if (Math .ceil (scrollTop + clientHeight ) >= scrollHeight ) {
60
+ isAutoScroll .value = true
61
+ }
36
62
}
37
63
38
64
onUpdated (() => {
39
- autoScrollBottom ()
65
+ autoScroll ()
40
66
})
41
67
</script >
42
68
@@ -45,6 +71,8 @@ onUpdated(() => {
45
71
ref =" sessionElement"
46
72
id =" session-list"
47
73
class =" relative flex-1 cursor-default overflow-auto"
74
+ @scroll =" handleScroll"
75
+ @wheel =" handleWheel"
48
76
>
49
77
<template v-if =" sessionDataList .length " >
50
78
<div
@@ -109,6 +137,18 @@ onUpdated(() => {
109
137
110
138
<!-- 当前无会话 -->
111
139
<NoSession v-else />
140
+
141
+ <a-back-top
142
+ @click =" isAutoScroll = false"
143
+ target-container =" #session-list"
144
+ class =" bottom-[114px]"
145
+ >
146
+ <a-button type =" primary" shape =" circle" >
147
+ <template #icon >
148
+ <IconCaretUp />
149
+ </template >
150
+ </a-button >
151
+ </a-back-top >
112
152
</div >
113
153
</template >
114
154
0 commit comments