Skip to content

Commit

Permalink
feat: add mix layout
Browse files Browse the repository at this point in the history
  • Loading branch information
chansee97 committed Jun 24, 2024
1 parent 8f5f11f commit 9ce6bd3
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 61 deletions.
63 changes: 20 additions & 43 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,
Expand All @@ -11,46 +9,16 @@
},
// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{
"rule": "style/*",
"severity": "off"
},
{
"rule": "format/*",
"severity": "off"
},
{
"rule": "*-indent",
"severity": "off"
},
{
"rule": "*-spacing",
"severity": "off"
},
{
"rule": "*-spaces",
"severity": "off"
},
{
"rule": "*-order",
"severity": "off"
},
{
"rule": "*-dangle",
"severity": "off"
},
{
"rule": "*-newline",
"severity": "off"
},
{
"rule": "*quotes",
"severity": "off"
},
{
"rule": "*semi",
"severity": "off"
}
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],
// Enable eslint for all supported languages
"eslint.validate": [
Expand All @@ -64,7 +32,16 @@
"json",
"jsonc",
"yaml",
"toml"
"toml",
"xml",
"gql",
"graphql",
"astro",
"css",
"less",
"scss",
"pcss",
"postcss"
],
"i18n-ally.sourceLanguage": "zh_CN",
"i18n-ally.displayLanguage": "zh_CN",
Expand Down
22 changes: 11 additions & 11 deletions src/components/common/NovaIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ const isLocal = computed(() => {
function getLocalIcon(icon: string) {
const svgName = icon.replace('local:', '')
const svg = import.meta.glob('@/assets/svg-icons/*.svg', {
const svg = import.meta.glob<string>('@/assets/svg-icons/*.svg', {
query: '?raw',
import: 'default',
eager: true,
})
return svg[`/src/assets/svg-icons/${svgName}.svg`]
const domparser = new DOMParser()
return domparser.parseFromString(svg[`/src/assets/svg-icons/${svgName}.svg`], 'image/svg+xml')
}
</script>

Expand All @@ -38,15 +40,13 @@ function getLocalIcon(icon: string) {
:depth="depth"
:color="color"
>
<Icon :icon="icon" />
</n-icon>
<n-icon
v-if="icon && isLocal"
:size="size"
:depth="depth"
:color="color"
v-html="getLocalIcon(icon)"
/>
<template v-if="isLocal">
{{ getLocalIcon(icon) }}
</template>
<template v-else>
<Icon :icon="icon" />
</template>
</n-icon>
</template>

<style scoped></style>
20 changes: 19 additions & 1 deletion src/layouts/components/common/LayoutSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const value = defineModel<LayoutMode>('value', { required: true })
:class="{
'outline outline-2': value === 'topMenu',
}"
class="grid grid-rows-[30%_1fr] outline-[var(--primary-color)] hover:(outline outline-2) cursor-pointer"
class="grid grid-rows-[30%_1fr] outline-[var(--primary-color)] hover:(outline outline-2) cursor-pointer"
@click="value = 'topMenu'"
>
<div class="bg-[var(--primary-color)]" />
Expand All @@ -38,6 +38,24 @@ const value = defineModel<LayoutMode>('value', { required: true })
</template>
<span> {{ $t('app.topMenu') }} </span>
</n-tooltip>

<n-tooltip placement="bottom" trigger="hover">
<template #trigger>
<n-el
:class="{
'outline outline-2': value === 'mixMenu',
}"
class="grid grid-cols-[20%_1fr] grid-rows-[15%_15%_1fr] outline-[var(--primary-color)] hover:(outline outline-2) cursor-pointer"
@click="value = 'mixMenu'"
>
<div class="bg-[var(--primary-color)] row-span-3" />
<div class="bg-[var(--primary-color)]" />
<div class="bg-[var(--primary-color-suppl)]" />
<div class="bg-[var(--divider-color)]" />
</n-el>
</template>
<span> {{ $t('app.topMenu') }} </span>
</n-tooltip>
</div>
</template>

Expand Down
8 changes: 4 additions & 4 deletions src/layouts/components/sider/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useAppStore, useRouteStore } from '@/store'
const route = useRoute()
const appStore = useAppStore()
const routesStore = useRouteStore()
const routeStore = useRouteStore()
const menuInstRef = ref<MenuInst | null>(null)
watch(
() => route.path,
() => {
menuInstRef.value?.showOption(routesStore.activeMenu as string)
menuInstRef.value?.showOption(routeStore.activeMenu as string)
},
{ immediate: true },
)
Expand All @@ -22,7 +22,7 @@ watch(
:collapsed="appStore.collapsed"
:indent="20"
:collapsed-width="64"
:options="routesStore.menus"
:value="routesStore.activeMenu"
:options="routeStore.menus"
:value="routeStore.activeMenu"
/>
</template>
2 changes: 2 additions & 0 deletions src/layouts/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script setup lang="ts">
import leftMenu from './leftMenu.layout.vue'
import topMenu from './topMenu.layout.vue'
import mixMenu from './mixMenu.layout.vue'
import { SettingDrawer } from './components'
import { useAppStore } from '@/store/app'
const appStore = useAppStore()
const layoutMap = {
leftMenu,
topMenu,
mixMenu,
}
</script>

Expand Down
152 changes: 152 additions & 0 deletions src/layouts/mixMenu.layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<script lang="ts" setup>
import type { MenuInst, MenuOption } from 'naive-ui'
import {
BackTop,
CollapaseButton,
FullScreen,
Logo,
Notices,
Search,
Setting,
TabBar,
UserCenter,
} from './components'
import { useAppStore, useRouteStore } from '@/store'
const routeStore = useRouteStore()
const appStore = useAppStore()
const pageRoute = useRoute()
const router = useRouter()
const menuInstRef = ref<MenuInst | null>(null)
watch(
() => pageRoute.path,
() => {
menuInstRef.value?.showOption(routeStore.activeMenu as string)
},
{ immediate: true },
)
const topMenu = ref<MenuOption[]>([])
const activeTopMenu = ref<string>('')
function handleTopMenu(rowMenu: MenuOption[]) {
topMenu.value = rowMenu.map((i) => {
const { icon, label, key } = i
return {
icon,
label,
key,
}
})
}
onMounted(() => {
handleTopMenu(routeStore.menus)
// 根据当前页面获取选中菜单和对应侧边菜单
const currentMenuKey = pageRoute.matched[1].path
updateTopMenu(currentMenuKey)
})
const sideMenu = ref<MenuOption[]>([])
function handleSideMenu(key: string) {
const targetMenu = routeStore.menus.find(i => i.key === key)
if (targetMenu) {
sideMenu.value = targetMenu.children ? targetMenu.children : [targetMenu]
}
}
function updateTopMenu(key: string) {
handleSideMenu(key)
activeTopMenu.value = key
router.push(key)
}
</script>

<template>
<n-layout
has-sider
class="wh-full"
embedded
>
<n-layout-sider
bordered
:collapsed="appStore.collapsed"
collapse-mode="width"
:collapsed-width="64"
:width="240"
content-style="display: flex;flex-direction: column;min-height:100%;"
>
<Logo v-if="appStore.showLogo" />
<n-scrollbar class="flex-1">
<n-menu
ref="menuInstRef"
:collapsed="appStore.collapsed"
:indent="20"
:collapsed-width="64"
:options="sideMenu"
:value="routeStore.activeMenu"
/>
</n-scrollbar>
</n-layout-sider>
<n-layout
class="h-full flex flex-col"
content-style="display: flex;flex-direction: column;min-height:100%;"
embedded
:native-scrollbar="false"
>
<n-layout-header bordered position="absolute" class="z-1">
<div class="h-60px flex-y-center justify-between">
<CollapaseButton />
<n-menu
ref="menuInstRef"
mode="horizontal"
responsive
:options="topMenu"
:value="activeTopMenu"
@update:value="updateTopMenu"
/>
<div class="flex-y-center gap-1 h-full p-x-xl">
<Search />
<Notices />
<FullScreen />
<DarkModeSwitch />
<LangsSwitch />
<Setting />
<UserCenter />
</div>
</div>
<TabBar v-if="appStore.showTabs" class="h-45px" />
</n-layout-header>
<div class="flex-1 p-16px flex flex-col">
<div class="h-60px" />
<div v-if="appStore.showTabs" class="h-45px" />
<router-view v-slot="{ Component, route }" class="flex-1">
<transition
:name="appStore.transitionAnimation"
mode="out-in"
>
<keep-alive :include="routeStore.cacheRoutes">
<component
:is="Component"
v-if="appStore.loadFlag"
:key="route.fullPath"
/>
</keep-alive>
</transition>
</router-view>
<div v-if="appStore.showFooter" class="h-40px" />
</div>
<n-layout-footer
v-if="appStore.showFooter"
bordered
position="absolute"
class="h-40px flex-center"
>
{{ appStore.footerText }}
</n-layout-footer>
<BackTop />
</n-layout>
</n-layout>
</template>
2 changes: 1 addition & 1 deletion src/store/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import themeConfig from './theme.json'
import { local, setLocale } from '@/utils'

type TransitionAnimation = '' | 'fade-slide' | 'fade-bottom' | 'fade-scale' | 'zoom-fade' | 'zoom-out'
export type LayoutMode = 'leftMenu' | 'topMenu'
export type LayoutMode = 'leftMenu' | 'topMenu' | 'mixMenu'

const docEle = ref(document.documentElement)

Expand Down
3 changes: 2 additions & 1 deletion src/store/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { MenuOption } from 'naive-ui'
import { createMenus, createRoutes, generateCacheRoutes } from './helper'
import { $t, local } from '@/utils'
import { router } from '@/router'
Expand All @@ -7,7 +8,7 @@ import { useAuthStore } from '@/store/auth'

interface RoutesStatus {
isInitAuthRoute: boolean
menus: AppRoute.Route[]
menus: MenuOption[]
rowRoutes: AppRoute.RowRoute[]
activeMenu: string | null
cacheRoutes: string[]
Expand Down

0 comments on commit 9ce6bd3

Please sign in to comment.