|
@@ -11,6 +11,7 @@ import { getAuthCache, setAuthCache } from './utils/auth'
|
|
|
import { LAYOUT_COLLAPSED_KEY } from './utils/cache/cacheEnum'
|
|
import { LAYOUT_COLLAPSED_KEY } from './utils/cache/cacheEnum'
|
|
|
import consts from './consts'
|
|
import consts from './consts'
|
|
|
import ModalStore from './components/ModalStore'
|
|
import ModalStore from './components/ModalStore'
|
|
|
|
|
+import { stringify } from 'qs'
|
|
|
|
|
|
|
|
const loginPath = '/user/login'
|
|
const loginPath = '/user/login'
|
|
|
|
|
|
|
@@ -83,7 +84,12 @@ export const layout = ({ initialState, setInitialState }) => {
|
|
|
onPageChange: async location => {
|
|
onPageChange: async location => {
|
|
|
// 如果没有登录,重定向到 login
|
|
// 如果没有登录,重定向到 login
|
|
|
if (!initialState?.currentUser?.staffId && location.pathname !== loginPath) {
|
|
if (!initialState?.currentUser?.staffId && location.pathname !== loginPath) {
|
|
|
- history.replace('/user/login')
|
|
|
|
|
|
|
+ history.replace({
|
|
|
|
|
+ pathname: loginPath,
|
|
|
|
|
+ search: stringify({
|
|
|
|
|
+ redirect: history.location.pathname
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
} else {
|
|
} else {
|
|
|
location.pathname !== loginPath &&
|
|
location.pathname !== loginPath &&
|
|
|
tryChangeWorkStatus(initialState?.currentUser?.staffId, location.pathname)
|
|
tryChangeWorkStatus(initialState?.currentUser?.staffId, location.pathname)
|
|
@@ -101,7 +107,12 @@ const errorHandler = error => {
|
|
|
if (info) {
|
|
if (info) {
|
|
|
const { errorMessage = '请求失败', showType, errorCode } = info
|
|
const { errorMessage = '请求失败', showType, errorCode } = info
|
|
|
if (consts.TOKEN_INVALID_CODE.includes(errorCode)) {
|
|
if (consts.TOKEN_INVALID_CODE.includes(errorCode)) {
|
|
|
- history.replace(consts.LOGIN_PATH)
|
|
|
|
|
|
|
+ history.replace({
|
|
|
|
|
+ pathname: loginPath,
|
|
|
|
|
+ search: stringify({
|
|
|
|
|
+ redirect: window.location.pathname
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
switch (showType) {
|
|
switch (showType) {
|
|
|
case ErrorShowType.ERROR_MESSAGE:
|
|
case ErrorShowType.ERROR_MESSAGE:
|