Commit beb4c3a37f314b97657a1d85e7db2abf40dbe6c3
1 parent
177010bf
fix: fix routing switch, tab is not activated
Showing
8 changed files
with
42 additions
and
26 deletions
src/components/Menu/src/BasicMenu.tsx
... | ... | @@ -239,14 +239,13 @@ export default defineComponent({ |
239 | 239 | ) : ( |
240 | 240 | <section class={`basic-menu-wrap`}> |
241 | 241 | {getSlot(slots, 'header')} |
242 | - {props.search && ( | |
243 | - <SearchInput | |
244 | - theme={props.theme} | |
245 | - onChange={handleInputChange} | |
246 | - onClick={handleInputClick} | |
247 | - collapsed={getCollapsedState} | |
248 | - /> | |
249 | - )} | |
242 | + <SearchInput | |
243 | + class={!props.search ? 'hidden' : ''} | |
244 | + theme={props.theme} | |
245 | + onChange={handleInputChange} | |
246 | + onClick={handleInputClick} | |
247 | + collapsed={getCollapsedState} | |
248 | + /> | |
250 | 249 | <section style={unref(getMenuWrapStyle)}> |
251 | 250 | <ScrollContainer>{() => renderMenu()}</ScrollContainer> |
252 | 251 | </section> | ... | ... |
src/hooks/web/usePage.ts
... | ... | @@ -10,6 +10,7 @@ export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEn |
10 | 10 | |
11 | 11 | function handleError(e: Error) { |
12 | 12 | console.error(e); |
13 | + // 101是为了 大于 打开时候设置的100延时防止闪动 | |
13 | 14 | setTimeout(() => { |
14 | 15 | appStore.commitPageLoadingState(false); |
15 | 16 | }, 101); | ... | ... |
src/hooks/web/useTabs.ts
... | ... | @@ -3,6 +3,9 @@ import { PageEnum } from '/@/enums/pageEnum'; |
3 | 3 | import { TabItem, tabStore } from '/@/store/modules/tab'; |
4 | 4 | import { appStore } from '/@/store/modules/app'; |
5 | 5 | import router from '/@/router'; |
6 | +import { ref } from 'vue'; | |
7 | + | |
8 | +const activeKeyRef = ref<string>(''); | |
6 | 9 | |
7 | 10 | type Fn = () => void; |
8 | 11 | type RouteFn = (tabItem: TabItem) => void; |
... | ... | @@ -70,12 +73,13 @@ export function useTabs() { |
70 | 73 | closeOther: () => canIUseFn() && closeOther(tabStore.getCurrentTab), |
71 | 74 | closeCurrent: () => canIUseFn() && closeCurrent(tabStore.getCurrentTab), |
72 | 75 | resetCache: () => canIUseFn() && resetCache(), |
73 | - addTab: (path: PageEnum, goTo = false) => { | |
76 | + addTab: (path: PageEnum, goTo = false, replace = false) => { | |
74 | 77 | useTimeout(() => { |
75 | 78 | tabStore.addTabByPathAction(path); |
76 | 79 | }, 0); |
77 | - | |
78 | - goTo && router.push(path); | |
80 | + activeKeyRef.value = path; | |
81 | + goTo && replace ? router.replace : router.push(path); | |
79 | 82 | }, |
83 | + activeKeyRef, | |
80 | 84 | }; |
81 | 85 | } | ... | ... |
src/layouts/Logo.vue
1 | 1 | <template> |
2 | 2 | <div class="app-logo" @click="handleGoHome"> |
3 | 3 | <img :src="logo" /> |
4 | - <div v-if="show" class="logo-title ml-2 ellipsis">{{ globSetting.title }}</div> | |
4 | + <div v-if="show" class="logo-title ml-1 ellipsis">{{ globSetting.title }}</div> | |
5 | 5 | </div> |
6 | 6 | </template> |
7 | 7 | <script lang="ts"> |
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | .logo-title { |
63 | 63 | display: none; |
64 | 64 | font-family: Georgia, serif; |
65 | - font-size: 18px; | |
65 | + font-size: 16px; | |
66 | 66 | .respond-to(medium,{ |
67 | 67 | display: block; |
68 | 68 | }); | ... | ... |
src/layouts/default/LayoutMenu.tsx
... | ... | @@ -193,7 +193,7 @@ export default defineComponent({ |
193 | 193 | class="layout-menu" |
194 | 194 | theme={themeData} |
195 | 195 | showLogo={isShowLogo} |
196 | - search={unref(showSearchRef)} | |
196 | + search={unref(showSearchRef) && !collapsed} | |
197 | 197 | items={unref(menusRef)} |
198 | 198 | flatItems={unref(flatMenusRef)} |
199 | 199 | onClickSearchInput={handleClickSearchInput} | ... | ... |
src/layouts/default/index.less
src/layouts/default/multitabs/index.tsx
... | ... | @@ -2,7 +2,14 @@ import type { TabContentProps } from './tab.data'; |
2 | 2 | import type { TabItem } from '/@/store/modules/tab'; |
3 | 3 | import type { AppRouteRecordRaw } from '/@/router/types'; |
4 | 4 | |
5 | -import { defineComponent, watch, computed, ref, unref, onMounted } from 'vue'; | |
5 | +import { | |
6 | + defineComponent, | |
7 | + watch, | |
8 | + computed, | |
9 | + // ref, | |
10 | + unref, | |
11 | + onMounted, | |
12 | +} from 'vue'; | |
6 | 13 | import { Tabs } from 'ant-design-vue'; |
7 | 14 | import TabContent from './TabContent'; |
8 | 15 | |
... | ... | @@ -12,41 +19,43 @@ import { TabContentEnum } from './tab.data'; |
12 | 19 | |
13 | 20 | import { useRouter } from 'vue-router'; |
14 | 21 | |
15 | -import './index.less'; | |
16 | 22 | import { tabStore } from '/@/store/modules/tab'; |
17 | 23 | import { closeTab } from './useTabDropdown'; |
18 | 24 | import router from '/@/router'; |
19 | 25 | import { useTabs } from '/@/hooks/web/useTabs'; |
20 | 26 | import { PageEnum } from '/@/enums/pageEnum'; |
21 | 27 | |
28 | +import './index.less'; | |
22 | 29 | export default defineComponent({ |
23 | 30 | name: 'MultiTabs', |
24 | 31 | setup() { |
25 | 32 | let isAddAffix = false; |
26 | 33 | const go = useGo(); |
27 | 34 | const { currentRoute } = useRouter(); |
28 | - | |
35 | + const { addTab, activeKeyRef } = useTabs(); | |
29 | 36 | onMounted(() => { |
30 | - const { addTab } = useTabs(); | |
31 | 37 | addTab(unref(currentRoute).path as PageEnum); |
32 | 38 | }); |
33 | 39 | |
34 | 40 | // 当前激活tab |
35 | - const activeKeyRef = ref<string>(''); | |
41 | + // const activeKeyRef = ref<string>(''); | |
42 | + | |
36 | 43 | // 当前tab列表 |
37 | 44 | const getTabsState = computed(() => { |
38 | 45 | return tabStore.getTabsState; |
39 | 46 | }); |
40 | 47 | |
48 | + if (!isAddAffix) { | |
49 | + addAffixTabs(); | |
50 | + isAddAffix = true; | |
51 | + } | |
52 | + | |
41 | 53 | watch( |
42 | 54 | () => unref(currentRoute).path, |
43 | 55 | (path) => { |
44 | - if (!isAddAffix) { | |
45 | - addAffixTabs(); | |
46 | - isAddAffix = true; | |
56 | + if (activeKeyRef.value !== path) { | |
57 | + activeKeyRef.value = path; | |
47 | 58 | } |
48 | - activeKeyRef.value = path; | |
49 | - | |
50 | 59 | // 监听路由的话虽然可以,但是路由切换的时间会造成卡顿现象? |
51 | 60 | // 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab |
52 | 61 | // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw); |
... | ... | @@ -55,6 +64,7 @@ export default defineComponent({ |
55 | 64 | immediate: true, |
56 | 65 | } |
57 | 66 | ); |
67 | + | |
58 | 68 | /** |
59 | 69 | * @description: 过滤所有固定路由 |
60 | 70 | */ |
... | ... | @@ -72,6 +82,7 @@ export default defineComponent({ |
72 | 82 | }); |
73 | 83 | return tabs; |
74 | 84 | } |
85 | + | |
75 | 86 | /** |
76 | 87 | * @description: 设置固定tabs |
77 | 88 | */ |
... | ... | @@ -87,6 +98,7 @@ export default defineComponent({ |
87 | 98 | activeKeyRef.value = activeKey; |
88 | 99 | go(activeKey, false); |
89 | 100 | } |
101 | + | |
90 | 102 | // 关闭当前ab |
91 | 103 | function handleEdit(targetKey: string) { |
92 | 104 | // 新增操作隐藏,目前只使用删除操作 | ... | ... |