main.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { createApp } from 'vue';
  2. // import Vue from 'vue';
  3. import App from './App.vue';
  4. import router from './router';
  5. import { store, key } from './store';
  6. import { directive } from '/@/utils/directive';
  7. import { i18n } from '/@/i18n/index';
  8. import other from '/@/utils/other';
  9. import ElementPlus from 'element-plus';
  10. import 'element-plus/dist/index.css';
  11. import 'element-plus/theme-chalk/dark/css-vars.css'
  12. import '/@/theme/index.scss';
  13. import mitt from 'mitt';
  14. import VueGridLayout from 'vue-grid-layout';
  15. import { getUpFileUrl, handleTree, selectDictLabel } from "/@/utils/common";
  16. import { useDict } from "/@/api/common/dict/data";
  17. // 分页组件
  18. import pagination from '/@/components/pagination/index.vue'
  19. import copy from '/@/components/copy/index.vue'
  20. //引入json数据展示
  21. import JsonViewer from "vue3-json-viewer"
  22. const app = createApp(App);
  23. directive(app);
  24. other.elSvg(app);
  25. app.component('pagination', pagination)
  26. app.component('copy', copy)
  27. app.use(router)
  28. .use(store, key)
  29. .use(ElementPlus, { i18n: i18n.global.t })
  30. .use(i18n)
  31. .use(JsonViewer)
  32. .use(VueGridLayout)
  33. .mount('#app');
  34. // 全局挂载
  35. app.config.globalProperties.getUpFileUrl = getUpFileUrl
  36. app.config.globalProperties.handleTree = handleTree
  37. app.config.globalProperties.useDict = useDict
  38. app.config.globalProperties.selectDictLabel = selectDictLabel
  39. app.config.globalProperties.mittBus = mitt();
  40. const matchMedia = window.matchMedia('(prefers-color-scheme: light)')
  41. matchMedia.addEventListener('change', function () {
  42. // console.log(`当前的主题是:${this.matches ? 'light' : 'dark'}`)
  43. setTheme(this.matches)
  44. })
  45. function setTheme(matches: Boolean) {
  46. const body = document.documentElement as HTMLElement;
  47. body.setAttribute('data-theme', matches ? '' : 'dark');
  48. document.querySelector('html')!.className = matches ? '' : 'dark'
  49. localStorage.setItem('isDark', matches ? '0' : '1')
  50. }