feat(style): dark mode
This commit is contained in:
		
							parent
							
								
									e8594de7b4
								
							
						
					
					
						commit
						3e92b7f1e0
					
				| @ -5,16 +5,21 @@ import { computed } from 'vue'; | |||||||
| import { useRoute } from 'vue-router' | import { useRoute } from 'vue-router' | ||||||
| 
 | 
 | ||||||
| import { | import { | ||||||
|  |   darkTheme, | ||||||
|   NConfigProvider, |   NConfigProvider, | ||||||
|   NGlobalStyle, |   NGlobalStyle, | ||||||
| } from 'naive-ui' | } from 'naive-ui' | ||||||
|  | import { useStyleStore } from './stores/style.store'; | ||||||
| 
 | 
 | ||||||
| const route = useRoute(); | const route = useRoute(); | ||||||
| const layout = computed(() => route?.meta?.layout ?? layouts.base) | const layout = computed(() => route?.meta?.layout ?? layouts.base) | ||||||
|  | const styleStore = useStyleStore() | ||||||
|  | 
 | ||||||
|  | const theme = computed(() => styleStore.isDarkTheme ? darkTheme : null) | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|   <n-config-provider> |   <n-config-provider :theme="theme"> | ||||||
|     <n-global-style /> |     <n-global-style /> | ||||||
|     <n-message-provider placement="bottom"> |     <n-message-provider placement="bottom"> | ||||||
|       <component :is="layout"> |       <component :is="layout"> | ||||||
|  | |||||||
| @ -2,13 +2,15 @@ | |||||||
| import { NIcon } from 'naive-ui'; | import { NIcon } from 'naive-ui'; | ||||||
| import { h, ref, type Component } from 'vue'; | import { h, ref, type Component } from 'vue'; | ||||||
| import { RouterLink, useRoute } from 'vue-router'; | import { RouterLink, useRoute } from 'vue-router'; | ||||||
| import { User } from '@vicons/tabler' | import { LightModeFilled, DarkModeFilled } from '@vicons/material' | ||||||
| import { tools } from '@/tools'; | import { tools } from '@/tools'; | ||||||
| import SearchBar from '../components/SearchBar.vue'; | import SearchBar from '../components/SearchBar.vue'; | ||||||
|  | import { useStyleStore } from '@/stores/style.store'; | ||||||
| 
 | 
 | ||||||
| const collapsed = ref(false) | const collapsed = ref(false) | ||||||
| const activeKey = ref(null) | const activeKey = ref(null) | ||||||
| const route = useRoute() | const route = useRoute() | ||||||
|  | const styleStore = useStyleStore() | ||||||
| 
 | 
 | ||||||
| const makeLabel = (text: string, to: string) => () => h(RouterLink, { to }, { default: () => text }) | const makeLabel = (text: string, to: string) => () => h(RouterLink, { to }, { default: () => text }) | ||||||
| const makeIcon = (icon: Component) => () => h(NIcon, null, { default: () => h(icon) }) | const makeIcon = (icon: Component) => () => h(NIcon, null, { default: () => h(icon) }) | ||||||
| @ -53,9 +55,16 @@ const menuOptions = tools.map(({ name, path, icon }) => ({ | |||||||
|             <div class="bar-wrapper"> |             <div class="bar-wrapper"> | ||||||
|                 <search-bar /> |                 <search-bar /> | ||||||
| 
 | 
 | ||||||
|                 <n-button secondary circle> |                 <n-button | ||||||
|                     <n-icon size="large"> |                     circle | ||||||
|                         <user /> |                     quaternary | ||||||
|  |                     @click="styleStore.isDarkTheme = !styleStore.isDarkTheme" | ||||||
|  |                 > | ||||||
|  |                     <n-icon size="large" v-if="styleStore.isDarkTheme"> | ||||||
|  |                         <LightModeFilled /> | ||||||
|  |                     </n-icon> | ||||||
|  |                     <n-icon size="large" v-else> | ||||||
|  |                         <DarkModeFilled /> | ||||||
|                     </n-icon> |                     </n-icon> | ||||||
|                 </n-button> |                 </n-button> | ||||||
|             </div> |             </div> | ||||||
| @ -76,7 +85,7 @@ const menuOptions = tools.map(({ name, path, icon }) => ({ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .content { | .content { | ||||||
|     background-color: #f1f5f9; |     // background-color: #f1f5f9; | ||||||
|     ::v-deep(.n-layout-scroll-container) { |     ::v-deep(.n-layout-scroll-container) { | ||||||
|         padding: 26px; |         padding: 26px; | ||||||
|     } |     } | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								src/stores/style.store.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/stores/style.store.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | import { defineStore } from 'pinia'; | ||||||
|  | 
 | ||||||
|  | export const useStyleStore = defineStore('style', () => ({ | ||||||
|  |   isDarkTheme: true, | ||||||
|  | })); | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user