main.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import store from '@/store'
  4. import { pcRouter } from '@/router'
  5. import { Loading } from 'element-ui'
  6. import Invite from '@/components/popup/invite'
  7. import Avatar from '@/components/popup/avatar'
  8. import Info from '@/components/popup/userInfo'
  9. import otherInfo from '@/components/popup/otherInfo'
  10. import imgPreview from '@/components/popup/imgPreview'
  11. import packetGet from '@/components/popup/packetGet'
  12. import packetSend from '@/components/popup/packetSend'
  13. import Toast from '@/components/popup/toast'
  14. import VueClipboard from 'vue-clipboard2'
  15. import TWEEN from '@tweenjs/tween.js'
  16. import i18n from '@/util/lang/lang'
  17. // 全局自定义插件
  18. import '@/plugins/directive'
  19. Vue.use(Invite, store, pcRouter)
  20. Vue.use(Avatar, store, i18n)
  21. Vue.use(Info, store, i18n)
  22. Vue.use(otherInfo, store, pcRouter)
  23. Vue.use(packetGet, store)
  24. Vue.use(packetSend, store)
  25. Vue.use(Toast)
  26. Vue.use(VueClipboard)
  27. Vue.use(imgPreview)
  28. Vue.use(Loading)
  29. Vue.config.productionTip = false
  30. new Vue({
  31. render: h => h(App),
  32. store,
  33. i18n,
  34. router: pcRouter
  35. }).$mount('#app')
  36. // Setup the animation loop.
  37. function animate (time) {
  38. requestAnimationFrame(animate)
  39. TWEEN.update(time)
  40. }
  41. requestAnimationFrame(animate)
  42. if ('serviceWorker' in navigator) {
  43. navigator.serviceWorker.register('/sw.js').then(function (reg) {
  44. if (reg.installing) {
  45. console.log('Service worker installing')
  46. } else if (reg.waiting) {
  47. console.log('Service worker installed')
  48. } else if (reg.active) {
  49. console.log('Service worker active')
  50. }
  51. reg.addEventListener('updatefound', function () {
  52. if (navigator.serviceWorker.controller) {
  53. var installingWorker = reg.installing
  54. installingWorker.onstatechange = function () {
  55. console.log('installingWorker.state:' + installingWorker.state)
  56. switch (installingWorker.state) {
  57. case 'installed':
  58. // MessageBox.confirm('新的内容已更新完毕,立即刷新页面?', '提示', {
  59. // confirmButtonText: '确定',
  60. // cancelButtonText: '取消'
  61. // }).then(() => {
  62. // location.reload()
  63. // }).catch(() => {})
  64. break
  65. case 'redundant':
  66. break
  67. default:
  68. }
  69. }
  70. }
  71. })
  72. if (navigator.serviceWorker) {
  73. navigator.serviceWorker.addEventListener('statechange', function (e) {
  74. console.log('statechange: ', e.target.state)
  75. })
  76. }
  77. }).catch(function (error) {
  78. // registration failed
  79. console.log('Registration failed with ' + error)
  80. })
  81. }