Skip to content

Commit

Permalink
feat: 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxingkang committed Sep 26, 2020
1 parent 2784c53 commit 04e52a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { history, RequestConfig } from 'umi';
import { fetchCurrent } from '@/services/user';
import RightContent from '@/components/right-content';
import Footer from '@/components/footer';
import { NO_LOGIN_WHITELIST } from '@/config';
import { getCookie, removeCookie } from '@/utils/cookie';
import logo from '@/assets/logo.svg';
import defaultSettings from '../config/default-settings';
Expand All @@ -28,7 +29,7 @@ export async function getInitialState(): Promise<{
return undefined;
};
// 如果是登录页面,不执行
if (history.location.pathname !== '/login' || history.location.pathname !== '/register') {
if (NO_LOGIN_WHITELIST.indexOf(history.location.pathname) === -1) {
const currentUser = await fetchUserInfo();
return {
fetchUserInfo,
Expand Down Expand Up @@ -56,7 +57,7 @@ export const layout = ({
const { location } = history;

// 如果没有登录,重定向到 login
if (!currentUser?.userid && (location.pathname !== '/login' || location.pathname !== '/register')) {
if (!currentUser?.userid && NO_LOGIN_WHITELIST.indexOf(location.pathname) === -1) {
history.push('/login');
}
},
Expand Down
8 changes: 7 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@

/**
* 免登陆白名单
*/
export const NO_LOGIN_WHITELIST = [
'/login',
'/register'
];
10 changes: 5 additions & 5 deletions src/pages/login/components/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
}
}

.prefixIcon {
color: @disabled-color;
font-size: 16px;
}

.submit {
width: 100%;
margin-top: 24px;
}
}

.prefixIcon {
color: @disabled-color;
font-size: 16px;
}

1 comment on commit 04e52a9

@vercel
Copy link

@vercel vercel bot commented on 04e52a9 Sep 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.