main.ts 2.2 KB

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