Skip to content

Commit e4361d3

Browse files
authoredMar 23, 2023
fix: scrollbar caton pause, close #52 #42 (#71)
1 parent f7c4a84 commit e4361d3

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed
 

‎src/components/Function/index.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { useRoleStore, useSessionStore } from '@/stores'
1212
import { getAiMessage } from '@/api'
1313
import { saveImage } from '@/utils'
14+
import { emit } from '@tauri-apps/api/event'
1415
1516
const { currentRole } = storeToRefs(useRoleStore())
1617
@@ -80,14 +81,22 @@ const functions = computed(() => [
8081
handleClick: () => (modalVisible.value = true)
8182
}
8283
])
84+
85+
const triggerScroll = () => {
86+
emit('scroll-to-bottom')
87+
}
8388
</script>
8489

8590
<!-- TODO:把聊天对象移过来 -->
8691
<template>
8792
<div class="function text-6 relative flex justify-end">
8893
<!-- 当前聊天角色对象 -->
8994
<div class="top-50% left-50% text-4 -translate-1/2 absolute">
90-
正在与 <span class="mark">{{ currentRole?.name }}</span> 对话
95+
正在与
96+
<span class="mark cursor-pointer" @click="triggerScroll">{{
97+
currentRole?.name
98+
}}</span>
99+
对话
91100
</div>
92101

93102
<div class="flex gap-2">

‎src/components/Session/index.vue

+48-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script setup lang="ts">
22
import MarkdownIt from 'markdown-it'
33
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'
55
import dayjs from 'dayjs'
66
import utc from 'dayjs/plugin/utc'
77
import { copyText, copyCode, saveImage, saveMarkdown } from '@/utils'
88
import { useSettingsStore, useSessionStore, useRoleStore } from '@/stores'
9+
import { listen } from '@tauri-apps/api/event'
910
1011
dayjs.extend(utc)
1112
@@ -23,20 +24,45 @@ const getLocalTime = (time: string) =>
2324
dayjs.utc(time).local().format('YYYY-MM-DD HH:mm:ss')
2425
2526
const sessionElement = ref<HTMLDivElement | null>(null)
27+
const isAutoScroll = ref(true)
2628
27-
/**
28-
* 自动滚动到底部
29-
*/
30-
const autoScrollBottom = () => {
31-
if (!sessionElement.value) return
29+
/** 自动滚动到底部 */
30+
const autoScroll = (isAuto = false) => {
31+
if (!sessionElement.value || !isAutoScroll.value) return
3232
3333
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)
3543
})
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+
}
3662
}
3763
3864
onUpdated(() => {
39-
autoScrollBottom()
65+
autoScroll()
4066
})
4167
</script>
4268

@@ -45,6 +71,8 @@ onUpdated(() => {
4571
ref="sessionElement"
4672
id="session-list"
4773
class="relative flex-1 cursor-default overflow-auto"
74+
@scroll="handleScroll"
75+
@wheel="handleWheel"
4876
>
4977
<template v-if="sessionDataList.length">
5078
<div
@@ -109,6 +137,18 @@ onUpdated(() => {
109137

110138
<!-- 当前无会话 -->
111139
<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>
112152
</div>
113153
</template>
114154

‎src/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createApp } from 'vue'
22
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
33
import App from './App.vue'
44
import '@arco-design/web-vue/es/message/style/css.js'
5+
import '@arco-design/web-vue/es/back-top/style/css.js'
56
import 'uno.css'
67
import 'highlight.js/styles/github-dark-dimmed.css'
78
import '@kidonng/daisyui/index.css'

‎vite.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default defineConfig(async () => ({
2525
enabled: false
2626
},
2727
imports: ['vue', 'pinia'],
28-
resolvers: [ArcoResolver()]
28+
resolvers: [ArcoResolver()],
29+
vueTemplate: true
2930
}),
3031
Components({
3132
dts: './src/types/components.d.ts',

0 commit comments

Comments
 (0)
Please sign in to comment.