main.js 2.2 KB

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