import './public-path' import { createApp } from 'vue' import App from './App.vue' import router, { routes } from './router' import '@/router/before' import { createPinia } from 'pinia' import antd from 'ant-design-vue' import UsePro from './utils/UsePro' import { assets } from '@/utils/static' import cronAnt from '@vue-js-cron/ant' import '@vue-js-cron/ant/dist/ant.css' import 'normalize.css' import { keyboard } from '@/directives/index' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' const pinia = createPinia() pinia.use(piniaPluginPersistedstate) // `trace` 是组件层级结构的追踪 // app.config.warnHandler = (msg, instance, trace) => { // } // 全局注册一些辅助性的函数 desc在 global.d.ts下 window.Map.prototype.toArray = function () { if (this === null || this === undefined) return this return Array.from(this, ([key, value]) => { if (typeof value === 'object') { return { key, ...value } } else { return { key, value } } }) } window.Array.prototype.toMap = function (key: string, valueKey?: string): Map { if (this && typeof this[0] !== 'object') throw new Error('仅支持Record[]格式的数组') else if (this == null || this === undefined) return this const _map = new Map() this.forEach(item => { _map.set(item[key], valueKey ? item[valueKey] : item) }) return _map } let _router = router let instance: any = null const render = (props: any = {}) => { const { container, data } = props if (window.__POWERED_BY_QIANKUN__) { data.store.useJLYAppRouter().setChildrenSiderRoutes(routes.map(item => item.children).filter(_ => !!_)[0]) } instance = createApp(App) instance.use(router) .use(pinia) .use(antd) .use(UsePro) .use(cronAnt) .directive('keyboard', keyboard) .provide('useStaticImg', assets) instance.mount(container ? container.querySelector('#cloudlink-ui') : '#cloudlink-ui') as any } console.log('是否是window.__POWERED_BY_QIANKUN__:', window.__POWERED_BY_QIANKUN__) /** eslint-disable */ if (!window.__POWERED_BY_QIANKUN__) { render() } export async function bootstrap () { console.log('cloudlink app bootstraped') } export async function mount (props) { console.log('cloudlink 子应用 挂载') render(props) } export async function unmount () { // if (instance.$destroy) { instance.unmount() instance._container.innerHTML = '' instance = null _router = null as any // } }