main.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import store from './store'
  5. import UAParser from "@/libs/ua-parser.min.js"
  6. import "@/assets/style/reset.css"
  7. import "@/assets/style/my-reset.css"
  8. import clickOutside from "@/directives/v-click-outside.js"
  9. import 'viewerjs/dist/viewer.css'
  10. import Viewer from 'v-viewer'
  11. import VueLazyload from 'vue-lazyload'
  12. import { MessageCenter } from "@/utils.js"
  13. import infiniteScroll from 'vue-infinite-scroll'
  14. console.log(`version: ${process.env.VUE_APP_VERSION}`)
  15. // 供全局使用的audio节点
  16. const audioNode = document.createElement("audio")
  17. audioNode.id = 'global-audio'
  18. audioNode.style.display = 'none'
  19. audioNode.loop = true
  20. document.body.appendChild(audioNode)
  21. const uaParser = new UAParser()
  22. const uaInfo = uaParser.getResult()
  23. console.log(uaInfo)
  24. Vue.prototype.$uaInfo = uaInfo
  25. if (uaInfo.browser && uaInfo.browser.name === 'WeChat') {
  26. Vue.prototype.$isWeChat = true
  27. }
  28. if (uaInfo.browser && uaInfo.browser.name === 'Safari') {
  29. Vue.prototype.$isSafari = true
  30. }
  31. if (uaInfo.device.type !== 'mobile' && window.innerWidth > window.innerHeight) {
  32. if (['#/lookGoods', '#/relics-appr-no-exit', '#/relic-detail'].includes(location.hash)) {
  33. location.replace(process.env.VUE_APP_PC_URL_ONLY_RELICS)
  34. } else if (location.hash.includes('#/info/')) {
  35. location.replace(location.href.replace('/YHTM/', '/YHT/'))
  36. } else {
  37. location.replace(process.env.VUE_APP_PC_URL)
  38. }
  39. }
  40. Vue.prototype.$globalConfig = globalConfig
  41. Vue.prototype.$cdnPath = process.env.VUE_APP_CDN_PATH
  42. Vue.prototype.$swkkHotspotVideoAudioPath = process.env.VUE_APP_SWKK_HOTSPOT_VIDEO_AUDIO_PATH
  43. Vue.prototype.$msgCenter = new MessageCenter()
  44. const idealWindowInnerWidth = 1125 // 设计稿的宽度
  45. const idealRootFontSize = 24 // 设计稿里选择的根元素尺寸
  46. let windowWidthLast = window.innerWidth
  47. let windowHeightLast = window.innerHeight
  48. function onResize() {
  49. Vue.prototype.$oneRemToPx = window.innerWidth * idealRootFontSize / idealWindowInnerWidth
  50. document.documentElement.style.fontSize = Vue.prototype.$oneRemToPx + 'px'
  51. if (window.innerWidth === windowWidthLast) {
  52. // 发生了高度变化,认为发生了软键盘显隐
  53. if (uaInfo.os.name === 'Android') {
  54. if (window.innerHeight < windowHeightLast) {
  55. Vue.prototype.$msgCenter.publish('need-hide-bottom-bar')
  56. } else if (window.innerHeight > windowHeightLast) {
  57. Vue.prototype.$msgCenter.publish('need-show-bottom-bar')
  58. }
  59. }
  60. }
  61. windowWidthLast = window.innerWidth
  62. windowHeightLast = window.innerHeight
  63. }
  64. onResize()
  65. window.addEventListener('resize', () => {
  66. onResize()
  67. })
  68. // 禁用上下文菜单
  69. document.oncontextmenu = function(e) {
  70. e.preventDefault()
  71. }
  72. Vue.config.productionTip = false
  73. Vue.use(clickOutside)
  74. Vue.use(Viewer)
  75. Vue.use(VueLazyload)
  76. Vue.use(infiniteScroll)
  77. new Vue({
  78. router,
  79. store,
  80. render: h => h(App)
  81. }).$mount('#app')