刘光辉
5 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { createApp, watchEffect } from 'vue';
import gridLayout from 'vue-grid-layout';
import { autoConnect, hiprint } from 'vue-plugin-hiprint';
 
import '@jnpf/bpmn/style';
import { setupLoadingDirective } from '@jnpf/ui';
import { registerDraggable, registerResizable } from '@jnpf/ui/modal';
import '@jnpf/ui/style';
import '@jnpf/univer/style';
import { mitt } from '@jnpf/utils';
 
import { registerAccessDirective } from '@vben/access';
import { registerLoadingDirective } from '@vben/common-ui';
import { useAppConfig } from '@vben/hooks';
import { preferences } from '@vben/preferences';
import { initStores, useUserStore } from '@vben/stores';
import '@vben/styles';
import '@vben/styles/antd';
 
import { VueQueryPlugin } from '@tanstack/vue-query';
import { useTitle } from '@vueuse/core';
 
import { getSystemBrand } from '#/api/system/sysConfig';
import { registerGlobComp } from '#/components/registerGlobComp';
import { $t, setupI18n } from '#/locales';
import { router } from '#/router';
import { useBaseStore } from '#/store';
import { getJnpfAppEnCode, getJnpfRouteTitle } from '#/utils/jnpf';
import { applyFavicon, normalizeBrandPath, resolveBrandAssetUrl } from '#/utils/systemBrand';
 
import { initComponentAdapter } from './adapter/component';
import App from './app.vue';
 
import '#/design/index.scss';
// 常驻连接本机 Hiprint 客户端,供静默打印直接复用。
hiprint.init();
autoConnect();
 
const emitter = mitt();
 
async function bootstrap(namespace: string) {
  // 初始化组件适配器
  await initComponentAdapter();
 
  const app = createApp(App);
 
  app.provide('emitter', emitter); // 注入provider
 
  // 注册v-spinning指令
  registerLoadingDirective(app, {
    spinning: 'spinning',
  });
 
  // 注册v-draggable指令并启用全局拖拽
  registerDraggable(app);
 
  // 注册v-resizable指令并启用全局缩放
  registerResizable(app);
 
  // 国际化 i18n 配置
  await setupI18n(app);
 
  // 注册全局组件
  registerGlobComp(app);
 
  // 配置 pinia-tore
  await initStores(app, { namespace, isCommonToken: true, sessionAuth: true });
 
  const baseStore = useBaseStore();
  const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
  baseStore.setSysConfig({ loginBackground: '', loginIcon: '', logoIcon: '' });
  try {
    const res = await getSystemBrand();
    baseStore.setSysConfig({
      ...res?.data,
      faviconIcon: normalizeBrandPath(res?.data?.faviconIcon),
    });
  } catch {
    // 品牌配置不可用时继续启动,页面按空配置规则展示。
  }
 
  watchEffect(() => {
    const faviconUrl = resolveBrandAssetUrl(baseStore.getSysConfig.faviconIcon, apiURL);
    void applyFavicon(faviconUrl);
  });
 
  // 安装权限指令
  registerAccessDirective(app);
 
  // 安装loading指令
  setupLoadingDirective(app);
 
  // 初始化 tippy
  const { initTippy } = await import('@vben/common-ui/es/tippy');
  initTippy(app);
 
  // 配置路由及路由守卫
  app.use(router);
 
  // 配置@tanstack/vue-query
  app.use(VueQueryPlugin);
 
  // 配置Motion插件
  const { MotionPlugin } = await import('@vben/plugins/motion');
  app.use(MotionPlugin);
 
  // 动态更新标题
  watchEffect(() => {
    const userStore = useUserStore();
    const appEnCode = getJnpfAppEnCode();
 
    const userInfo = userStore.getUserInfo;
    const { title = '' } = baseStore.getSysConfig;
    let appTitle = title || preferences.app.name;
    if (appEnCode && !['teamwork', 'workFlow'].includes(appEnCode) && userInfo?.systemName) appTitle = userInfo?.systemName;
 
    if (preferences.app.dynamicTitle) {
      const route = router.currentRoute.value;
      const routeTitle = getJnpfRouteTitle(route.query) || (route?.meta?.i18nCode ? $t(route?.meta?.i18nCode, route?.meta?.title) : route?.meta?.title);
      const pageTitle = routeTitle ? ` ${routeTitle} - ${appTitle} ` : `${appTitle}`;
      useTitle(pageTitle);
    } else {
      useTitle(appTitle);
    }
  });
  app.use(gridLayout);
 
  app.mount('#app');
}
 
export { bootstrap };