Commit 7d91a387 authored by 前端-许佳敏's avatar 前端-许佳敏

新增本地环境无需鉴权功能

parent 719120aa
This diff is collapsed.
...@@ -34,10 +34,12 @@ const memberCenterRoute = { ...@@ -34,10 +34,12 @@ const memberCenterRoute = {
...routes, ...routes,
{ {
path: '/noAuth', path: '/noAuth',
auth: false,
component: '@/pages/403', component: '@/pages/403',
}, },
// 能力中心的404页 // 能力中心的404页
{ {
auth: false,
component: '@/pages/404', component: '@/pages/404',
}, },
], ],
......
...@@ -7,13 +7,13 @@ import '@/global/styles/global.less'; // 导入全局样式 ...@@ -7,13 +7,13 @@ import '@/global/styles/global.less'; // 导入全局样式
// 默认引入所有的ant样式, 不引入css因为无法做到变量覆盖 // 默认引入所有的ant样式, 不引入css因为无法做到变量覆盖
import 'antd/dist/antd.less' import 'antd/dist/antd.less'
import { isDev } from '@/constants'
import { setup } from '@formily/antd-components'; import { setup } from '@formily/antd-components';
import { GlobalConfig } from './global/config'; import { getRouters, getAuth, asyncRouter } from './utils/auth';
import { asyncRouter } from './utils/asyncRouter';
import { getRouters, getAuth } from './utils/auth';
setup() setup()
// let routeAuthUrls: any[] = [] // let routeAuthUrls: any[] = []
// 路由白名单 // 路由白名单
const whiteLists = [ const whiteLists = [
...@@ -40,6 +40,9 @@ const whiteLists = [ ...@@ -40,6 +40,9 @@ const whiteLists = [
* *
*/ */
export function patchRoutes({ routes }: IRoutes) { export function patchRoutes({ routes }: IRoutes) {
if (isDev) {
return ;
}
asyncRouter(getRouters(), routes) asyncRouter(getRouters(), routes)
} }
...@@ -62,10 +65,14 @@ export function render(oldRender:Function) { ...@@ -62,10 +65,14 @@ export function render(oldRender:Function) {
*/ */
export function onRouteChange({ routes, matchedRoutes, location, action }) { export function onRouteChange({ routes, matchedRoutes, location, action }) {
console.log(`当前可访问的路由为`) console.log(`当前可访问的路由为`)
console.log(routes) console.log(routes, matchedRoutes, location)
if (isDev) {
return ;
}
if (whiteLists.includes(location.pathname)) return ; if (whiteLists.includes(location.pathname)) return ;
const routeAuthUrls = getRouters() const routeAuthUrls = getRouters()
// 是否登录
if (getAuth()) { if (getAuth()) {
if (routeAuthUrls.includes(location.pathname)) { if (routeAuthUrls.includes(location.pathname)) {
......
...@@ -8,6 +8,9 @@ export const MALL_TYPE = { ...@@ -8,6 +8,9 @@ export const MALL_TYPE = {
5: '渠道积分商城' 5: '渠道积分商城'
} }
// 本地环境跳过权限校验
export const isDev = true
export const Environment_Status = { export const Environment_Status = {
0: "所有", 0: "所有",
1: "PC", 1: "PC",
......
...@@ -13,26 +13,9 @@ export interface UseType { ...@@ -13,26 +13,9 @@ export interface UseType {
businessType: BusinessType[]; businessType: BusinessType[];
} }
export interface Element {
id: number;
fieldName: string;
fieldCNName: string;
fieldType: string;
fieldLength: number;
fieldEmpty: number;
fieldOrder: number;
fieldRemark: string;
checkRules: any[];
}
export interface UseDetail {
groupName: string;
elements: Element[];
}
export interface UserRegister { export interface UserRegister {
useType: UseType; useType: UseType;
useDetail: UseDetail[]; useDetail: any[];
} }
export interface CountryList { export interface CountryList {
......
...@@ -4,6 +4,7 @@ import { AppstoreOutlined } from '@ant-design/icons' ...@@ -4,6 +4,7 @@ import { AppstoreOutlined } from '@ant-design/icons'
import { Link } from 'umi' import { Link } from 'umi'
import styles from '../styles/MenuSlider.less' import styles from '../styles/MenuSlider.less'
import { getRouters } from '@/utils/auth' import { getRouters } from '@/utils/auth'
import { isDev } from '@/constants'
const { Sider } = Layout const { Sider } = Layout
...@@ -12,17 +13,27 @@ export interface OuterSiderProps { ...@@ -12,17 +13,27 @@ export interface OuterSiderProps {
pathname: string | undefined; pathname: string | undefined;
} }
const OuterSider: React.FC<OuterSiderProps> = (props) => { const OuterSider: React.FC<OuterSiderProps> = (props) => {
const { menuData, pathname = "/" } = props const { menuData, pathname = "/" } = props
const authRouters = getRouters() const authRouters = getRouters()
let defaultSelectedKeys: string = "" let defaultSelectedKeys: string = ""
const isAuthPath = (path) => {
if (isDev) {
return true
} else {
return authRouters.includes(path)
}
}
const getSubMenu = () => { const getSubMenu = () => {
const subHeadMenus: Array<any> = [] const subHeadMenus: Array<any> = []
menuData.forEach(item => { menuData.forEach(item => {
if (pathname.indexOf(item.key) > -1) { if (pathname.indexOf(item.key) > -1) {
defaultSelectedKeys = item.key defaultSelectedKeys = item.key
} }
!item.hideInMenu && authRouters.includes(item.path) && subHeadMenus.push({ !item.hideInMenu && isAuthPath(item.path) && subHeadMenus.push({
path: item.path, path: item.path,
title: item.name, title: item.name,
icon: item.icon, icon: item.icon,
......
export const asyncRouter = async (routeLists: string[], routes: any[]) => {
for (let i = 0; i < routes.length; i++) {
const item = routes[i]
if (item.routes) {
asyncRouter(routeLists, item.routes)
} else {
// 参与权限校验的页面
if (item.path && !routeLists.includes(item.path)) {
item.hideInMenu = true
item.noAuth = true
}
}
}
}
...@@ -35,3 +35,18 @@ export const removeRouters = () => { ...@@ -35,3 +35,18 @@ export const removeRouters = () => {
export const removeAuth = () => { export const removeAuth = () => {
window.localStorage.removeItem('auth') window.localStorage.removeItem('auth')
} }
export const asyncRouter = async (routeLists: string[], routes: any[]) => {
for (let i = 0; i < routes.length; i++) {
const item = routes[i]
if (item.routes) {
asyncRouter(routeLists, item.routes)
} else {
// 参与权限校验的页面
if (item.path && !routeLists.includes(item.path)) {
item.hideInMenu = true
item.noAuth = true
}
}
}
}
\ No newline at end of file
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