Skip to content

Commit

Permalink
fix: pageLoading not working
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 12, 2020
1 parent 577bf78 commit 3f78b5a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/design/var/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
@side-drag-z-index: 200;
@page-loading-z-index: 10000;

// app menu

// left-menu
@app-menu-item-height: 42px;
@app-menu-item-height: 46px;
1 change: 0 additions & 1 deletion src/layouts/default/LayoutContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default defineComponent({
return () => {
const { contentMode, openPageLoading } = unref(getProjectConfigRef);
const { getPageLoading } = appStore;

const wrapClass = contentMode === ContentEnum.FULL ? 'full' : 'fixed';
return (
<div class={[`default-layout__main`]}>
Expand Down
22 changes: 14 additions & 8 deletions src/layouts/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ import { appStore } from '/@/store/modules/app';
export default defineComponent({
name: 'PageLayout',
setup() {
const getProjectConfigRef = computed(() => {
return appStore.getProjectConfig;
const getProjectConfigRef = computed(() => appStore.getProjectConfig);
const openCacheRef = computed(() => {
const {
openKeepAlive,
multiTabsSetting: { show },
} = unref(getProjectConfigRef);
return openKeepAlive && show;
});
const getCacheTabsRef = computed(() => toRaw(tabStore.getKeepAliveTabsState) as string[]);

const { openPageLoading } = unref(getProjectConfigRef);

let on = {};
Expand All @@ -27,21 +34,20 @@ export default defineComponent({
const {
routerTransition,
openRouterTransition,
openKeepAlive,
multiTabsSetting: { show, max },
multiTabsSetting: { max },
} = unref(getProjectConfigRef);

const openCache = openKeepAlive && show;
const cacheTabs = toRaw(tabStore.getKeepAliveTabsState) as string[];
return (
<div>
<RouterView>
{{
default: ({ Component, route }: { Component: any; route: RouteLocation }) => {
// No longer show animations that are already in the tab
const name = route.meta.inTab ? 'fade' : null;
const cacheTabs = unref(getCacheTabsRef);
const isInCache = cacheTabs.includes(route.name as string);
const name = isInCache && route.meta.inTab ? 'fade' : null;

const Content = openCache ? (
const Content = unref(openCacheRef) ? (
<KeepAlive max={max} include={cacheTabs}>
<Component key={route.fullPath} />
</KeepAlive>
Expand Down
1 change: 1 addition & 0 deletions src/layouts/page/useTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
export function useTransition() {
function handleAfterEnter() {
const { openRouterTransition, openPageLoading } = appStore.getProjectConfig;

if (!openRouterTransition || !openPageLoading) return;
// Close loading after the route switching animation ends
appStore.setPageLoadingAction(false);
Expand Down
3 changes: 2 additions & 1 deletion src/router/guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export function createGuard(router: Router) {
if (removeAllHttpPending) {
axiosCanceler = new AxiosCanceler();
}

createPageLoadingGuard(router);
router.beforeEach(async (to) => {
// Determine whether the tab has been opened
const isOpen = getIsOpenTab(to.fullPath);
Expand Down Expand Up @@ -59,5 +61,4 @@ export function createGuard(router: Router) {

openNProgress && createProgressGuard(router);
createPermissionGuard(router);
createPageLoadingGuard(router);
}
1 change: 1 addition & 0 deletions src/router/guard/pageLoadingGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function createPageLoadingGuard(router: Router) {
appStore.commitPageLoadingState(true);
return true;
}

if (show && openKeepAlive && !isFirstLoad) {
const tabList = tabStore.getTabsState;

Expand Down

0 comments on commit 3f78b5a

Please sign in to comment.