Commit 981c80a1 authored by 前端-许佳敏's avatar 前端-许佳敏

权限修改

parent 7a9690b5
...@@ -9,7 +9,7 @@ import '@/global/styles/global.less'; // 导入全局样式 ...@@ -9,7 +9,7 @@ import '@/global/styles/global.less'; // 导入全局样式
import 'antd/dist/antd.less' import 'antd/dist/antd.less'
import { isDev } from '@/constants' import { isDev } from '@/constants'
import { setup } from '@formily/antd-components'; import { setup } from '@formily/antd-components';
import { getRouters, getAuth, asyncRouter, setAuth, setRouters } from './utils/auth'; import { getRouters, getAuth, asyncRouter, setAuth, setRouters, removeAuth, removeRouters } from './utils/auth';
import { PublicApi } from './services/api'; import { PublicApi } from './services/api';
setup() setup()
...@@ -66,13 +66,20 @@ export function render(oldRender: Function) { ...@@ -66,13 +66,20 @@ export function render(oldRender: Function) {
const authInfo = getAuth() const authInfo = getAuth()
if (authInfo) { if (authInfo) {
PublicApi.getMemberLoginReget().then(res => { PublicApi.getMemberLoginReget().then(res => {
const { data } = res const { data, code } = res
if (code === 1000) {
setAuth({ setAuth({
memberId: data.memberId, memberId: data.memberId,
userId: data.userId, userId: data.userId,
token: data.token token: data.token
}) })
setRouters(data.urls) setRouters(data.urls)
} else {
removeAuth()
removeRouters()
history.push('/user/login')
}
oldRender() oldRender()
}) })
} else { } else {
...@@ -89,22 +96,33 @@ export function render(oldRender: Function) { ...@@ -89,22 +96,33 @@ export function render(oldRender: Function) {
*/ */
export function onRouteChange({ routes, matchedRoutes, location, action }) { export function onRouteChange({ routes, matchedRoutes, location, action }) {
console.log('onRouteChange') console.log('onRouteChange')
console.log(window.location.search)
if (isDev) { if (isDev) {
return; return;
} }
if (whiteLists.includes(location.pathname)) return; if (whiteLists.includes(location.pathname)) return;
const routeAuthUrls = getRouters() const routeAuthUrls = getRouters()
// 是否登录 // 是否登录
if (getAuth()) { if (getAuth()) {
console.log(location) const { query, pathname } = location
console.log(matchedRoutes)
if (routeAuthUrls.includes(location.pathname)) {
} else { // return ;
// // 固定配置, 出现此参数说明需携带参数校验权限路由
// if (query.page_type && routeAuthUrls.find(authPath => {
// })) {
// return ;
// }
// console.log(query)
// 是否在路由权限列表里
if (routeAuthUrls.includes(pathname)) {
return ;
}
// 无权限访问时 // 无权限访问时
history.replace('/memberCenter/noAuth') history.replace('/memberCenter/noAuth')
}
} else { } else {
history.replace('/user/login') history.replace('/user/login')
} }
......
...@@ -330,6 +330,11 @@ export const getFieldType = (field) => { ...@@ -330,6 +330,11 @@ export const getFieldType = (field) => {
} }
} }
export const getQueryStringParams = (url?: string) => {
const nowUrl = url || window.location.href
const splitUrl = nowUrl.split('?')
const searchParam = [1]
}
export default { export default {
isArray, isArray,
isObject, isObject,
......
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