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 './view/mixin.vue';
  7. import Conf from '../../src/config.json';
  8. import NutUI from '../../src/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. const app = new Vue({
  39. el: '#demo',
  40. router,
  41. components: { App },
  42. template: '<App/>'
  43. });
  44. OfflinePluginRuntime.install({
  45. onUpdating: () => {
  46. console.log('SW Event:', 'onUpdating');
  47. },
  48. onUpdateReady: () => {
  49. console.log('SW Event:', 'onUpdateReady');
  50. OfflinePluginRuntime.applyUpdate();
  51. },
  52. onUpdated: () => {
  53. console.log('SW Event:', 'onUpdated');
  54. console.log('PWA缓存有更新,需要刷新页面');
  55. app.$dialog({
  56. title: "您正在浏览的页面有更新,请刷新",
  57. noCloseBtn: true,
  58. noOkBtn: true,
  59. cancelBtnTxt: "刷新页面",
  60. closeOnClickModal:false,
  61. lockBgScroll:true,
  62. onCancelBtn(){
  63. window.location.reload();
  64. }
  65. });
  66. //window.location.reload();
  67. },
  68. onUpdateFailed: () => {
  69. console.log('SW Event:', 'onUpdateFailed');
  70. }
  71. });
  72. Vue.prototype.NUTCONF = Conf;
  73. let pageLoading = app.$toast.loading();
  74. router.beforeEach((to, from, next) => {
  75. pageLoading.show();
  76. next();
  77. })
  78. router.beforeResolve((to, from, next) => {
  79. next();
  80. });
  81. router.afterEach((to, from) => {
  82. pageLoading.hide();
  83. });