main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 mitt from "mitt"
  9. import 'viewerjs/dist/viewer.css'
  10. import VueViewer from 'v-viewer'
  11. import ElementPlus from 'element-plus'
  12. import 'element-plus/dist/index.css'
  13. import { Swiper, SwiperSlide } from 'swiper/vue'
  14. import 'swiper/css'
  15. import 'swiper/css/pagination' // 分页器样式
  16. import BtnBack from '@/components/BtnBack.vue'
  17. import OperationTip from '@/components/OperationTip.vue'
  18. import HotspotComp from '@/components/HotspotComp.vue'
  19. import HotspotForHomepage from '@/components/HotspotForHomepage.vue'
  20. import SerialFrames from '@/components/LongImageSerialFrames.vue'
  21. import BtnSkip from '@/components/BtnSkip.vue'
  22. import PaginationComp from '@/components/PaginationComp.vue'
  23. console.log(`version: ${process.env.VUE_APP_VERSION}`)
  24. console.log(`Build time: ${process.env.VUE_APP_UPDATE_TIME}`)
  25. const app = createApp(App)
  26. // 挂载配置信息
  27. app.provide('$config', config)
  28. app.provide('$env', process.env)
  29. // 挂载消息发布订阅中心
  30. app.provide('$mitt', mitt())
  31. // 解析、挂载浏览器信息
  32. const uaParser = new UAParser()
  33. const uaInfo = uaParser.getResult()
  34. console.log('uaInfo: ', uaInfo)
  35. app.provide('$uaInfo', uaInfo)
  36. if (uaInfo.browser && uaInfo.browser.name === 'WeChat') {
  37. app.provide('$isWeChat', true)
  38. }
  39. if (uaInfo.browser && uaInfo.browser.name === 'Safari') {
  40. app.provide('$isSafari', true)
  41. }
  42. if (uaInfo.device.type === 'mobile') {
  43. app.provide('$isMobile', true)
  44. }
  45. // 处理resize事件
  46. let windowWidthLast = window.innerWidth
  47. let windowHeightLast = window.innerHeight
  48. function onResize() {
  49. if (window.innerWidth === windowWidthLast) {
  50. // 发生了高度变化,认为发生了软键盘显隐
  51. if (uaInfo.os.name === 'Android') {
  52. if (window.innerHeight < windowHeightLast) {
  53. // ...
  54. } else if (window.innerHeight > windowHeightLast) {
  55. // ...
  56. }
  57. }
  58. }
  59. windowWidthLast = window.innerWidth
  60. windowHeightLast = window.innerHeight
  61. }
  62. window.addEventListener('resize', () => {
  63. onResize()
  64. })
  65. // // 禁用上下文菜单
  66. document.oncontextmenu = function(e) {
  67. e.preventDefault()
  68. }
  69. // // safari里只能在交互行为的回调中成功地首次调用audio的play方法,所以需要一个全局的audio元素来播放随时可能需要自发播放的音频。
  70. // const audioNode = document.createElement("audio")
  71. // audioNode.id = 'global-audio'
  72. // audioNode.style.display = 'none'
  73. // audioNode.loop = true
  74. // document.body.appendChild(audioNode)
  75. app.use(store)
  76. .use(router)
  77. .use(VueViewer)
  78. .use(ElementPlus)
  79. .component('BtnBack', BtnBack)
  80. .component('OperationTip', OperationTip)
  81. .component('HotspotComp', HotspotComp)
  82. .component('HotspotForHomepage', HotspotForHomepage)
  83. .component('Swiper', Swiper)
  84. .component('SwiperSlide', SwiperSlide)
  85. .component('SerialFrames', SerialFrames)
  86. .component('BtnSkip', BtnSkip)
  87. .component('PaginationComp', PaginationComp)
  88. .mount('#app')
  89. // you can reset the default options at any other time
  90. VueViewer.setDefaults({
  91. inline: false,
  92. button: true,
  93. navbar: false,
  94. title: false,
  95. toolbar: false,
  96. tooltip: false,
  97. movable: true,
  98. zoomable: true,
  99. rotatable: false,
  100. // "scalable": true,
  101. transition: true,
  102. fullscreen: true,
  103. keyboard: true,
  104. })
  105. // 必须在vue根组件挂载之后执行
  106. if (uaInfo.device.type === 'mobile') {
  107. document.getElementById('app').classList.add('mobile')
  108. }