|
@@ -19,9 +19,31 @@ import { createPinia } from 'pinia'
|
|
|
|
|
|
|
|
import App from './App.vue'
|
|
import App from './App.vue'
|
|
|
import router from './router'
|
|
import router from './router'
|
|
|
|
|
+import { useThemeStore } from '@/stores/modules/theme'
|
|
|
|
|
|
|
|
const app = createApp(App)
|
|
const app = createApp(App)
|
|
|
|
|
|
|
|
|
|
+for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
|
|
|
+ app.component(key, component)
|
|
|
|
|
+}
|
|
|
|
|
+// 让VxeTable支持导出Excel
|
|
|
|
|
+VXETable.use(VXETablePluginExportXLSX, {
|
|
|
|
|
+ ExcelJS
|
|
|
|
|
+})
|
|
|
|
|
+VXETable.setI18n('en-US', enUS)
|
|
|
|
|
+VXETable.setLanguage('en-US')
|
|
|
|
|
+
|
|
|
|
|
+app.use(createPinia())
|
|
|
|
|
+app.use(VXETable)
|
|
|
|
|
+app.use(VxeUI)
|
|
|
|
|
+app.use(router)
|
|
|
|
|
+app.use(Antd)
|
|
|
|
|
+
|
|
|
|
|
+// 注册全局指令
|
|
|
|
|
+app.directive('vloading', VLoading)
|
|
|
|
|
+
|
|
|
|
|
+const themeStore = useThemeStore()
|
|
|
|
|
+
|
|
|
// 动态加载暗黑主题
|
|
// 动态加载暗黑主题
|
|
|
async function loadDarkTheme() {
|
|
async function loadDarkTheme() {
|
|
|
await import('element-plus/theme-chalk/dark/css-vars.css') // 动态导入暗黑主题
|
|
await import('element-plus/theme-chalk/dark/css-vars.css') // 动态导入暗黑主题
|
|
@@ -33,15 +55,24 @@ function unloadDarkTheme() {
|
|
|
darkThemeStylesheet.remove()
|
|
darkThemeStylesheet.remove()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-// 根据用户偏好或系统设置决定是否加载暗黑主题 (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ||
|
|
|
|
|
-if (localStorage.getItem('theme') === 'dark') {
|
|
|
|
|
- loadDarkTheme()
|
|
|
|
|
- document.documentElement.classList.add('dark')
|
|
|
|
|
|
|
+// 用户没有手动切换主题时,根据系统设置自动切换
|
|
|
|
|
+if (!themeStore.isManualChange) {
|
|
|
|
|
+ // 根据用户偏好或系统设置决定是否添加暗黑模式类名
|
|
|
|
|
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
|
|
|
+ themeStore.toggleTheme('dark')
|
|
|
|
|
+ loadDarkTheme()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ unloadDarkTheme()
|
|
|
|
|
+ themeStore.toggleTheme('light')
|
|
|
|
|
+ }
|
|
|
|
|
+} else {
|
|
|
|
|
+ // 用户手动切换主题时,根据用户设置切换
|
|
|
|
|
+ if (themeStore.theme === 'dark') {
|
|
|
|
|
+ loadDarkTheme()
|
|
|
|
|
+ themeStore.toggleTheme('dark')
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-// 根据用户偏好或系统设置决定是否添加暗黑模式类名
|
|
|
|
|
-// if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
|
|
|
-// document.documentElement.classList.add('dark')
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+
|
|
|
// 提供一个全局方法来切换主题
|
|
// 提供一个全局方法来切换主题
|
|
|
app.config.globalProperties.$toggleDarkMode = () => {
|
|
app.config.globalProperties.$toggleDarkMode = () => {
|
|
|
const html = document.documentElement
|
|
const html = document.documentElement
|
|
@@ -56,23 +87,4 @@ app.config.globalProperties.$toggleDarkMode = () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
|
|
|
- app.component(key, component)
|
|
|
|
|
-}
|
|
|
|
|
-// 让VxeTable支持导出Excel
|
|
|
|
|
-VXETable.use(VXETablePluginExportXLSX, {
|
|
|
|
|
- ExcelJS
|
|
|
|
|
-})
|
|
|
|
|
-VXETable.setI18n('en-US', enUS)
|
|
|
|
|
-VXETable.setLanguage('en-US')
|
|
|
|
|
-
|
|
|
|
|
-app.use(createPinia())
|
|
|
|
|
-app.use(VXETable)
|
|
|
|
|
-app.use(VxeUI)
|
|
|
|
|
-app.use(router)
|
|
|
|
|
-app.use(Antd)
|
|
|
|
|
-
|
|
|
|
|
-// 注册全局指令
|
|
|
|
|
-app.directive('vloading', VLoading)
|
|
|
|
|
-
|
|
|
|
|
app.mount('#app')
|
|
app.mount('#app')
|