1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2026-01-23 08:00:22 +08:00

wip: 主题设置

This commit is contained in:
zclzone
2023-12-13 23:18:54 +08:00
parent c8616ebbf3
commit 4f0fbf6107
37 changed files with 1141 additions and 52 deletions

View File

@@ -12,7 +12,7 @@
:locale="zhCN"
:date-locale="dateZhCN"
:theme="appStore.isDark ? darkTheme : undefined"
:theme-overrides="settings.naiveThemeOverrides"
:theme-overrides="appStore.naiveThemeOverrides"
>
<router-view v-if="Layout" v-slot="{ Component, route: curRoute }">
<component :is="Layout">
@@ -20,16 +20,18 @@
<component :is="Component" v-if="!tabStore.reloading" :key="curRoute.fullPath" />
</KeepAlive>
</component>
<ThemeSetting class="fixed bottom-12 right-12" />
</router-view>
</n-config-provider>
</template>
<script setup>
import { zhCN, dateZhCN, darkTheme } from 'naive-ui'
import { ThemeSetting } from '@/components'
import { useCssVar } from '@vueuse/core'
import { kebabCase } from 'lodash-es'
import { useAppStore, useTabStore } from '@/store'
import settings from '@/settings'
const layouts = new Map()
function getLayout(name) {
@@ -44,11 +46,11 @@ const route = useRoute()
const appStore = useAppStore()
const Layout = computed(() => {
if (!route.matched?.length) return null
return getLayout(route.meta?.layout || appStore.layout || settings.defaultLayout)
return getLayout(route.meta?.layout || appStore.layout)
})
function setupCssVar() {
const common = settings.naiveThemeOverrides?.common || {}
const common = appStore.naiveThemeOverrides?.common || {}
for (const key in common) {
useCssVar(`--${kebabCase(key)}`, document.documentElement).value = common[key] || ''
if (key === 'primaryColor') window.localStorage.setItem('__THEME_COLOR__', common[key] || '')