-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wuping
committed
Jan 26, 2024
1 parent
5bd9247
commit 80ca7d9
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
const Auth = (props) => { | ||
console.log(props, 'props') | ||
let role = 'admin' | ||
if (props.meta.role) { | ||
if (!role.includes(props.meta.role)) { | ||
return ( | ||
<div>没有权限</div> | ||
) | ||
} | ||
} | ||
return ( | ||
<>{props.children}</> | ||
) | ||
} | ||
|
||
const authLoad = (element, meta = {}) => { | ||
return <Auth meta={meta}>{element}</Auth>; | ||
}; | ||
|
||
const transformRoutes = (routes) => { | ||
let list = []; | ||
routes.forEach((route) => { | ||
const obj = { ...route }; | ||
if (obj.redirect) { | ||
obj.element = <Navigate to={obj.redirect} replace={true} />; | ||
} | ||
|
||
if (obj.element) { | ||
obj.element = authLoad(obj.element, obj.meta); | ||
} | ||
|
||
delete obj.redirect; | ||
delete obj.meta; | ||
|
||
if (obj.children) { | ||
obj.children = transformRoutes(obj.children); | ||
} | ||
list.push(obj); | ||
}); | ||
return list; | ||
}; | ||
|
||
|
||
|
||
|
||
export { | ||
Auth, | ||
authLoad, | ||
transformRoutes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters