Commit 7d102618 authored by GuanHua's avatar GuanHua

fix: 登录问题修改

parent 7eda8acf
......@@ -92,6 +92,7 @@ const whiteLists = [
...userLoginLists,
// ...mallLists,
// '/memberCenter',
'/',
'/memberCenter/noAuth',
'/403',
'/404',
......@@ -200,6 +201,7 @@ export function onRouteChange({ routes, matchedRoutes, location, action }) {
setRouters(urls)
}
const { pathname } = location
console.log(pathname, 'pathname')
if (userLoginLists.includes(pathname)) {
// 当登录过, 并且尝试访问登录相关页面, 需重定向到首页
history.replace('/memberCenter/home')
......@@ -216,6 +218,7 @@ export function onRouteChange({ routes, matchedRoutes, location, action }) {
}
// 无权限访问时
// console.log(pathname)
console.log('无权限访问时')
history.replace('/memberCenter/noAuth')
} else {
if (whiteLists.includes(location.pathname)) {
......
......@@ -5,6 +5,7 @@ import { getCookie, removeCookie, setCookie } from './cookie'
import { getUserCookie, setUserCookie } from './siteCookie'
export interface AuthInfo {
urls: string[]
userId: number,
memberId: number,
name: string,
......@@ -12,7 +13,9 @@ export interface AuthInfo {
logo: string,
levelTag: string,
creditPoint: number,
urls: string[]
memberRoleType: number,
memberRoleId: number,
roles: any,
}
const AUTH_KEY = 'AUTH'
......@@ -27,6 +30,7 @@ export const setAuth = (info: AuthInfo) => {
creditPoint: info.creditPoint
}
setCookie(AUTH_KEY, JSON.stringify(auth), { domain: TOP_DOMAIN })
setCookie('AUTH_ROLES', JSON.stringify(info.roles), { domain: TOP_DOMAIN })
setLocalAuth(info)
setRouters(info.urls)
}
......@@ -40,6 +44,8 @@ export const setLocalAuth = (info: AuthInfo) => {
export const getAuth = (): AuthInfo => {
try {
// const localAuth: AuthInfo = getCookie('AUTH') as unknown as AuthInfo
// return (localAuth || {}) as AuthInfo
const localAuth = JSON.parse(window.localStorage.getItem(AUTH_KEY))
return (localAuth || {} )as AuthInfo
} catch (error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment