// 引入unocss css
|
import '@/plugins/unocss'
|
|
// 导入全局的svg图标
|
import '@/plugins/svgIcon'
|
|
// 初始化多语言
|
import { setupI18n } from '@/plugins/vueI18n'
|
|
// 引入状态管理
|
import { setupStore } from '@/store'
|
|
// 全局组件
|
import { setupGlobCom } from '@/components'
|
|
// 引入 element-plus
|
import { setupElementPlus } from '@/plugins/elementPlus'
|
|
// 引入 form-create
|
import { setupFormCreate } from '@/plugins/formCreate'
|
|
// 引入全局样式
|
import '@/styles/index.scss'
|
|
// 引入动画
|
import '@/plugins/animate.css'
|
|
// 路由
|
import router, { setupRouter } from '@/router'
|
|
// 权限
|
import { setupAuth } from '@/directives'
|
|
import { createApp } from 'vue'
|
|
import App from './App.vue'
|
|
import './permission'
|
|
import '@/plugins/tongji' // 百度统计
|
import Logger from '@/utils/Logger'
|
|
import VueDOMPurifyHTML from 'vue-dompurify-html' // 解决v-html 的安全隐患
|
|
import WujieVue from 'wujie-vue3'
|
|
const { setupApp } = WujieVue
|
|
import hostMap from "@/utils/hostMap";
|
|
import { micros } from '@/utils/micors'
|
|
import lifecycles from '@/utils/lifecycles' // 生命周期函数
|
|
// import credentialsFetch from "@/utils/fetch";
|
|
const isProduction = process.env.NODE_ENV === "production";
|
|
// 创建实例
|
const setupAll = async () => {
|
const app = createApp(App)
|
|
await setupI18n(app)
|
|
setupStore(app)
|
|
setupGlobCom(app)
|
|
setupElementPlus(app)
|
|
setupFormCreate(app)
|
|
setupRouter(app)
|
|
setupAuth(app)
|
|
await router.isReady()
|
|
app.use(VueDOMPurifyHTML)
|
|
app.use(WujieVue)
|
|
app.mount('#app')
|
}
|
|
setupAll()
|
|
const degrade = window.localStorage.getItem("degrade") === "true" || !window.Proxy || !window.CustomElementRegistry;
|
const props = {
|
jump: (name) => {
|
router.push({ name });
|
},
|
};
|
|
// 模拟接口查询,实现动动态子应用加载与动态路由添加
|
const setMiro = () =>
|
new Promise((resolve) => {
|
for (const value of micros) {
|
const obj: any = {
|
path: `/${value.name}`,
|
name: value.name,
|
component: () => import(`@/views/micro/index.vue`)
|
}
|
router.addRoute('home', obj)
|
const attrs = isProduction ? { src: hostMap("//localhost/") } : {};
|
setupApp({
|
name: "fast",
|
url: hostMap("//localhost:90/"),
|
attrs,
|
exec: true,
|
alive: true,
|
plugins: [{ cssExcludes: ["https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"] }],
|
props,
|
// 引入了的第三方样式不需要添加credentials
|
// fetch: (url, options) =>
|
// url.includes(hostMap("//localhost:90/")) ? credentialsFetch(url, options) : window.fetch(url, options),
|
degrade,
|
...lifecycles,
|
});
|
// setupApp({
|
// name: value.name,
|
// url: getUrl(value.name, micros),
|
// exec: true,
|
// ...lifecycles
|
// })
|
}
|
resolve(true)
|
})
|
// eslint-disable-next-line require-await
|
router.beforeEach(async (to, _from, next) => {
|
if (router.getRoutes().length <= 3) {
|
// 如果路由个数为基础路由,则说明没有进行路由和子应用添加,需要动态添加,添加完成,根据路由地址进行跳转
|
await setMiro()
|
next({
|
path: to.path,
|
query: { ...to.query }
|
})
|
} else {
|
next()
|
}
|
})
|
|
Logger.prettyPrimary(`欢迎使用`, import.meta.env.VITE_APP_TITLE)
|