From cd260cfbcfa88047a31f0fc2197bb980b7a2562f Mon Sep 17 00:00:00 2001 From: harrywan <445436867@qq.com> Date: Tue, 7 Jun 2022 17:29:24 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20qiankun=20=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=E9=97=AE=E9=A2=98=20(#126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复乾坤插件内存问题 * fix: 多页签时关闭页面需要清除缓存 * feat: 乾坤增加entry配置,用于区别同一name不同位置用法 * docs: 去掉文档 * fix: preset-build-in的route api 兼容 * fix: 修复问题 * docs: 更新w文档 * fix: 变更api --- docs/reference/api/README.md | 1 - docs/reference/plugin/dev/api.md | 2 +- docs/reference/plugin/plugins/qiankun.md | 21 ++++++++++++++++ .../src/runtime/views/MultiTabProvider.vue | 25 +++++++++++++------ .../examples/app1/src/pages/app1/index.vue | 1 + .../examples/app1/src/pages/app1/test.vue | 1 + .../examples/main/src/pages/index.vue | 3 ++- .../src/main/modifyRoutes.js | 5 ++-- .../src/main/runtime/MicroApp.tpl | 23 +++++++++++------ .../main/runtime/MicroAppWithMemoHistory.tpl | 1 + .../runtime/getMicroAppRouteComponent.tpl | 3 ++- .../src/micro/runtime/lifecycles.tpl | 20 ++++++++++++--- .../src/micro/runtime/runtime.tpl | 17 ++++++------- .../src/plugins/generateFiles/fes/fes.tpl | 1 + .../plugins/misc/route/template/routes.tpl | 5 +--- 15 files changed, 91 insertions(+), 38 deletions(-) diff --git a/docs/reference/api/README.md b/docs/reference/api/README.md index 47c7b8ad..a33f6555 100644 --- a/docs/reference/api/README.md +++ b/docs/reference/api/README.md @@ -74,7 +74,6 @@ Fes.js 路由基于 [Vue Router 4.0](https://next.router.vuejs.org/introduction. 返回当前 `router` 实例。 ```js import { getRouter } from "@fesjs/fes"; - const router = getRouter(); router.push(); ``` diff --git a/docs/reference/plugin/dev/api.md b/docs/reference/plugin/dev/api.md index 70209931..9c70905b 100644 --- a/docs/reference/plugin/dev/api.md +++ b/docs/reference/plugin/dev/api.md @@ -301,7 +301,7 @@ import { access, useAccess } from '@fesjs/fes'; ```js api.addCoreExports(() => [ { - specifiers: ['getRoutes', 'getRouter', 'getHistory', 'destroyRouter'], + specifiers: ['getRoutes'], source: absCoreFilePath } ]); diff --git a/docs/reference/plugin/plugins/qiankun.md b/docs/reference/plugin/plugins/qiankun.md index 61706c49..06c98428 100644 --- a/docs/reference/plugin/plugins/qiankun.md +++ b/docs/reference/plugin/plugins/qiankun.md @@ -269,3 +269,24 @@ export default { - 主应用使用 props 的模式传递数据(参考主应用装载子应用配置一节) - 子应用在生命周期钩子中获取 props 消费数据(参考子应用运行时配置一节) + + +### MicroApp +| 属性 | 说明 | 类型 | 默认值 | +| ---- | ----------- | ------------- | ---------- | +| name | 子应用名称,传入`qiankun.main.apps`配置中的`name` | String | - | +| settings | 子应用配置信息 | Object | {} | +| props | 传入子应用的参数 | Object | {} | +| lifeCycles | 子应用生命周期钩子 | Object | {} | +| cacheName | 子应用缓存名称,配置后根据`name`+`cacheName`缓存子应用实例 | Object | - | + + +### MicroAppWithMemoHistory +| 属性 | 说明 | 类型 | 默认值 | +| ---- | ----------- | ------------- | ---------- | +| name | 子应用名称,传入`qiankun.main.apps`配置中的`name` | String | - | +| settings | 子应用配置信息 | Object | {} | +| props | 传入子应用的参数 | Object | {} | +| lifeCycles | 子应用生命周期钩子 | Object | {} | +| cacheName | 子应用缓存名称,配置后根据`name`+`cacheName`缓存子应用实例 | Object | - | +| url | 子应用的路由地址 | String | - | \ No newline at end of file diff --git a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue index 128e4bd7..c3e027c6 100644 --- a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue +++ b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue @@ -31,8 +31,11 @@ - - + + @@ -68,11 +71,12 @@ export default { return { path: _route.path, route: _route, - name: _route.meta.name, + name: _route.meta.name ?? _route.name, title: computed(() => transTitle(title)), key: getKey() }; }; + const keepAlivePages = ref([]); const route = useRoute(); const router = useRouter(); @@ -122,6 +126,12 @@ export default { } list.splice(index, 1); pageList.value = list; + const _keepAlivePages = [...keepAlivePages.value]; + const keepIndex = _keepAlivePages.indexOf(selectedPage.name); + if (keepIndex !== -1) { + _keepAlivePages.splice(keepIndex, 1); + } + keepAlivePages.value = _keepAlivePages; }; const reloadPage = (path) => { const selectedPage = findPage(path || unref(route.path)); @@ -132,6 +142,7 @@ export default { const closeOtherPage = (path) => { const selectedPage = findPage(path || unref(route.path)); pageList.value = [selectedPage]; + keepAlivePages.value = [selectedPage.name]; }; const getPageKey = (_route) => { const selectedPage = findPage(_route.path); @@ -151,10 +162,10 @@ export default { default: } }; - const keepAlivePages = ref([]); - const getComponent = (Component, _route) => { - if (_route.meta['keep-alive']) { - const name = _route.meta?.name || _route.name; + + const getComponent = (Component, _route, isKeep = false) => { + if (isKeep || _route.meta['keep-alive']) { + const name = _route.meta?.name ?? _route.name; if (name) { // 修改组件的 name Component.type.name = name; diff --git a/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue index ef9b2005..5dbfb5b9 100644 --- a/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue +++ b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue @@ -1,6 +1,7 @@ diff --git a/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue index f20e10fd..746abb88 100644 --- a/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue +++ b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue @@ -1,6 +1,7 @@ diff --git a/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue b/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue index 7e91d6fb..39dde730 100644 --- a/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue +++ b/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue @@ -1,9 +1,10 @@