diff --git a/docs/reference/plugin/plugins/layout.md b/docs/reference/plugin/plugins/layout.md index 74251c78b..2ce3e70fc 100644 --- a/docs/reference/plugin/plugins/layout.md +++ b/docs/reference/plugin/plugins/layout.md @@ -313,7 +313,7 @@ export const layout = (layoutConfig, { initialState }) => ({ 比如: ```js -export const access = { +export const layout = { unAccessHandler({ to, next }) { const accesssIds = accessApi.getAccess(); if (to.path === '/404') { @@ -343,7 +343,7 @@ export const access = { 比如: ```js -export const access = { +export const layout = { noFoundHandler({ next }) { const accesssIds = accessApi.getAccess(); if (!accesssIds.includes('/404')) { @@ -354,6 +354,30 @@ export const access = { }; ``` +## API + +### useTabTitle +类型定义如下: +```ts +function useTabTitle(title: string | Ref): void; +``` + + +当使用多页签模式时,在页面中使用 `useTabTitle` 可以自定义页面标签: +```vue + +``` + + + + ## 4.x 升级到 5.x 1. 个性化 layout 配置改为使用传入 navigation diff --git a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/html.js b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/html.js index 8c8d45ec3..a598b0a34 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/html.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/html.js @@ -7,7 +7,7 @@ export default async function createHtmlWebpackConfig({ api, cwd, config, webpac filename: '[name].html', ...config.html, templateParameters: { - title: config.html?.title || api.config.title || 'Fes.js', + title: api.config.title || config.html?.title || 'fes.js', ...resolveRuntimeEnv(publicPath), mountElementId: config.mountElementId, }, diff --git a/packages/fes-plugin-layout/src/index.js b/packages/fes-plugin-layout/src/index.js index a06920c8d..1870e1e64 100644 --- a/packages/fes-plugin-layout/src/index.js +++ b/packages/fes-plugin-layout/src/index.js @@ -75,7 +75,7 @@ export default (api) => { api.addPluginExports(() => [ { - specifiers: ['Page'], + specifiers: ['Page', 'useTabTitle'], source: join(namespace, 'index.js'), }, ]); diff --git a/packages/fes-plugin-layout/src/runtime/index.js b/packages/fes-plugin-layout/src/runtime/index.js index 72f0ee5a3..5117f920c 100644 --- a/packages/fes-plugin-layout/src/runtime/index.js +++ b/packages/fes-plugin-layout/src/runtime/index.js @@ -1 +1,2 @@ export { default as Page } from './views/page.vue'; +export { useTabTitle } from './useTitle'; diff --git a/packages/fes-plugin-layout/src/runtime/useTitle.js b/packages/fes-plugin-layout/src/runtime/useTitle.js new file mode 100644 index 000000000..e56636e40 --- /dev/null +++ b/packages/fes-plugin-layout/src/runtime/useTitle.js @@ -0,0 +1,18 @@ +import { reactive, ref } from 'vue'; +import { useRoute } from '@@/core/coreExports'; + +const cache = reactive(new Map()); + +export const getTitle = (path) => cache.get(path); + +export const deleteTitle = (patch) => cache.delete(patch); + +export const useTabTitle = (title) => { + const route = useRoute(); + const titleRef = ref(title); + const path = route.path; + + cache.set(path, titleRef); + + return titleRef; +}; diff --git a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue index 974fe297b..1066fedc0 100644 --- a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue +++ b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue @@ -31,6 +31,7 @@ import { FTabs, FTabPane, FDropdown } from '@fesjs/fes-design'; import { ReloadOutlined, MoreOutlined } from '@fesjs/fes-design/icon'; import { useRouter, useRoute } from '@@/core/coreExports'; import { transTitle } from '../helpers/pluginLocale'; +import { getTitle, deleteTitle } from '../useTitle'; import Page from './page.vue'; let i = 0; @@ -52,17 +53,20 @@ export default { const route = useRoute(); const router = useRouter(); const createPage = (_route) => { - const title = _route.meta.title; + const computedTitle = computed(() => { + const customTitle = unref(getTitle(_route.path)); + return customTitle ?? transTitle(_route.meta.title); + }); return { path: _route.path, route: _route, name: _route.meta.name ?? _route.name, - title: computed(() => transTitle(title)), + title: computedTitle, key: getKey(), }; }; - const pageList = ref([createPage(route)]); + const pageList = ref([createPage(router.currentRoute.value)]); const actions = [ { value: 'closeOtherPage', @@ -113,6 +117,7 @@ export default { list.splice(index, 1); pageList.value = list; pageRef.value.removeKeepAlive(selectedPage.name); + deleteTitle(selectedPage.path); }; const reloadPage = (path) => { const selectedPage = findPage(path || unref(route.path)); diff --git a/packages/fes-plugin-layout/types.d.ts b/packages/fes-plugin-layout/types.d.ts index 0c3a53219..e33b2e466 100644 --- a/packages/fes-plugin-layout/types.d.ts +++ b/packages/fes-plugin-layout/types.d.ts @@ -12,6 +12,8 @@ interface Menu { export const Page: Component; +export function useTabTitle(title: string | Ref): void; + interface LayoutRuntimeConfig { footer?: string; theme?: 'dark' | 'light'; diff --git a/packages/fes-preset-built-in/src/plugins/generateFiles/fes/index.js b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/index.js index a15bae4e4..d64504d3e 100644 --- a/packages/fes-preset-built-in/src/plugins/generateFiles/fes/index.js +++ b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/index.js @@ -24,7 +24,7 @@ export default function (api) { path: 'fes.js', content: Mustache.render(fesTpl, { enableTitle: api.config.title !== false, - defaultTitle: api.config.title || '', + defaultTitle: api.config.title || 'fes.js', runtimePath, rootElement: `#${api.config.mountElementId || 'app'}`, entryCode: ( diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index 83373159e..1f2824ba8 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -41,7 +41,7 @@ export default defineBuildConfig({ layout: { title: 'Fes.js', footer: 'Created by MumbleFE', - multiTabs: false, + multiTabs: true, navigation: 'side', theme: 'dark', menus: [ diff --git a/packages/fes-template/src/pages/menuTest/@id.vue b/packages/fes-template/src/pages/menuTest/@id.vue index 4977d60ff..1b6e397ec 100644 --- a/packages/fes-template/src/pages/menuTest/@id.vue +++ b/packages/fes-template/src/pages/menuTest/@id.vue @@ -1,7 +1,5 @@ { @@ -9,17 +7,22 @@ } diff --git a/packages/fes-template/src/pages/menuTest/index.vue b/packages/fes-template/src/pages/menuTest/index.vue index d3ce9c1b9..9cf15ba75 100644 --- a/packages/fes-template/src/pages/menuTest/index.vue +++ b/packages/fes-template/src/pages/menuTest/index.vue @@ -1,6 +1,11 @@ @@ -10,12 +15,10 @@ diff --git a/packages/fes-template/src/pages/menuTest/layout.vue b/packages/fes-template/src/pages/menuTest/layout.vue deleted file mode 100644 index 6e323c0dc..000000000 --- a/packages/fes-template/src/pages/menuTest/layout.vue +++ /dev/null @@ -1,8 +0,0 @@ -