finish basic sidebar

This commit is contained in:
2025-03-14 19:04:15 +08:00
parent 9200befaf8
commit 8f18560a38
9 changed files with 215 additions and 61 deletions

View File

@@ -10,3 +10,4 @@ export const useCounterStore = defineStore('counter', () => {
return { count, doubleCount, increment }
})

47
src/stores/theme.ts Normal file
View File

@@ -0,0 +1,47 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const useThemeStore = defineStore('theme', () => {
const allTheme = ["winter", "night"]
const darkTheme = "night";
const lightTheme = "winter";
const currentTheme = ref("night")
function setTheme(theme: string) {
const isContained: boolean = allTheme.includes(theme)
if (isContained) {
currentTheme.value = theme
}
else {
console.error('Not have such theme: ${theme}')
}
}
function toggleTheme() {
if (currentTheme.value == darkTheme) {
currentTheme.value = lightTheme;
} else if (currentTheme.value == lightTheme) {
currentTheme.value = darkTheme;
} else {
currentTheme.value = lightTheme;
}
}
function isDarkTheme(): boolean {
return currentTheme.value == darkTheme
}
function isLightTheme(): boolean {
return currentTheme.value == lightTheme
}
return {
allTheme,
currentTheme,
setTheme,
toggleTheme,
isDarkTheme,
isLightTheme
}
})