1
0
forked from Leaf/amber-ui

改进 底部判断

This commit is contained in:
Twilight 2024-09-16 21:08:27 +08:00
parent f4e5ffeb7a
commit 0f97ab5bfa
3 changed files with 25 additions and 4 deletions

View File

@ -6,7 +6,7 @@
class="flex-grow mt-3 mb-1 text-5xl select-none"
v-if="!chatMessages?.length"
>
<n-gradient-text type="info" class="pr-3 pb-2 pt-2">
<n-gradient-text type="success" class="pr-3 pb-2 pt-2">
你好{{ userStore.user.name }}
</n-gradient-text>
<br />
@ -22,7 +22,7 @@
<div
class="fixed bottom-0 left-0 right-0"
:class="onBottom ? 'hidden' : 'mb-6'"
:class="!appStore.contentScrollOnBottom ? 'hidden' : 'mb-6'"
>
<!-- <div
class="mx-auto w-2xl max-w-2xl text-center mb-3 animate__animated animate__pulse text-lg"
@ -129,7 +129,7 @@
<n-text
depth="3"
class="text-center block mt-2 mb-2 text-sm select-none"
v-show="onBottom"
v-show="appStore.contentScrollOnBottom"
>
AI 也有可能犯错误请在使用之前核查信息
</n-text>
@ -158,6 +158,7 @@ import { useChatStore } from "@/stores/chat";
import router from "@/router";
import element from "@/config/element";
import { useIsMobile } from "@/utils/composables";
import { useAppStore } from "@/stores/app";
// chatId
const chatId: Ref<string | number | undefined | null> = ref(null);
@ -192,7 +193,7 @@ const processing = ref(false);
const fileUpload = ref();
const uploading = ref(false);
const autoScroll = ref(true);
const onBottom = ref(false);
const appStore = useAppStore()
function onKeydown(e: KeyboardEvent) {
// shift

View File

@ -6,9 +6,11 @@ import router from "../router";
import Header from "./Header.vue";
import element from "@/config/element";
import { useIsMobile } from "@/utils/composables";
import { useAppStore } from "@/stores/app";
const currentRoute = computed(() => router.currentRoute.value.name);
const userStore = useUserStore();
const appStore = useAppStore();
const route = useRoute();
const isMobile = useIsMobile();
@ -18,6 +20,20 @@ const mainContainer = ref();
onMounted(() => {
element.mainContainer = mainContainer.value;
});
const onScroll = (e: Event) => {
//
const target = e.target as HTMLElement;
const scrollTop = target.scrollTop;
const scrollHeight = target.scrollHeight;
const clientHeight = target.clientHeight;
appStore.contentScrollHeight = scrollHeight;
appStore.contentScrollOnBottom = scrollTop + clientHeight >= scrollHeight
//
appStore.contentScrollPosition = scrollTop;
}
</script>
<template>
@ -37,6 +53,7 @@ onMounted(() => {
position="absolute"
:style="userStore.logined ? 'margin-top: var(--header-height)' : ''"
ref="mainContainer"
:on-scroll="onScroll"
>
<!-- <n-layout-sider
v-if="userStore.logined && !isMobile"

View File

@ -5,5 +5,8 @@ export const useAppStore = defineStore("app", {
persist: false,
state: () => ({
updating: false,
contentScrollHeight: 0,
contentScrollPosition: 0,
contentScrollOnBottom: false,
}),
});