main.js 2.7 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('user agent: ', uaInfo)
  24. Vue.prototype.$uaInfo = uaInfo
  25. if (uaInfo.device.type === 'mobile') {
  26. Vue.prototype.$isMobile = true
  27. } else {
  28. Vue.prototype.$isMobile = false
  29. }
  30. if (uaInfo.browser && uaInfo.browser.name === 'WeChat') {
  31. Vue.prototype.$isWeChat = true
  32. }
  33. if (uaInfo.browser && uaInfo.browser.name === 'Safari') {
  34. Vue.prototype.$isSafari = true
  35. }
  36. // 酌情跳转到PC版
  37. // if (uaInfo.device.type !== 'mobile' && window.innerWidth > window.innerHeight) {
  38. // location.replace(process.env.VUE_APP_PC_URL)
  39. // }
  40. Vue.prototype.$origin = process.env.VUE_APP_ORIGIN
  41. Vue.prototype.$globalConfig = globalConfig
  42. Vue.prototype.$cdnPath = process.env.VUE_APP_CDN_PATH
  43. Vue.prototype.$msgCenter = new MessageCenter()
  44. // let windowWidthLast = window.innerWidth
  45. // let windowHeightLast = window.innerHeight
  46. // function onResize() {
  47. // if (window.innerWidth === windowWidthLast) {
  48. // // 发生了高度变化,认为发生了软键盘显隐
  49. // if (uaInfo.os.name === 'Android') {
  50. // if (window.innerHeight < windowHeightLast) {
  51. // Vue.prototype.$msgCenter.publish('need-hide-bottom-bar')
  52. // } else if (window.innerHeight > windowHeightLast) {
  53. // Vue.prototype.$msgCenter.publish('need-show-bottom-bar')
  54. // }
  55. // }
  56. // }
  57. // windowWidthLast = window.innerWidth
  58. // windowHeightLast = window.innerHeight
  59. // }
  60. // onResize()
  61. // window.addEventListener('resize', () => {
  62. // onResize()
  63. // })
  64. // 禁用上下文菜单
  65. document.oncontextmenu = function(e) {
  66. e.preventDefault()
  67. }
  68. Vue.config.productionTip = false
  69. Vue.use(clickOutside)
  70. Vue.use(Viewer)
  71. Vue.use(VueLazyload)
  72. Vue.use(infiniteScroll)
  73. new Vue({
  74. router,
  75. store,
  76. render: h => h(App)
  77. }).$mount('#app')
  78. // 必须在vue根组件挂载之后执行
  79. if (Vue.prototype.$isMobile) {
  80. document.getElementById('app').classList.add('mobile')
  81. }