-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.vue
122 lines (112 loc) · 3.02 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<script setup lang="ts">
import { appKeywords, appName } from "@/constants/index";
// 1、确认是否登录
const user = useUserStore();
const setting = useSettingStore();
// 退出登录时候
watch(
() => user.isLogin,
async (val) => {
if (val) {
// 获取用户信息
user.onCheckLogin();
}
},
{
immediate: true,
},
);
// https://nuxt.com.cn/docs/guide/directory-structure/app
// 准备完成关闭加载
onMounted(() => {
const app = document.querySelector("#app");
if (app)
app.classList.remove("stop-transition");
ElMessage.closeAll("error");
const font = setting.settingPage.fontFamily.value || null;
if (font)
document.documentElement.style.setProperty("--font-family", font);
// 是否关闭动画
if (setting.settingPage.isColseAllTransition)
document.documentElement.classList.add("stop-transition-all");
else
document.documentElement.classList.remove("stop-transition-all");
});
useHead({
title: `${appName} - 开启你的极物之旅 ✨`,
meta: [
{
name: "description",
content: "极物圈-主页 开启你的极物之旅!",
},
],
htmlAttrs: {
lang: "zh",
},
});
useSeoMeta({
title: `${appName} - 开启你的极物之旅 ✨`,
description: "极物圈-主页 开启你的极物之旅!",
keywords: appKeywords,
});
const colorMode = useColorMode();
function keyToggleTheme(e: KeyboardEvent) {
if (setting.isThemeChangeLoad)
return;
if (e?.altKey && e?.key && e?.key === "k") {
// 计算屏幕中心坐标
const centerX = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) / 2;
const centerY = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) / 2;
useModeToggle(colorMode.preference === "dark" ? "light" : "dark", {
clientX: +centerX,
clientY: +centerY,
} as MouseEvent);
}
}
setting.isThemeChangeLoad = true;
setting.isThemeChangeLoad = true;
onMounted(() => {
// 覆盖
window.addEventListener("keydown", keyToggleTheme);
if (setting.settingPage.modeToggle.value === "auto") {
const nowDate = new Date();
useModeToggle(nowDate.getHours() < 18 && nowDate.getHours() > 6 ? "light" : "dark");
}
setTimeout(() => {
setting.isThemeChangeLoad = false;
}, 1000);
});
// 同步修改系统 主题
watch(() => setting.settingPage.modeToggle.value, (val) => {
const nowDate = new Date();
if (val === "auto")
useModeToggle(nowDate.getHours() < 18 && nowDate.getHours() > 6 ? "light" : "dark");
}, {
immediate: false,
});
onUnmounted(() => {
window.removeEventListener("keydown", keyToggleTheme);
});
</script>
<template>
<div id="app">
<NuxtPage />
</div>
</template>
<style lang="scss">
// .page-enter-active,
// .page-leave-active {
// opacity: 1;
// transition-duration: 0.1s;
// transition-property: opacity;
// will-change: opacity;
// }
// .page-enter-from,
// .page-leave-to {
// opacity: 0;
// }
// .dark .page-enter-from,
// .dark .page-leave-to {
// opacity: 0.7;
// }
</style>