diff --git a/packages/fes-plugin-layout/package.json b/packages/fes-plugin-layout/package.json
index 3b474dc7..e20386ef 100644
--- a/packages/fes-plugin-layout/package.json
+++ b/packages/fes-plugin-layout/package.json
@@ -34,7 +34,8 @@
"vue-router": "^4.0.1"
},
"dependencies": {
- "@fesjs/utils": "^3.0.1"
+ "@fesjs/utils": "^3.0.1",
+ "@vueuse/core": "^10.7.0"
},
"typings": "./types.d.ts"
}
diff --git a/packages/fes-plugin-layout/src/index.js b/packages/fes-plugin-layout/src/index.js
index 999ca432..5ff334de 100644
--- a/packages/fes-plugin-layout/src/index.js
+++ b/packages/fes-plugin-layout/src/index.js
@@ -1,5 +1,5 @@
-import { readFileSync } from 'fs';
-import { join } from 'path';
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
import { winPath } from '@fesjs/utils';
import { name } from '../package.json';
@@ -40,7 +40,7 @@ export default (api) => {
const iconNames = helper.getIconNamesFromMenu(userConfig.menus);
- const iconsString = iconNames.map((iconName) => `import { ${iconName} } from '@fesjs/fes-design/icon'`);
+ const iconsString = iconNames.map(iconName => `import { ${iconName} } from '@fesjs/fes-design/icon'`);
api.writeTmpFile({
path: join(namespace, 'icons.js'),
content: `
@@ -84,7 +84,7 @@ export default (api) => {
api.addPluginExports(() => [
{
- specifiers: ['Page', 'useTabTitle'],
+ specifiers: ['Page', 'useTabTitle', 'useLayout'],
source: join(namespace, 'index.js'),
},
]);
@@ -92,7 +92,7 @@ export default (api) => {
// 把 BaseLayout插入到路由配置中,作为根路由
// 添加 403 和 404 路由
api.modifyRoutes((routes) => {
- if (!routes.find((item) => item.path === '/403')) {
+ if (!routes.find(item => item.path === '/403')) {
routes.push({
path: '/403',
name: 'Exception403',
@@ -102,7 +102,7 @@ export default (api) => {
},
});
}
- if (!routes.find((item) => item.path === '/404')) {
+ if (!routes.find(item => item.path === '/404')) {
routes.push({
path: '/404',
name: 'Exception404',
diff --git a/packages/fes-plugin-layout/src/runtime/index.js b/packages/fes-plugin-layout/src/runtime/index.js
index 5117f920..f5738924 100644
--- a/packages/fes-plugin-layout/src/runtime/index.js
+++ b/packages/fes-plugin-layout/src/runtime/index.js
@@ -1,2 +1,3 @@
export { default as Page } from './views/page.vue';
export { useTabTitle } from './useTitle';
+export * from './useLayout';
diff --git a/packages/fes-plugin-layout/src/runtime/useLayout.js b/packages/fes-plugin-layout/src/runtime/useLayout.js
new file mode 100644
index 00000000..452cf17d
--- /dev/null
+++ b/packages/fes-plugin-layout/src/runtime/useLayout.js
@@ -0,0 +1,12 @@
+import { createSharedComposable } from '@vueuse/core';
+import { shallowReactive } from 'vue';
+
+function _useLayout() {
+ const state = shallowReactive({
+ closeTab: () => {},
+ });
+
+ return state;
+}
+
+export const useLayout = createSharedComposable(_useLayout);
diff --git a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue
index cec9349d..96b9e683 100644
--- a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue
+++ b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue
@@ -33,6 +33,7 @@ import { MoreOutlined, ReloadOutlined } from '@fesjs/fes-design/icon';
import { useRoute, useRouter } from '@@/core/coreExports';
import { transTitle } from '../helpers/pluginLocale';
import { deleteTitle, getTitle } from '../useTitle';
+import { useLayout } from '../useLayout';
import Page from './page.vue';
let i = 0;
@@ -53,6 +54,8 @@ export default {
const pageRef = ref();
const route = useRoute();
const router = useRouter();
+ const layoutState = useLayout();
+
const createPage = (_route) => {
const computedTitle = computed(() => {
const customTitle = unref(getTitle(_route.path));
@@ -104,6 +107,7 @@ export default {
}
};
const handleCloseTab = async (targetKey) => {
+ targetKey = targetKey || route.path;
const selectedPage = findPage(targetKey);
const list = [...pageList.value];
const index = list.indexOf(selectedPage);
@@ -121,6 +125,8 @@ export default {
pageRef.value.removeKeepAlive(selectedPage.name);
deleteTitle(selectedPage.path);
};
+ layoutState.closeTab = handleCloseTab;
+
const reloadPage = (path) => {
const selectedPage = findPage(path || unref(route.path));
if (selectedPage)
diff --git a/packages/fes-template/src/pages/editor.vue b/packages/fes-template/src/pages/editor.vue
index c4b192eb..a895987c 100644
--- a/packages/fes-template/src/pages/editor.vue
+++ b/packages/fes-template/src/pages/editor.vue
@@ -1,29 +1,35 @@
-
+
{{ json }}
+
{
"name": "editor",
"title": "$editor"
}
+