main.js 3.8 KB

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