123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <!--
- - Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
- -
- - Licensed under the GNU Affero General Public License, Version 3 (the "License");
- - you may not use this file except in compliance with the License.
- - You may obtain a copy of the License at
- -
- - https://www.gnu.org/licenses/agpl-3.0.html
- -
- - Unless required by applicable law or agreed to in writing, software
- - distributed under the License is distributed on an "AS IS" BASIS,
- - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- - See the License for the specific language governing permissions and
- - limitations under the License.
- -->
- <template>
- <n-layout :position="fixedMenu" class="layout" has-sider>
- <n-layout-sider
- v-if="
- !isMobile && isMixMenuNoneSub && (navMode === 'vertical' || navMode === 'horizontal-mix')
- "
- :collapsed="collapsed"
- :collapsed-width="64"
- :inverted="inverted"
- :native-scrollbar="false"
- :position="fixedMenu"
- :width="leftMenuWidth"
- class="layout-sider"
- collapse-mode="width"
- show-trigger="bar"
- @collapse="collapsed = true"
- @expand="collapsed = false"
- >
- <Logo :collapsed="collapsed" />
- <AsideMenu v-model:collapsed="collapsed" v-model:location="getMenuLocation" />
- </n-layout-sider>
- <n-drawer
- v-model:show="showSideDrawer"
- :placement="'left'"
- :width="menuWidth"
- class="layout-side-drawer"
- >
- <n-layout-sider
- :collapsed="false"
- :inverted="inverted"
- :native-scrollbar="false"
- :position="fixedMenu"
- :width="menuWidth"
- class="layout-sider"
- >
- <Logo :collapsed="collapsed" />
- <AsideMenu v-model:location="getMenuLocation" />
- </n-layout-sider>
- </n-drawer>
- <n-layout :inverted="inverted">
- <n-layout-header :inverted="getHeaderInverted" :position="fixedHeader">
- <PageHeader v-model:collapsed="collapsed" :inverted="inverted" />
- </n-layout-header>
- <n-layout-content
- :class="{ 'layout-default-background': getDarkTheme === false }"
- class="layout-content"
- >
- <div
- :class="{
- 'layout-content-main-fix': fixedMulti,
- 'fluid-header': fixedHeader === 'static',
- }"
- class="layout-content-main"
- >
- <TabsView v-if="isMultiTabs" v-model:collapsed="collapsed" />
- <div
- :class="{
- 'main-view-fix': fixedMulti,
- noMultiTabs: !isMultiTabs,
- 'mt-3': !isMultiTabs,
- }"
- class="main-view"
- >
- <MainView />
- </div>
- </div>
- <!--1.15废弃,没啥用,占用操作空间-->
- <!-- <NLayoutFooter v-if="getShowFooter">-->
- <!-- <PageFooter />-->
- <!-- </NLayoutFooter>-->
- </n-layout-content>
- <n-back-top :right="100" />
- </n-layout>
- </n-layout>
- </template>
- <script lang="ts" setup>
- import { computed, onMounted, ref, unref, watch } from 'vue';
- import { Logo } from './components/Logo';
- import { TabsView } from './components/TagsView';
- import { MainView } from './components/Main';
- import { AsideMenu } from './components/Menu';
- import { PageHeader } from './components/Header';
- import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
- import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
- import { useRoute } from 'vue-router';
- import { useProjectSettingStore } from '@/store/modules/projectSetting';
- const { getDarkTheme } = useDesignSetting();
- const {
- // showFooter,
- navMode,
- navTheme,
- headerSetting,
- menuSetting,
- multiTabsSetting,
- } = useProjectSetting();
- const settingStore = useProjectSettingStore();
- const collapsed = ref<boolean>(false);
- const { mobileWidth, menuWidth } = unref(menuSetting);
- const isMobile = computed<boolean>({
- get: () => settingStore.getIsMobile,
- set: (val) => settingStore.setIsMobile(val),
- });
- const fixedHeader = computed(() => {
- const { fixed } = unref(headerSetting);
- return fixed ? 'absolute' : 'static';
- });
- const isMixMenuNoneSub = computed(() => {
- const mixMenu = unref(menuSetting).mixMenu;
- const currentRoute = useRoute();
- if (unref(navMode) != 'horizontal-mix') return true;
- if (unref(navMode) === 'horizontal-mix' && mixMenu && currentRoute.meta.isRoot) {
- return false;
- }
- return true;
- });
- const fixedMenu = computed(() => {
- const { fixed } = unref(headerSetting);
- return fixed ? 'absolute' : 'static';
- });
- const isMultiTabs = computed(() => {
- return unref(multiTabsSetting).show;
- });
- const fixedMulti = computed(() => {
- return unref(multiTabsSetting).fixed;
- });
- const inverted = computed(() => {
- return ['dark', 'header-dark'].includes(unref(navTheme));
- });
- const getHeaderInverted = computed(() => {
- return ['light', 'header-dark'].includes(unref(navTheme)) ? unref(inverted) : !unref(inverted);
- });
- const leftMenuWidth = computed(() => {
- const { minMenuWidth, menuWidth } = unref(menuSetting);
- return collapsed.value ? minMenuWidth : menuWidth;
- });
- const getMenuLocation = computed(() => {
- return 'left';
- });
- // 控制显示或隐藏移动端侧边栏
- const showSideDrawer = computed({
- get: () => isMobile.value && collapsed.value,
- set: (val) => (collapsed.value = val),
- });
- //判断是否触发移动端模式
- const checkMobileMode = () => {
- if (document.body.clientWidth <= mobileWidth) {
- isMobile.value = true;
- } else {
- isMobile.value = false;
- }
- collapsed.value = false;
- };
- const watchWidth = () => {
- const Width = document.body.clientWidth;
- if (Width <= 950) {
- collapsed.value = true;
- } else collapsed.value = false;
- checkMobileMode();
- };
- watch(
- () => settingStore.menuSetting.collapsed,
- (val) => {
- if (val) {
- // 单独校验store中的collapsed配置,优先于store中设置的true选项
- collapsed.value = true;
- }
- }
- );
- onMounted(() => {
- checkMobileMode();
- window.addEventListener('resize', watchWidth);
- });
- </script>
- <style lang="less">
- .layout-side-drawer {
- background-color: rgb(0, 20, 40);
- .layout-sider {
- min-height: 100vh;
- box-shadow: 2px 0 8px 0 rgb(29 35 41 / 5%);
- position: relative;
- z-index: 13;
- transition: all 0.2s ease-in-out;
- }
- }
- </style>
- <style lang="less" scoped>
- .layout {
- display: flex;
- flex-direction: row;
- flex: auto;
- &-default-background {
- background: #f8f8fa;
- }
- .layout-sider {
- min-height: 100vh;
- box-shadow: 2px 0 8px 0 rgb(29 35 41 / 5%);
- position: relative;
- z-index: 13;
- transition: all 0.2s ease-in-out;
- }
- .layout-sider-fix {
- position: fixed;
- top: 0;
- left: 0;
- }
- .ant-layout {
- overflow: hidden;
- }
- .layout-right-fix {
- overflow-x: hidden;
- padding-left: 200px;
- min-height: 100vh;
- transition: all 0.2s ease-in-out;
- }
- .layout-content {
- flex: auto;
- min-height: 100vh;
- }
- .n-layout-header.n-layout-header--absolute-positioned {
- z-index: 11;
- }
- .n-layout-footer {
- background: none;
- }
- }
- .layout-content-main {
- margin: 0 10px 10px;
- position: relative;
- padding-top: 64px;
- }
- .layout-content-main-fix {
- padding-top: 64px;
- }
- .fluid-header {
- padding-top: 0;
- }
- .main-view-fix {
- padding-top: 44px;
- height: calc(100vh - 64px) !important;
- }
- .noMultiTabs {
- padding-top: 0;
- }
- </style>
|