Commit 53ba6f5f authored by 前端-许佳敏's avatar 前端-许佳敏

权限校验优化

parent 89f42eff
......@@ -43,6 +43,7 @@
"moment": "^2.27.0",
"prettier": "^1.19.1",
"qrcode": "^1.4.4",
"query-string": "^6.13.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-fontawesome": "^1.7.1",
......
......@@ -2,6 +2,7 @@ import { IRoutes } from '.';
import { history, RequestConfig, Redirect } from 'umi';
import React from 'react'
import MobxProvider from './store'
import queryString from 'query-string'
import '@/global/styles/reset.less'; // 重置antd样式
import '@/global/styles/global.less'; // 导入全局样式
......@@ -96,11 +97,10 @@ export function render(oldRender: Function) {
*/
export function onRouteChange({ routes, matchedRoutes, location, action }) {
console.log('onRouteChange')
console.log(window.location.search)
if (isDev) {
return;
}
// if (isDev) {
// return;
// }
if (whiteLists.includes(location.pathname)) return;
......@@ -108,15 +108,16 @@ export function onRouteChange({ routes, matchedRoutes, location, action }) {
// 是否登录
if (getAuth()) {
const { query, pathname } = location
// return ;
// // 固定配置, 出现此参数说明需携带参数校验权限路由
// if (query.page_type && routeAuthUrls.find(authPath => {
// })) {
// return ;
// }
// console.log(query)
// 固定配置, 出现此参数说明需携带参数校验权限路由
if (query.page_type && routeAuthUrls.find(authPath => {
const parseUrl = queryString.parseUrl(authPath)
const { query: selfQuery, url } = parseUrl
// 当页面出现参数page_type时, 需进入深度校验, 即对应的参数和路径匹配
return url === pathname && selfQuery.page_type === query.page_type
})) {
// 深度匹配成功, 可正常访问
return ;
}
// 是否在路由权限列表里
if (routeAuthUrls.includes(pathname)) {
return ;
......
......@@ -3,6 +3,7 @@ import moment from 'moment';
import deepClone from 'clone'
import { ISchema } from '@formily/antd';
import { UPLOAD_TYPE } from '@/constants';
import queryString from 'query-string'
function isArray(arr: any) {
return Array.isArray(arr)
......@@ -332,8 +333,10 @@ export const getFieldType = (field) => {
export const getQueryStringParams = (url?: string) => {
const nowUrl = url || window.location.href
const splitUrl = nowUrl.split('?')
const searchParam = [1]
const firstIndex = nowUrl.indexOf('?')
const searchParam = url ? url.substring(firstIndex) : window.location.search
return queryString.parse(searchParam)
}
export default {
isArray,
......
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