diff --git a/.fes.js b/.fes.js index 94ba5dfe..6bd0503d 100644 --- a/.fes.js +++ b/.fes.js @@ -4,7 +4,7 @@ * @Autor: 地虎降天龙 * @Date: 2023-10-16 10:53:09 * @LastEditors: 地虎降天龙 - * @LastEditTime: 2025-04-01 15:43:12 + * @LastEditTime: 2025-04-02 09:30:39 */ // import { resolve } from 'path'; import { join } from 'path' @@ -104,7 +104,12 @@ export default defineBuildConfig({ }, }, }, - server: { + server: { + server: { + headers: { + 'Access-Control-Allow-Origin': '*', + }, + }, host: '0.0.0.0', proxy: { '/resource.cos': { diff --git a/public/plugins/qiankunTvt/preview/events.png b/public/plugins/qiankunTvt/preview/events.png new file mode 100644 index 00000000..d2f14610 Binary files /dev/null and b/public/plugins/qiankunTvt/preview/events.png differ diff --git a/public/plugins/qiankunTvt/preview/theBasic.png b/public/plugins/qiankunTvt/preview/theBasic.png new file mode 100644 index 00000000..02b1aa7a Binary files /dev/null and b/public/plugins/qiankunTvt/preview/theBasic.png differ diff --git a/src/app.jsx b/src/app.jsx index fce8aa5b..86decf75 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -4,7 +4,7 @@ * @Autor: 地虎降天龙 * @Date: 2023-10-16 10:53:09 * @LastEditors: 地虎降天龙 - * @LastEditTime: 2025-04-01 10:43:48 + * @LastEditTime: 2025-04-02 11:00:19 */ import { defineRuntimeConfig, useModel } from '@fesjs/fes' import { FMenu } from '@fesjs/fes-design' @@ -20,17 +20,24 @@ import { addCollection } from 'iconify-icon' import uimIcons from '@iconify/json/json/uim.json' import lineMdIcons from '@iconify/json/json/line-md.json' import wiIcons from '@iconify/json/json/wi.json' +import { useQiankunTvtStore } from 'PLS/qiankunTvt/stores/index' +import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper' import UserCenter from '@/components/forPreview/userCenter.vue' import PageLoading from '@/components/pageLoading.vue' + addCollection(uimIcons) addCollection(lineMdIcons) addCollection(wiIcons) +let qiankunTvtStore = null export default defineRuntimeConfig({ beforeRender: { loading: , action () { + if (qiankunWindow.__POWERED_BY_QIANKUN__) { + qiankunTvtStore = useQiankunTvtStore() + } const { signin, getMenu } = useModel('forPreview') signin() if ((process.env.FES_APP_PLUGINS === 'true' && process.env.NODE_ENV === 'development') || process.env.FES_APP_ONLINE_API) { @@ -51,11 +58,13 @@ export function layout (layoutConfig) { } } + export function onAppCreated ({ app }) { app.use(FMenu) app.use(Tres) window.$vue = app + // if (process.env.FES_APP_PLUGINS === 'true') { console.log(chalk.hex('#1c86e5')(` ░▒▓████████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓████████▓▒░ ░▒▓█▓▒░ ░▒▓███████▓▒░ @@ -152,14 +161,21 @@ export function modifyRoute (memo) { } } -export const qiankun = { +export const qiankun = { // 应用加载之前 async bootstrap (props) { console.log('son TvT.js bootstrap', props) }, // 应用 render 之前触发 async mount (props) { + console.log('son TvT.js mount', props) + if (props) { + props.onGlobalStateChange((state, prev) => { + qiankunTvtStore.setGlobalState(state) + }) + window.qiankunProps = props + } }, // 当 props 更新时触发 async update (props) { diff --git a/src/plugins/qiankunTvt/config.js b/src/plugins/qiankunTvt/config.js new file mode 100644 index 00000000..a59408d5 --- /dev/null +++ b/src/plugins/qiankunTvt/config.js @@ -0,0 +1,38 @@ +/* + * @Description: + * @Version: 1.668 + * @Autor: 地虎降天龙 + * @Date: 2025-04-01 15:50:33 + * @LastEditors: 地虎降天龙 + * @LastEditTime: 2025-04-02 11:25:25 + */ +export default { + name: 'qiankunTvt', + title: '微前端qiankun', + intro: '本案例结合qiankun微前端框架,演示了如何把tvt以子应用引入到自己的主应用框架中,并且实现了qiankun的沙箱隔离机制。qiankun是一个基于single-spa的微前端框架,支持多种主应用和子应用的组合方式。', + version: '1.0.0', + author: '地虎降天龙', + website: 'https://gitee.com/hawk86104', + state: 'active', + creatTime: '2025-04-01', + updateTime: '2025-04-01', + require: [], + preview: [ + { + src: 'plugins/qiankunTvt/preview/theBasic.png', + type: 'img', + name: 'theBasic', + title: '简单实例', + disableFPSGraph: false, + disableSrcBtn: true, + }, + { + src: 'plugins/qiankunTvt/preview/events.png', + type: 'img', + name: 'events', + title: '通讯实例', + disableFPSGraph: false, + disableSrcBtn: true, + }, + ], +} diff --git a/src/plugins/qiankunTvt/pages/events.vue b/src/plugins/qiankunTvt/pages/events.vue new file mode 100644 index 00000000..9ffc7619 --- /dev/null +++ b/src/plugins/qiankunTvt/pages/events.vue @@ -0,0 +1,113 @@ + + + diff --git a/src/plugins/qiankunTvt/pages/theBasic.vue b/src/plugins/qiankunTvt/pages/theBasic.vue index 97090669..ab775585 100644 --- a/src/plugins/qiankunTvt/pages/theBasic.vue +++ b/src/plugins/qiankunTvt/pages/theBasic.vue @@ -24,6 +24,7 @@ +

请通过qiankun主程序访问此页面