app.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import Vue from 'vue';
  2. import App from './app.vue';
  3. import router from './router';
  4. import mixin from './view/mixin.js';
  5. import Conf from '@/config.json';
  6. import NutUI from '@/nutui';
  7. // import en from '../../src/locales/lang/en-US';
  8. // import demoEN from './lang/en-US';
  9. import * as OfflinePluginRuntime from 'offline-plugin/runtime';
  10. import './asset/css/common.scss';
  11. import './asset/img/logo_share.png';
  12. Vue.config.productionTip = false;
  13. // Object.assign(en, demoEN);
  14. // Vue.use(NutUI, {
  15. // locale: 'en-US',
  16. // lang: en
  17. // });
  18. NutUI.install(Vue);
  19. //Vue.locale = () => {};
  20. // const i18n = new VueI18n({
  21. // locale: 'en-US',
  22. // messages: {
  23. // 'en-US': en
  24. // }
  25. // });
  26. // 兼容vue-i18n
  27. // Vue.locale = () => {};
  28. // const i18n = new VueI18n({
  29. // locale: 'en-US',
  30. // messages: {
  31. // 'en-US': en
  32. // }
  33. // });
  34. // Vue.prototype.$i18n = i18n;
  35. // Vue.use(VueI18n);
  36. Vue.mixin(mixin);
  37. const app = new Vue({
  38. el: '#demo',
  39. router,
  40. components: { App },
  41. template: '<App/>'
  42. });
  43. OfflinePluginRuntime.install({
  44. onUpdating: () => {
  45. console.log('SW Event:', 'onUpdating');
  46. },
  47. onUpdateReady: () => {
  48. console.log('SW Event:', 'onUpdateReady');
  49. OfflinePluginRuntime.applyUpdate();
  50. },
  51. onUpdated: () => {
  52. console.log('SW Event:', 'onUpdated');
  53. console.log('PWA缓存有更新,需要刷新页面');
  54. app.$dialog({
  55. title: "当前页面有新版本,请刷新",
  56. noCloseBtn: true,
  57. noOkBtn: true,
  58. cancelBtnTxt: "刷新页面",
  59. closeOnClickModal:false,
  60. lockBgScroll:true,
  61. onCancelBtn(){
  62. window.location.reload();
  63. }
  64. });
  65. //window.location.reload();
  66. },
  67. onUpdateFailed: () => {
  68. console.log('SW Event:', 'onUpdateFailed');
  69. }
  70. });
  71. Vue.prototype.NUTCONF = Conf;
  72. let pageLoading = app.$toast.loading();
  73. router.beforeEach((to, from, next) => {
  74. pageLoading.show();
  75. next();
  76. })
  77. router.beforeResolve((to, from, next) => {
  78. next();
  79. });
  80. router.afterEach((to, from) => {
  81. pageLoading.hide();
  82. });