main.js 3.5 KB

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