feat: 更改参数名 & 关闭页面清数据

This commit is contained in:
wanchun 2023-03-12 11:05:26 +08:00
parent beb4661c2d
commit 67ec736e70
9 changed files with 31 additions and 25 deletions

View File

@ -366,11 +366,12 @@ function useTitle(title: string | Ref<string>): void;
当使用多页签模式时,在页面中使用 `useTitle` 可以自定义页面标签: 当使用多页签模式时,在页面中使用 `useTitle` 可以自定义页面标签:
```vue ```vue
<script setup> <script setup>
import { ref } from 'vue'; import { useRoute, useTabTitle } from '@fesjs/fes';
import { useRoute, useTitle } from '@fesjs/fes';
const title = ref(`详情-${route.params?.id}`); const titleRef = useTabTitle(`详情-${route.params?.id}`);
useTitle(title);
//如果要更新
titleRef.value = "changed"
</script> </script>
``` ```

View File

@ -75,7 +75,7 @@ export default (api) => {
api.addPluginExports(() => [ api.addPluginExports(() => [
{ {
specifiers: ['Page', 'useTitle'], specifiers: ['Page', 'useTabTitle'],
source: join(namespace, 'index.js'), source: join(namespace, 'index.js'),
}, },
]); ]);

View File

@ -1,2 +1,2 @@
export { default as Page } from './views/page.vue'; export { default as Page } from './views/page.vue';
export { useTitle } from './useTitle'; export { useTabTitle } from './useTitle';

View File

@ -1,11 +1,18 @@
import { reactive, ref } from 'vue';
import { useRoute } from '@@/core/coreExports'; import { useRoute } from '@@/core/coreExports';
import { reactive } from 'vue';
const cache = reactive(new Map()); const cache = reactive(new Map());
export const getTitle = (path) => cache.get(path); export const getTitle = (path) => cache.get(path);
export const useTitle = (title) => { export const deleteTitle = (patch) => cache.delete(patch);
export const useTabTitle = (title) => {
const route = useRoute(); const route = useRoute();
cache.set(route.path, title); const titleRef = ref(title);
const path = route.path;
cache.set(path, titleRef);
return titleRef;
}; };

View File

@ -31,7 +31,7 @@ import { FTabs, FTabPane, FDropdown } from '@fesjs/fes-design';
import { ReloadOutlined, MoreOutlined } from '@fesjs/fes-design/icon'; import { ReloadOutlined, MoreOutlined } from '@fesjs/fes-design/icon';
import { useRouter, useRoute } from '@@/core/coreExports'; import { useRouter, useRoute } from '@@/core/coreExports';
import { transTitle } from '../helpers/pluginLocale'; import { transTitle } from '../helpers/pluginLocale';
import { getTitle } from '../useTitle'; import { getTitle, deleteTitle } from '../useTitle';
import Page from './page.vue'; import Page from './page.vue';
let i = 0; let i = 0;
@ -117,6 +117,7 @@ export default {
list.splice(index, 1); list.splice(index, 1);
pageList.value = list; pageList.value = list;
pageRef.value.removeKeepAlive(selectedPage.name); pageRef.value.removeKeepAlive(selectedPage.name);
deleteTitle(selectedPage.path);
}; };
const reloadPage = (path) => { const reloadPage = (path) => {
const selectedPage = findPage(path || unref(route.path)); const selectedPage = findPage(path || unref(route.path));

View File

@ -12,7 +12,7 @@ interface Menu {
export const Page: Component; export const Page: Component;
export function useTitle(title: string | Ref<string>): void; export function useTabTitle(title: string | Ref<string>): void;
interface LayoutRuntimeConfig { interface LayoutRuntimeConfig {
footer?: string; footer?: string;

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="page">menuTest: {{ route.params }}</div> <div class="page">menuTest: {{ route.params }} <input style="border: 1px solid red" /></div>
</template> </template>
<config> <config>
{ {
@ -7,15 +7,13 @@
} }
</config> </config>
<script> <script>
import { ref } from 'vue'; import { useRoute, useTabTitle } from '@fesjs/fes';
import { useRoute, useTitle } from '@fesjs/fes';
export default { export default {
components: {}, components: {},
setup() { setup() {
const route = useRoute(); const route = useRoute();
const title = ref(`详情-${route.params?.id}`); const title = useTabTitle(`详情-${route.params?.id}`);
useTitle(title);
setTimeout(() => { setTimeout(() => {
title.value = `详情-${route.params?.id}-changed`; title.value = `详情-${route.params?.id}-changed`;

View File

@ -1,5 +1,12 @@
<template> <template>
<div class="page">menuTest-index</div> <div class="page">
menuTest-index
<div style="display: flex; flex-direction: column">
<router-link to="/menuTest/1">Go to 1</router-link>
<router-link to="/menuTest/2">Go to 2</router-link>
<router-link to="/menuTest/3">Go to 3</router-link>
</div>
</div>
</template> </template>
<config> <config>
{ {

View File

@ -1,8 +0,0 @@
<template>
<div style="display: flex; flex-direction: column">
<router-link to="/menuTest/1">Go to 1</router-link>
<router-link to="/menuTest/2">Go to 2</router-link>
<router-link to="/menuTest/3">Go to 3</router-link>
</div>
<router-view />
</template>