| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import './assets/main.css'
- import './styles/index.scss'
- import './styles/icons/iconfont.js'
- import VXETable from 'vxe-table'
- import 'vxe-table/lib/style.css'
- import enUS from 'vxe-table/lib/locale/lang/en-US'
- import VxeUI from 'vxe-pc-ui'
- import 'element-plus/dist/index.css'
- import 'vxe-pc-ui/lib/style.css'
- import Antd from 'ant-design-vue'
- import 'ant-design-vue/dist/reset.css'
- import * as ElementPlusIconsVue from '@element-plus/icons-vue'
- import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
- import ExcelJS from 'exceljs'
- import { VLoading } from './directive/VLoading'
- import { createApp } from 'vue'
- import { createPinia } from 'pinia'
- import App from './App.vue'
- import router from './router'
- const app = createApp(App)
- // 动态加载暗黑主题
- async function loadDarkTheme() {
- await import('element-plus/theme-chalk/dark/css-vars.css') // 动态导入暗黑主题
- }
- // 动态移除暗黑主题
- function unloadDarkTheme() {
- const darkThemeStylesheet = document.getElementById('dark-theme-style')
- if (darkThemeStylesheet) {
- darkThemeStylesheet.remove()
- }
- }
- // 根据用户偏好或系统设置决定是否加载暗黑主题 (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ||
- if (localStorage.getItem('theme') === 'dark') {
- loadDarkTheme()
- document.documentElement.classList.add('dark')
- }
- // 根据用户偏好或系统设置决定是否添加暗黑模式类名
- // if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
- // document.documentElement.classList.add('dark')
- // }
- // 提供一个全局方法来切换主题
- app.config.globalProperties.$toggleDarkMode = () => {
- const html = document.documentElement
- if (html.classList.contains('dark')) {
- unloadDarkTheme()
- html.classList.remove('dark')
- localStorage.setItem('theme', 'light')
- } else {
- loadDarkTheme()
- html.classList.add('dark')
- localStorage.setItem('theme', 'dark')
- }
- }
- 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')
|