Commit beb4c3a37f314b97657a1d85e7db2abf40dbe6c3

Authored by nebv
1 parent 177010bf

fix: fix routing switch, tab is not activated

src/components/Menu/src/BasicMenu.tsx
@@ -239,14 +239,13 @@ export default defineComponent({ @@ -239,14 +239,13 @@ export default defineComponent({
239 ) : ( 239 ) : (
240 <section class={`basic-menu-wrap`}> 240 <section class={`basic-menu-wrap`}>
241 {getSlot(slots, 'header')} 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 <section style={unref(getMenuWrapStyle)}> 249 <section style={unref(getMenuWrapStyle)}>
251 <ScrollContainer>{() => renderMenu()}</ScrollContainer> 250 <ScrollContainer>{() => renderMenu()}</ScrollContainer>
252 </section> 251 </section>
src/hooks/web/usePage.ts
@@ -10,6 +10,7 @@ export type RouteLocationRawEx = Omit&lt;RouteLocationRaw, &#39;path&#39;&gt; &amp; { path: PageEn @@ -10,6 +10,7 @@ export type RouteLocationRawEx = Omit&lt;RouteLocationRaw, &#39;path&#39;&gt; &amp; { path: PageEn
10 10
11 function handleError(e: Error) { 11 function handleError(e: Error) {
12 console.error(e); 12 console.error(e);
  13 + // 101是为了 大于 打开时候设置的100延时防止闪动
13 setTimeout(() => { 14 setTimeout(() => {
14 appStore.commitPageLoadingState(false); 15 appStore.commitPageLoadingState(false);
15 }, 101); 16 }, 101);
src/hooks/web/useTabs.ts
@@ -3,6 +3,9 @@ import { PageEnum } from &#39;/@/enums/pageEnum&#39;; @@ -3,6 +3,9 @@ import { PageEnum } from &#39;/@/enums/pageEnum&#39;;
3 import { TabItem, tabStore } from '/@/store/modules/tab'; 3 import { TabItem, tabStore } from '/@/store/modules/tab';
4 import { appStore } from '/@/store/modules/app'; 4 import { appStore } from '/@/store/modules/app';
5 import router from '/@/router'; 5 import router from '/@/router';
  6 +import { ref } from 'vue';
  7 +
  8 +const activeKeyRef = ref<string>('');
6 9
7 type Fn = () => void; 10 type Fn = () => void;
8 type RouteFn = (tabItem: TabItem) => void; 11 type RouteFn = (tabItem: TabItem) => void;
@@ -70,12 +73,13 @@ export function useTabs() { @@ -70,12 +73,13 @@ export function useTabs() {
70 closeOther: () => canIUseFn() && closeOther(tabStore.getCurrentTab), 73 closeOther: () => canIUseFn() && closeOther(tabStore.getCurrentTab),
71 closeCurrent: () => canIUseFn() && closeCurrent(tabStore.getCurrentTab), 74 closeCurrent: () => canIUseFn() && closeCurrent(tabStore.getCurrentTab),
72 resetCache: () => canIUseFn() && resetCache(), 75 resetCache: () => canIUseFn() && resetCache(),
73 - addTab: (path: PageEnum, goTo = false) => { 76 + addTab: (path: PageEnum, goTo = false, replace = false) => {
74 useTimeout(() => { 77 useTimeout(() => {
75 tabStore.addTabByPathAction(path); 78 tabStore.addTabByPathAction(path);
76 }, 0); 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 <template> 1 <template>
2 <div class="app-logo" @click="handleGoHome"> 2 <div class="app-logo" @click="handleGoHome">
3 <img :src="logo" /> 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 </div> 5 </div>
6 </template> 6 </template>
7 <script lang="ts"> 7 <script lang="ts">
@@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
62 .logo-title { 62 .logo-title {
63 display: none; 63 display: none;
64 font-family: Georgia, serif; 64 font-family: Georgia, serif;
65 - font-size: 18px; 65 + font-size: 16px;
66 .respond-to(medium,{ 66 .respond-to(medium,{
67 display: block; 67 display: block;
68 }); 68 });
src/layouts/default/LayoutMenu.tsx
@@ -193,7 +193,7 @@ export default defineComponent({ @@ -193,7 +193,7 @@ export default defineComponent({
193 class="layout-menu" 193 class="layout-menu"
194 theme={themeData} 194 theme={themeData}
195 showLogo={isShowLogo} 195 showLogo={isShowLogo}
196 - search={unref(showSearchRef)} 196 + search={unref(showSearchRef) && !collapsed}
197 items={unref(menusRef)} 197 items={unref(menusRef)}
198 flatItems={unref(flatMenusRef)} 198 flatItems={unref(flatMenusRef)}
199 onClickSearchInput={handleClickSearchInput} 199 onClickSearchInput={handleClickSearchInput}
src/layouts/default/index.less
@@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
48 .layout-menu { 48 .layout-menu {
49 &__logo { 49 &__logo {
50 height: @header-height; 50 height: @header-height;
51 - padding: 10px; 51 + padding: 10px 4px;
52 52
53 img { 53 img {
54 width: @logo-width; 54 width: @logo-width;
src/layouts/default/multitabs/index.tsx
@@ -2,7 +2,14 @@ import type { TabContentProps } from &#39;./tab.data&#39;; @@ -2,7 +2,14 @@ import type { TabContentProps } from &#39;./tab.data&#39;;
2 import type { TabItem } from '/@/store/modules/tab'; 2 import type { TabItem } from '/@/store/modules/tab';
3 import type { AppRouteRecordRaw } from '/@/router/types'; 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 import { Tabs } from 'ant-design-vue'; 13 import { Tabs } from 'ant-design-vue';
7 import TabContent from './TabContent'; 14 import TabContent from './TabContent';
8 15
@@ -12,41 +19,43 @@ import { TabContentEnum } from &#39;./tab.data&#39;; @@ -12,41 +19,43 @@ import { TabContentEnum } from &#39;./tab.data&#39;;
12 19
13 import { useRouter } from 'vue-router'; 20 import { useRouter } from 'vue-router';
14 21
15 -import './index.less';  
16 import { tabStore } from '/@/store/modules/tab'; 22 import { tabStore } from '/@/store/modules/tab';
17 import { closeTab } from './useTabDropdown'; 23 import { closeTab } from './useTabDropdown';
18 import router from '/@/router'; 24 import router from '/@/router';
19 import { useTabs } from '/@/hooks/web/useTabs'; 25 import { useTabs } from '/@/hooks/web/useTabs';
20 import { PageEnum } from '/@/enums/pageEnum'; 26 import { PageEnum } from '/@/enums/pageEnum';
21 27
  28 +import './index.less';
22 export default defineComponent({ 29 export default defineComponent({
23 name: 'MultiTabs', 30 name: 'MultiTabs',
24 setup() { 31 setup() {
25 let isAddAffix = false; 32 let isAddAffix = false;
26 const go = useGo(); 33 const go = useGo();
27 const { currentRoute } = useRouter(); 34 const { currentRoute } = useRouter();
28 - 35 + const { addTab, activeKeyRef } = useTabs();
29 onMounted(() => { 36 onMounted(() => {
30 - const { addTab } = useTabs();  
31 addTab(unref(currentRoute).path as PageEnum); 37 addTab(unref(currentRoute).path as PageEnum);
32 }); 38 });
33 39
34 // 当前激活tab 40 // 当前激活tab
35 - const activeKeyRef = ref<string>(''); 41 + // const activeKeyRef = ref<string>('');
  42 +
36 // 当前tab列表 43 // 当前tab列表
37 const getTabsState = computed(() => { 44 const getTabsState = computed(() => {
38 return tabStore.getTabsState; 45 return tabStore.getTabsState;
39 }); 46 });
40 47
  48 + if (!isAddAffix) {
  49 + addAffixTabs();
  50 + isAddAffix = true;
  51 + }
  52 +
41 watch( 53 watch(
42 () => unref(currentRoute).path, 54 () => unref(currentRoute).path,
43 (path) => { 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 // 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab 60 // 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab
52 // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw); 61 // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw);
@@ -55,6 +64,7 @@ export default defineComponent({ @@ -55,6 +64,7 @@ export default defineComponent({
55 immediate: true, 64 immediate: true,
56 } 65 }
57 ); 66 );
  67 +
58 /** 68 /**
59 * @description: 过滤所有固定路由 69 * @description: 过滤所有固定路由
60 */ 70 */
@@ -72,6 +82,7 @@ export default defineComponent({ @@ -72,6 +82,7 @@ export default defineComponent({
72 }); 82 });
73 return tabs; 83 return tabs;
74 } 84 }
  85 +
75 /** 86 /**
76 * @description: 设置固定tabs 87 * @description: 设置固定tabs
77 */ 88 */
@@ -87,6 +98,7 @@ export default defineComponent({ @@ -87,6 +98,7 @@ export default defineComponent({
87 activeKeyRef.value = activeKey; 98 activeKeyRef.value = activeKey;
88 go(activeKey, false); 99 go(activeKey, false);
89 } 100 }
  101 +
90 // 关闭当前ab 102 // 关闭当前ab
91 function handleEdit(targetKey: string) { 103 function handleEdit(targetKey: string) {
92 // 新增操作隐藏,目前只使用删除操作 104 // 新增操作隐藏,目前只使用删除操作
src/settings/projectSetting.ts
@@ -51,7 +51,7 @@ const setting: ProjectConfig = { @@ -51,7 +51,7 @@ const setting: ProjectConfig = {
51 // 是否显示搜索框 51 // 是否显示搜索框
52 showSearch: true, 52 showSearch: true,
53 // 菜单宽度 53 // 菜单宽度
54 - menuWidth: 200, 54 + menuWidth: 180,
55 // 菜单模式 55 // 菜单模式
56 mode: MenuModeEnum.INLINE, 56 mode: MenuModeEnum.INLINE,
57 // 菜单类型 57 // 菜单类型