@@ -12,8 +12,6 @@ import {
1212 cloneDeep ,
1313 intersection ,
1414 isAllEmpty ,
15- isIncludeAllChildren ,
16- isString ,
1715 storageLocal
1816} from "@pureadmin/utils" ;
1917import { getConfig } from "@/config" ;
@@ -152,7 +150,8 @@ function addPathMatch() {
152150}
153151
154152/** 处理动态路由(后端返回的路由) */
155- function handleAsyncRoutes ( routeList ) {
153+ function handleAsyncRoutes ( routeList , authList ) {
154+ usePermissionStoreHook ( ) . handleWholeAuths ( authList ) ;
156155 if ( routeList . length === 0 ) {
157156 usePermissionStoreHook ( ) . handleWholeMenus ( routeList ) ;
158157 } else {
@@ -203,25 +202,28 @@ function initRouter() {
203202 if ( getConfig ( ) ?. CachingAsyncRoutes ) {
204203 // 开启动态路由缓存本地localStorage
205204 const key = "async-routes" ;
205+ const authKey = "async-auths" ;
206206 const asyncRouteList = storageLocal ( ) . getItem ( key ) as any ;
207+ const asyncAuthList = storageLocal ( ) . getItem ( authKey ) as any ;
207208 if ( asyncRouteList && asyncRouteList ?. length > 0 ) {
208209 return new Promise ( resolve => {
209- handleAsyncRoutes ( asyncRouteList ) ;
210+ handleAsyncRoutes ( asyncRouteList , asyncAuthList ) ;
210211 resolve ( router ) ;
211212 } ) ;
212213 } else {
213214 return new Promise ( resolve => {
214- getAsyncRoutes ( ) . then ( ( { data } ) => {
215- handleAsyncRoutes ( cloneDeep ( data ) ) ;
215+ getAsyncRoutes ( ) . then ( ( { data, auths } ) => {
216+ handleAsyncRoutes ( cloneDeep ( data ) , auths ) ;
216217 storageLocal ( ) . setItem ( key , data ) ;
218+ storageLocal ( ) . setItem ( authKey , auths ) ;
217219 resolve ( router ) ;
218220 } ) ;
219221 } ) ;
220222 }
221223 } else {
222224 return new Promise ( resolve => {
223- getAsyncRoutes ( ) . then ( ( { data } ) => {
224- handleAsyncRoutes ( cloneDeep ( data ) ) ;
225+ getAsyncRoutes ( ) . then ( ( { data, auths } ) => {
226+ handleAsyncRoutes ( cloneDeep ( data ) , auths ) ;
225227 resolve ( router ) ;
226228 } ) ;
227229 } ) ;
@@ -365,26 +367,24 @@ function getAuths(): Array<string> {
365367}
366368
367369/** 是否有按钮级别的权限 */
368- function hasAuth ( value : string | Array < string > ) : boolean {
369- if ( ! value ) return false ;
370- /** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */
371- const metaAuths = getAuths ( ) ;
372- if ( ! metaAuths ) return false ;
373- const isAuths = isString ( value )
374- ? metaAuths . includes ( value )
375- : isIncludeAllChildren ( value , metaAuths ) ;
376- return isAuths ? true : false ;
377- }
370+ // function hasAuth(value: string | Array<string>): boolean {
371+ // if (!value) return false;
372+ // /** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */
373+ // const metaAuths = getAuths();
374+ // if (!metaAuths) return false;
375+ // const isAuths = isString(value)
376+ // ? metaAuths.includes(value)
377+ // : isIncludeAllChildren(value, metaAuths);
378+ // return isAuths ? true : false;
379+ // }
378380
379381/** 是否有按钮级别的权限 */
380- function hasGlobalAuth ( value : string | Array < string > ) : boolean {
382+ function hasAuth ( value : string ) : boolean {
381383 if ( ! value ) return false ;
382384 /** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */
383- const metaAuths = usePermissionStoreHook ( ) . metaAuths ;
384- if ( ! metaAuths ) return false ;
385- return isString ( value )
386- ? metaAuths . includes ( value )
387- : isIncludeAllChildren ( value , metaAuths ) ;
385+ const permissionAuths = usePermissionStoreHook ( ) . permissionAuths ;
386+ if ( ! permissionAuths ) return false ;
387+ return permissionAuths [ value ] ;
388388}
389389
390390/** 获取所有菜单中的第一个菜单(顶级菜单)*/
@@ -420,7 +420,6 @@ export {
420420 getTopMenu ,
421421 addPathMatch ,
422422 isOneOfArray ,
423- hasGlobalAuth ,
424423 getHistoryMode ,
425424 addAsyncRoutes ,
426425 getParentPaths ,
0 commit comments