add logout && fix theme

This commit is contained in:
jxxghp
2023-06-24 17:26:00 +08:00
parent db40e4a800
commit 4a6cde67b3
5 changed files with 152 additions and 166 deletions

View File

@@ -1,22 +1,35 @@
<script setup lang="ts">
import { useTheme } from 'vuetify'
import type { ThemeSwitcherTheme } from '@layouts/types'
import type { ThemeSwitcherTheme } from '@layouts/types';
import { ref, watch } from 'vue';
import { useTheme } from 'vuetify';
const props = defineProps<{
themes: ThemeSwitcherTheme[]
}>()
const { name: themeName, global: globalTheme } = useTheme()
const { state: currentThemeName, next: getNextThemeName, index: currentThemeIndex } = useCycleList(props.themes.map(t => t.name), { initialValue: themeName })
const savedTheme = ref(localStorage.getItem('theme') ?? themeName)
const { state: currentThemeName, next: getNextThemeName, index: currentThemeIndex } = useCycleList(props.themes.map(t => t.name), { initialValue: savedTheme.value })
const changeTheme = () => {
globalTheme.name.value = getNextThemeName()
const nextTheme = getNextThemeName()
globalTheme.name.value = nextTheme
savedTheme.value = nextTheme
localStorage.setItem('theme', nextTheme)
}
// Update icon if theme is changed from other sources
watch(() => globalTheme.name.value, val => {
currentThemeName.value = val
})
// Apply saved theme on page load
onMounted(() => {
globalTheme.name.value = savedTheme.value
})
</script>
<template>