提交 | 用户 | 时间
|
820397
|
1 |
// 引入unocss css |
H |
2 |
import '@/plugins/unocss' |
|
3 |
|
|
4 |
// 导入全局的svg图标 |
|
5 |
import '@/plugins/svgIcon' |
|
6 |
|
|
7 |
// 初始化多语言 |
|
8 |
import { setupI18n } from '@/plugins/vueI18n' |
|
9 |
|
|
10 |
// 引入状态管理 |
|
11 |
import { setupStore } from '@/store' |
|
12 |
|
|
13 |
// 全局组件 |
|
14 |
import { setupGlobCom } from '@/components' |
|
15 |
|
|
16 |
// 引入 element-plus |
|
17 |
import { setupElementPlus } from '@/plugins/elementPlus' |
|
18 |
|
|
19 |
// 引入 form-create |
|
20 |
import { setupFormCreate } from '@/plugins/formCreate' |
|
21 |
|
|
22 |
// 引入全局样式 |
|
23 |
import '@/styles/index.scss' |
|
24 |
|
|
25 |
// 引入动画 |
|
26 |
import '@/plugins/animate.css' |
|
27 |
|
|
28 |
// 路由 |
|
29 |
import router, { setupRouter } from '@/router' |
|
30 |
|
|
31 |
// 权限 |
|
32 |
import { setupAuth } from '@/directives' |
|
33 |
|
|
34 |
import { createApp } from 'vue' |
|
35 |
|
|
36 |
import App from './App.vue' |
|
37 |
|
|
38 |
import './permission' |
|
39 |
|
|
40 |
import '@/plugins/tongji' // 百度统计 |
|
41 |
import Logger from '@/utils/Logger' |
|
42 |
|
|
43 |
import VueDOMPurifyHTML from 'vue-dompurify-html' // 解决v-html 的安全隐患 |
|
44 |
|
e7305d
|
45 |
import WujieVue from 'wujie-vue3' |
H |
46 |
|
|
47 |
const { setupApp } = WujieVue |
|
48 |
|
|
49 |
import { micros, getUrl } from '@/utils/micors' |
|
50 |
|
|
51 |
import lifecycles from '@/utils/lifecycles' // 生命周期函数 |
|
52 |
|
820397
|
53 |
// 创建实例 |
H |
54 |
const setupAll = async () => { |
|
55 |
const app = createApp(App) |
|
56 |
|
|
57 |
await setupI18n(app) |
|
58 |
|
|
59 |
setupStore(app) |
|
60 |
|
|
61 |
setupGlobCom(app) |
|
62 |
|
|
63 |
setupElementPlus(app) |
|
64 |
|
|
65 |
setupFormCreate(app) |
|
66 |
|
|
67 |
setupRouter(app) |
|
68 |
|
|
69 |
setupAuth(app) |
|
70 |
|
|
71 |
await router.isReady() |
|
72 |
|
|
73 |
app.use(VueDOMPurifyHTML) |
|
74 |
|
e7305d
|
75 |
app.use(WujieVue) |
H |
76 |
|
820397
|
77 |
app.mount('#app') |
H |
78 |
} |
|
79 |
|
|
80 |
setupAll() |
|
81 |
|
e7305d
|
82 |
// 模拟接口查询,实现动动态子应用加载与动态路由添加 |
H |
83 |
const setMiro = () => |
|
84 |
new Promise((resolve) => { |
|
85 |
for (const value of micros) { |
|
86 |
const obj: any = { |
|
87 |
path: `/${value.name}`, |
|
88 |
name: value.name, |
|
89 |
component: () => import(`@/views/micro/index.vue`) |
|
90 |
} |
|
91 |
router.addRoute('home', obj) |
|
92 |
setupApp({ |
|
93 |
name: value.name, |
|
94 |
url: getUrl(value.name, micros), |
|
95 |
exec: true, |
|
96 |
...lifecycles |
|
97 |
}) |
|
98 |
} |
|
99 |
resolve(true) |
|
100 |
}) |
|
101 |
// eslint-disable-next-line require-await |
|
102 |
router.beforeEach(async (to, _from, next) => { |
|
103 |
if (router.getRoutes().length <= 3) { |
|
104 |
// 如果路由个数为基础路由,则说明没有进行路由和子应用添加,需要动态添加,添加完成,根据路由地址进行跳转 |
|
105 |
await setMiro() |
|
106 |
next({ |
|
107 |
path: to.path, |
|
108 |
query: { ...to.query } |
|
109 |
}) |
|
110 |
} else { |
|
111 |
next() |
|
112 |
} |
|
113 |
}) |
|
114 |
|
820397
|
115 |
Logger.prettyPrimary(`欢迎使用`, import.meta.env.VITE_APP_TITLE) |