amber-ui/src/layouts/DefaultLayout.vue

105 lines
2.9 KiB
Vue
Raw Normal View History

2024-09-10 08:29:08 +00:00
<script setup lang="ts">
2024-09-13 01:07:34 +00:00
import { NLayout } from "naive-ui";
2024-10-10 03:27:36 +00:00
import { useUserStore } from "../stores/user";
2024-09-27 06:18:42 +00:00
// import Guest from "../pages/guest/index.vue";
// import router from "../router";
2024-09-12 05:49:24 +00:00
import Header from "./Header.vue";
import element from "@/config/element";
2024-09-27 06:20:50 +00:00
import { useIsMobile } from "@/utils/composables";
2024-09-16 13:08:27 +00:00
import { useAppStore } from "@/stores/app";
2024-10-10 03:27:36 +00:00
import ChatLayout from "@/components/chat/Layout.vue";
2024-09-27 06:18:42 +00:00
// const currentRoute = computed(() => router.currentRoute.value.name);
2024-09-10 08:29:08 +00:00
2024-10-10 03:27:36 +00:00
const userStore = useUserStore();
2024-09-16 13:08:27 +00:00
const appStore = useAppStore();
2024-09-12 13:50:39 +00:00
const route = useRoute();
const isMobile = useIsMobile();
const mainContainer = ref();
onMounted(() => {
element.mainContainer = mainContainer.value;
});
2024-09-16 13:08:27 +00:00
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;
2024-09-16 13:53:48 +00:00
appStore.contentScrollOnBottom = scrollTop + clientHeight >= scrollHeight;
2024-09-16 13:08:27 +00:00
// 当前位置
appStore.contentScrollPosition = scrollTop;
2024-09-16 13:53:48 +00:00
// 检测是否能滚动(如果内容的高度还没有超过可视区域的高度)
if (scrollHeight > clientHeight) {
appStore.contentScrollable = true;
} else {
appStore.contentScrollable = false;
}
};
2024-09-10 08:29:08 +00:00
</script>
<template>
2024-09-12 13:50:39 +00:00
<Header
style="
min-height: var(--header-height);
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
"
></Header>
2024-09-25 04:39:07 +00:00
<!-- <n-layout
:native-scrollbar="isMobile"
2024-09-12 13:50:39 +00:00
position="absolute"
:style="userStore.logined ? 'margin-top: var(--header-height)' : ''"
ref="mainContainer"
2024-09-16 13:08:27 +00:00
:on-scroll="onScroll"
2024-09-25 04:29:36 +00:00
></n-layout> -->
<n-layout
:native-scrollbar="isMobile"
position="absolute"
style="margin-top: var(--header-height)"
ref="mainContainer"
:on-scroll="onScroll"
2024-09-27 06:18:42 +00:00
:content-style="
!isMobile
? {
'padding-left': '32px',
'padding-right': '32px',
}
: {
'padding-left': '16px',
'padding-right': '16px',
}
"
2024-09-12 13:50:39 +00:00
>
2024-09-25 04:29:36 +00:00
<!-- <n-back-top v-if="!isMobile" :right="100" /> -->
2024-09-12 13:50:39 +00:00
<n-layout :native-scrollbar="isMobile">
2024-09-25 04:29:36 +00:00
<div class="!pt-2">
2024-10-17 14:06:36 +00:00
<div v-if="userStore.logined && !userStore.isExpired()">
2024-10-10 03:27:36 +00:00
<ChatLayout>
<router-view :key="route.path"> </router-view>
</ChatLayout>
</div>
<div v-else>
<router-view :key="route.path"> </router-view>
</div>
2024-09-25 04:29:36 +00:00
</div>
2024-09-10 08:29:08 +00:00
<!-- <Guest v-if="!userStore.logined && currentRoute != '/auth/login'" />
<Container v-else /> -->
2024-09-25 04:29:36 +00:00
<!-- <Guest v-if="!userStore.logined && !currentRoute?.startsWith('/auth')" />
<div v-else :class="userStore.logined ? 'pt-2' : ''">
2024-09-12 13:50:39 +00:00
<router-view :key="route.path"> </router-view>
2024-09-25 04:29:36 +00:00
</div> -->
2024-09-12 13:50:39 +00:00
</n-layout>
2024-09-10 08:29:08 +00:00
</n-layout>
</template>