feat(theme): 主题切换全局响应

This commit is contained in:
BTMuli
2023-04-22 21:09:10 +08:00
parent add9fc4d23
commit 7488ada30d
3 changed files with 43 additions and 8 deletions

View File

@@ -139,7 +139,9 @@
<script lang="ts" setup>
// vue
import { computed, ref } from "vue";
import { computed, ref, onMounted } from "vue";
// tauri
import { event } from "@tauri-apps/api";
// store
import { useAppStore } from "../store/modules/app";
@@ -174,11 +176,20 @@ function collapse () {
appStore.sidebar.collapse = rail.value;
}
function switchTheme () {
appStore.changeTheme();
document.documentElement.className = themeGet.value;
onMounted(async () => {
await listenOnTheme();
});
async function listenOnTheme () {
await event.listen("readTheme", (e) => {
const theme = e.payload as string;
themeGet.value = theme === "default" ? "default" : "dark";
});
}
async function switchTheme () {
await event.emit("readTheme", themeGet.value === "default" ? "dark" : "default");
}
</script>
<style lang="css" scoped>