app.js 2.0 KB

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