main.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import store from './store'
  5. import "@/assets/style/reset.css"
  6. import "@/assets/style/my-reset.css"
  7. import UAParser from "@/libs/ua-parser.min.js"
  8. import clickOutside from "@/directives/v-click-outside.js"
  9. import mitt from "mitt"
  10. import ElementPlus from 'element-plus'
  11. import 'element-plus/dist/index.css'
  12. // import 'viewerjs/dist/viewer.css'
  13. // import VueViewer from 'v-viewer'
  14. console.log(`version: ${process.env.VUE_APP_VERSION}`)
  15. console.log(`Build time: ${process.env.VUE_APP_UPDATE_TIME}`)
  16. if (
  17. localStorage.getItem('useDarkTheme') === '1' ||
  18. (!localStorage.getItem('useDarkTheme') && gConfigInfo.defaultDarkTheme)
  19. ) {
  20. store.commit('setIsDarkTheme', true)
  21. }
  22. const app = createApp(App)
  23. // 挂载配置信息
  24. app.config.globalProperties.$config = config
  25. app.config.globalProperties.$gConfigInfo = gConfigInfo
  26. app.config.globalProperties.$gConfigTxt = gConfigTxt
  27. app.config.globalProperties.$env = process.env
  28. // 挂载消息发布订阅中心
  29. app.config.globalProperties.$mitt = mitt()
  30. // 解析、挂载浏览器信息
  31. const uaParser = new UAParser()
  32. const uaInfo = uaParser.getResult()
  33. console.log(uaInfo)
  34. app.config.globalProperties.$uaInfo = uaInfo
  35. if (uaInfo.browser && uaInfo.browser.name === 'WeChat') {
  36. app.config.globalProperties.$isWeChat = true
  37. }
  38. if (uaInfo.browser && uaInfo.browser.name === 'Safari') {
  39. app.config.globalProperties.$isSafari = true
  40. }
  41. if (uaInfo.device.type === 'mobile') {
  42. app.config.globalProperties.$isMobile = true
  43. document.body.classList.add('mobile')
  44. } else {
  45. app.config.globalProperties.$isMobile = false
  46. }
  47. // // 处理resize事件
  48. // let windowWidthLast = window.innerWidth
  49. // let windowHeightLast = window.innerHeight
  50. // function onResize() {
  51. // windowWidthLast = window.innerWidth
  52. // windowHeightLast = window.innerHeight
  53. // }
  54. // window.addEventListener('resize', () => {
  55. // onResize()
  56. // })
  57. // // 禁用上下文菜单
  58. // document.oncontextmenu = function(e) {
  59. // e.preventDefault()
  60. // }
  61. // // safari里只能在交互行为的回调中成功地首次调用audio的play方法,所以需要一个全局的audio元素来播放随时可能需要自发播放的音频。
  62. // const audioNode = document.createElement("audio")
  63. // audioNode.id = 'global-audio'
  64. // audioNode.style.display = 'none'
  65. // audioNode.loop = true
  66. // document.body.appendChild(audioNode)
  67. app.use(store)
  68. .use(router)
  69. .use(clickOutside)
  70. .use(ElementPlus)
  71. // .use(VueViewer)
  72. // .component('HotSpot', HotSpot)
  73. .mount('#app')
  74. // 必须在vue根组件挂载之后执行
  75. if (app.config.globalProperties.$isMobile) {
  76. document.getElementById('app').classList.add('mobile')
  77. }