main.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // 取消 vue warn
  24. app.config.warnHandler = function () { }
  25. directive(app);
  26. other.elSvg(app);
  27. app.component('pagination', pagination)
  28. app.component('copy', copy)
  29. app.use(router)
  30. .use(store, key)
  31. .use(ElementPlus, { i18n: i18n.global.t })
  32. .use(i18n)
  33. .use(JsonViewer)
  34. .use(VueGridLayout)
  35. .mount('#app');
  36. // 全局挂载
  37. app.config.globalProperties.getUpFileUrl = getUpFileUrl
  38. app.config.globalProperties.handleTree = handleTree
  39. app.config.globalProperties.useDict = useDict
  40. app.config.globalProperties.selectDictLabel = selectDictLabel
  41. app.config.globalProperties.mittBus = mitt();
  42. const matchMedia = window.matchMedia('(prefers-color-scheme: light)')
  43. matchMedia.addEventListener('change', function () {
  44. // console.log(`当前的主题是:${this.matches ? 'light' : 'dark'}`)
  45. setTheme(this.matches)
  46. })
  47. function setTheme(matches: Boolean) {
  48. const body = document.documentElement as HTMLElement;
  49. body.setAttribute('data-theme', matches ? '' : 'dark');
  50. document.querySelector('html')!.className = matches ? '' : 'dark'
  51. localStorage.setItem('isDark', matches ? '0' : '1')
  52. }