main.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import store from '@/store'
  4. import { h5Router } from '@/router'
  5. import Invite from '@/components/popup/invite'
  6. import Avatar from '@/components/popup/avatar'
  7. import Info from '@/components/popup/userInfo'
  8. import otherInfo from '@/components/popup/otherInfo'
  9. import imgPreview from '@/components/popup/imgPreview'
  10. import packetGet from '@/components/popup/packetGet'
  11. import packetSend from '@/components/popup/packetSend'
  12. import Toast from '@/components/popup/toast'
  13. import VueClipboard from 'vue-clipboard2'
  14. import directive from '@/plugins/directive'
  15. import TWEEN from '@tweenjs/tween.js'
  16. import { register } from 'register-service-worker'
  17. import { MessageBox } from 'element-ui'
  18. Vue.use(Invite, store)
  19. Vue.use(Avatar, store)
  20. Vue.use(Info, store)
  21. Vue.use(otherInfo, store)
  22. Vue.use(packetGet, store)
  23. Vue.use(packetSend, store)
  24. Vue.use(Toast)
  25. Vue.use(VueClipboard)
  26. Vue.use(directive)
  27. Vue.use(imgPreview)
  28. Vue.config.productionTip = false
  29. new Vue({
  30. render: h => h(App),
  31. router: h5Router,
  32. store
  33. }).$mount('#app')
  34. // Setup the animation loop.
  35. function animate (time) {
  36. requestAnimationFrame(animate)
  37. TWEEN.update(time)
  38. }
  39. requestAnimationFrame(animate)
  40. if (process.env.NODE_ENV === 'production') {
  41. let updatefound = false
  42. register('/sw.js', {
  43. ready () {
  44. console.log(
  45. 'App is being served from cache by a service worker.\n' +
  46. 'For more details, visit https://goo.gl/AFskqB'
  47. )
  48. },
  49. registered () {
  50. console.log('Service worker has been registered.')
  51. },
  52. cached () {
  53. console.log('Content has been cached for offline use.')
  54. },
  55. updatefound () {
  56. updatefound = true
  57. console.log('New content is downloading.')
  58. },
  59. updated () {
  60. if (updatefound) {
  61. MessageBox.confirm('新的内容已更新完毕,立即刷新页面?', '提示', {
  62. confirmButtonText: '确定',
  63. cancelButtonText: '取消'
  64. }).then(() => {
  65. location.reload() && window.location.reload()
  66. }).catch(() => {})
  67. }
  68. },
  69. offline () {
  70. console.log('No internet connection found. App is running in offline mode.')
  71. },
  72. error (error) {
  73. console.error('Error during service worker registration:', error)
  74. }
  75. })
  76. }