main.ts 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9
import { install as installCore } from '@ibiz-template/core';
import { install as installRuntime } from '@ibiz-template/runtime';
import { install as installDefaultViewLayout } from '@ibiz-template/mob-theme';
import {
  LoadingUtil,
  MessageUtil,
  ModalUtil,
  NotificationUtil,
  OpenViewUtil,
10
  ConfirmUtil,
11 12
  OverlayController,
} from '@ibiz-template/mob-vue3-components';
13
import { OverlayContainer, PluginFactory } from '@ibiz-template/vue3-util';
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
import App from './App';
import { attachEnvironmentConfig } from './attach-environment-config';
import { createVueApp } from './create-vue-app';
import { AppRouter } from '@/router';
import { UnauthorizedHandler } from './util';

async function createApp(): Promise<void> {
  OverlayContainer.createVueApp = createVueApp;

  installCore();
  installRuntime();

  // 插件对象初始化放置在创建 app 之前
  ibiz.plugin = new PluginFactory();

  const app = createVueApp(App);

  // 全局 window 异常处理
  window.onerror = function (
    _event: Event | string,
    _source?: string,
    _lineno?: number,
    _colno?: number,
    error?: Error,
  ) {
    if (error) {
      ibiz.util.error.handle(error);
    }
  };

  // 全局 promise 异常处理
  window.addEventListener('unhandledrejection', function (event) {
    // 阻止继续冒泡
    event.preventDefault();
    // 获取到未处理的promise对象
    event.promise.catch(err => {
      ibiz.util.error.handle(err);
    });
  });

  await attachEnvironmentConfig();

  const router = AppRouter.getRouter();

  app.use(router);

  ibiz.openView = new OpenViewUtil(router);
  ibiz.message = new MessageUtil();
  ibiz.modal = new ModalUtil();
63
  ibiz.confirm = new ConfirmUtil();
64 65 66 67 68 69 70
  ibiz.notification = new NotificationUtil();
  ibiz.loading = new LoadingUtil();
  ibiz.overlay = new OverlayController();
  ibiz.util.error.register(new UnauthorizedHandler());
  installDefaultViewLayout((key, model) => {
    ibiz.util.layoutPanel.register(key, model);
  });
71
  await ibiz.i18n.init();
72 73 74 75 76

  app.mount('#app');
}

createApp();