Commit 3f78b5aa0cd3e7a6f17d58512ca93ee2905d5e2f

Authored by vben
1 parent 577bf788

fix: pageLoading not working

src/design/var/index.less
@@ -15,7 +15,5 @@ @@ -15,7 +15,5 @@
15 @side-drag-z-index: 200; 15 @side-drag-z-index: 200;
16 @page-loading-z-index: 10000; 16 @page-loading-z-index: 10000;
17 17
18 -// app menu  
19 -  
20 // left-menu 18 // left-menu
21 -@app-menu-item-height: 42px; 19 +@app-menu-item-height: 46px;
src/layouts/default/LayoutContent.tsx
@@ -16,7 +16,6 @@ export default defineComponent({ @@ -16,7 +16,6 @@ export default defineComponent({
16 return () => { 16 return () => {
17 const { contentMode, openPageLoading } = unref(getProjectConfigRef); 17 const { contentMode, openPageLoading } = unref(getProjectConfigRef);
18 const { getPageLoading } = appStore; 18 const { getPageLoading } = appStore;
19 -  
20 const wrapClass = contentMode === ContentEnum.FULL ? 'full' : 'fixed'; 19 const wrapClass = contentMode === ContentEnum.FULL ? 'full' : 'fixed';
21 return ( 20 return (
22 <div class={[`default-layout__main`]}> 21 <div class={[`default-layout__main`]}>
src/layouts/page/index.tsx
@@ -12,9 +12,16 @@ import { appStore } from &#39;/@/store/modules/app&#39;; @@ -12,9 +12,16 @@ import { appStore } from &#39;/@/store/modules/app&#39;;
12 export default defineComponent({ 12 export default defineComponent({
13 name: 'PageLayout', 13 name: 'PageLayout',
14 setup() { 14 setup() {
15 - const getProjectConfigRef = computed(() => {  
16 - return appStore.getProjectConfig; 15 + const getProjectConfigRef = computed(() => appStore.getProjectConfig);
  16 + const openCacheRef = computed(() => {
  17 + const {
  18 + openKeepAlive,
  19 + multiTabsSetting: { show },
  20 + } = unref(getProjectConfigRef);
  21 + return openKeepAlive && show;
17 }); 22 });
  23 + const getCacheTabsRef = computed(() => toRaw(tabStore.getKeepAliveTabsState) as string[]);
  24 +
18 const { openPageLoading } = unref(getProjectConfigRef); 25 const { openPageLoading } = unref(getProjectConfigRef);
19 26
20 let on = {}; 27 let on = {};
@@ -27,21 +34,20 @@ export default defineComponent({ @@ -27,21 +34,20 @@ export default defineComponent({
27 const { 34 const {
28 routerTransition, 35 routerTransition,
29 openRouterTransition, 36 openRouterTransition,
30 - openKeepAlive,  
31 - multiTabsSetting: { show, max }, 37 + multiTabsSetting: { max },
32 } = unref(getProjectConfigRef); 38 } = unref(getProjectConfigRef);
33 39
34 - const openCache = openKeepAlive && show;  
35 - const cacheTabs = toRaw(tabStore.getKeepAliveTabsState) as string[];  
36 return ( 40 return (
37 <div> 41 <div>
38 <RouterView> 42 <RouterView>
39 {{ 43 {{
40 default: ({ Component, route }: { Component: any; route: RouteLocation }) => { 44 default: ({ Component, route }: { Component: any; route: RouteLocation }) => {
41 // No longer show animations that are already in the tab 45 // No longer show animations that are already in the tab
42 - const name = route.meta.inTab ? 'fade' : null; 46 + const cacheTabs = unref(getCacheTabsRef);
  47 + const isInCache = cacheTabs.includes(route.name as string);
  48 + const name = isInCache && route.meta.inTab ? 'fade' : null;
43 49
44 - const Content = openCache ? ( 50 + const Content = unref(openCacheRef) ? (
45 <KeepAlive max={max} include={cacheTabs}> 51 <KeepAlive max={max} include={cacheTabs}>
46 <Component key={route.fullPath} /> 52 <Component key={route.fullPath} />
47 </KeepAlive> 53 </KeepAlive>
src/layouts/page/useTransition.ts
@@ -3,6 +3,7 @@ import { tryOnUnmounted } from &#39;/@/utils/helper/vueHelper&#39;; @@ -3,6 +3,7 @@ import { tryOnUnmounted } from &#39;/@/utils/helper/vueHelper&#39;;
3 export function useTransition() { 3 export function useTransition() {
4 function handleAfterEnter() { 4 function handleAfterEnter() {
5 const { openRouterTransition, openPageLoading } = appStore.getProjectConfig; 5 const { openRouterTransition, openPageLoading } = appStore.getProjectConfig;
  6 +
6 if (!openRouterTransition || !openPageLoading) return; 7 if (!openRouterTransition || !openPageLoading) return;
7 // Close loading after the route switching animation ends 8 // Close loading after the route switching animation ends
8 appStore.setPageLoadingAction(false); 9 appStore.setPageLoadingAction(false);
src/router/guard/index.ts
@@ -21,6 +21,8 @@ export function createGuard(router: Router) { @@ -21,6 +21,8 @@ export function createGuard(router: Router) {
21 if (removeAllHttpPending) { 21 if (removeAllHttpPending) {
22 axiosCanceler = new AxiosCanceler(); 22 axiosCanceler = new AxiosCanceler();
23 } 23 }
  24 +
  25 + createPageLoadingGuard(router);
24 router.beforeEach(async (to) => { 26 router.beforeEach(async (to) => {
25 // Determine whether the tab has been opened 27 // Determine whether the tab has been opened
26 const isOpen = getIsOpenTab(to.fullPath); 28 const isOpen = getIsOpenTab(to.fullPath);
@@ -59,5 +61,4 @@ export function createGuard(router: Router) { @@ -59,5 +61,4 @@ export function createGuard(router: Router) {
59 61
60 openNProgress && createProgressGuard(router); 62 openNProgress && createProgressGuard(router);
61 createPermissionGuard(router); 63 createPermissionGuard(router);
62 - createPageLoadingGuard(router);  
63 } 64 }
src/router/guard/pageLoadingGuard.ts
@@ -20,6 +20,7 @@ export function createPageLoadingGuard(router: Router) { @@ -20,6 +20,7 @@ export function createPageLoadingGuard(router: Router) {
20 appStore.commitPageLoadingState(true); 20 appStore.commitPageLoadingState(true);
21 return true; 21 return true;
22 } 22 }
  23 +
23 if (show && openKeepAlive && !isFirstLoad) { 24 if (show && openKeepAlive && !isFirstLoad) {
24 const tabList = tabStore.getTabsState; 25 const tabList = tabStore.getTabsState;
25 26