perf: improve login logic

This commit is contained in:
vben
2021-02-22 23:04:47 +08:00
parent be3a3ed699
commit a09a0eedd2
29 changed files with 352 additions and 821 deletions

View File

@@ -2,7 +2,9 @@ import type { AppRouteRecordRaw } from '/@/router/types';
import ParentLayout from '/@/layouts/page/ParentView.vue';
import { t } from '/@/hooks/web/useI18n';
const EXCEPTION_COMPONENT = () => import('../views/sys/exception/Exception.vue');
export const REDIRECT_NAME = 'Redirect';
export const EXCEPTION_COMPONENT = () => import('../views/sys/exception/Exception.vue');
/**
* @description: default layout
@@ -44,8 +46,6 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
],
};
export const REDIRECT_NAME = 'Redirect';
export const REDIRECT_ROUTE: AppRouteRecordRaw = {
path: '/redirect',
name: REDIRECT_NAME,

View File

@@ -2,6 +2,10 @@ import type { Router } from 'vue-router';
import { useProjectSetting } from '/@/hooks/setting';
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
/**
* The interface used to close the current page to complete the request when the route is switched
* @param router
*/
export function createHttpGuard(router: Router) {
const { removeAllHttpPending } = useProjectSetting();
let axiosCanceler: Nullable<AxiosCanceler>;

View File

@@ -4,6 +4,10 @@ import { Modal, notification } from 'ant-design-vue';
import { warn } from '/@/utils/log';
/**
* Used to close the message instance when the route is switched
* @param router
*/
export function createMessageGuard(router: Router) {
const { closeMessageOnSwitch } = useProjectSetting();

View File

@@ -6,7 +6,6 @@ import { createRouter, createWebHashHistory } from 'vue-router';
import { createGuard } from './guard/';
import { basicRoutes } from './routes/';
import { scrollBehavior } from './scrollBehavior';
import { REDIRECT_NAME } from './constant';
// app router
@@ -14,7 +13,7 @@ const router = createRouter({
history: createWebHashHistory(),
routes: (basicRoutes as unknown) as RouteRecordRaw[],
strict: true,
scrollBehavior: scrollBehavior,
scrollBehavior: () => ({ left: 0, top: 0 }),
});
// reset router

View File

@@ -1,57 +0,0 @@
// see https://github.com/vuejs/vue-router-next/blob/master/playground/scrollWaiter.ts
import type { RouteLocationNormalized } from 'vue-router';
// class ScrollQueue {
// private resolve: (() => void) | null = null;
// private promise: Promise<any> | null = null;
// add() {
// this.promise = new Promise((resolve) => {
// this.resolve = resolve as () => void;
// });
// }
// flush() {
// this.resolve && this.resolve();
// this.resolve = null;
// this.promise = null;
// }
// async wait() {
// await this.promise;
// }
// }
// const scrollWaiter = new ScrollQueue();
/**
* Handles the scroll behavior on route navigation
*
* @param {object} to Route object of next page
* @param {object} from Route object of previous page
* @param {object} savedPosition Used by popstate navigations
* @returns {(object|boolean)} Scroll position or `false`
*/
// @ts-ignore
export async function scrollBehavior(to, from, savedPosition) {
// await scrollWaiter.wait();
// Use predefined scroll behavior if defined, defaults to no scroll behavior
const behavior = 'smooth';
// Returning the `savedPosition` (if available) will result in a native-like
// behavior when navigating with back/forward buttons
if (savedPosition) {
return { ...savedPosition, behavior };
}
// Scroll to anchor by returning the selector
if (to.hash) {
return { el: decodeURI(to.hash), behavior };
}
// Check if any matched route config has meta that discourages scrolling to top
if (to.matched.some((m: RouteLocationNormalized) => m.meta.scrollToTop === false)) {
// Leave scroll as it is
return false;
}
// Always scroll to top
return { left: 0, top: 0, behavior };
}

View File

@@ -89,12 +89,5 @@ export interface MenuModule {
menu: Menu;
}
// interface RouteModule {
// layout: AppRouteRecordRaw;
// routes: AppRouteRecordRaw[];
// children?: AppRouteRecordRaw[];
// component?: Component;
// }
// export type AppRouteModule = RouteModule | AppRouteRecordRaw;
export type AppRouteModule = AppRouteRecordRaw;