mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	fix: 修复动态路由 rank 问题
				
					
				
			This commit is contained in:
		
							parent
							
								
									7987a18c70
								
							
						
					
					
						commit
						1419df10d2
					
				@ -5,7 +5,7 @@ export const auth: Directive = {
 | 
				
			|||||||
  mounted(el: HTMLElement, binding: DirectiveBinding) {
 | 
					  mounted(el: HTMLElement, binding: DirectiveBinding) {
 | 
				
			||||||
    const { value } = binding;
 | 
					    const { value } = binding;
 | 
				
			||||||
    if (value) {
 | 
					    if (value) {
 | 
				
			||||||
      !hasAuth(value) && el.parentNode.removeChild(el);
 | 
					      !hasAuth(value) && el.parentNode?.removeChild(el);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      throw new Error("need auths! Like v-auth=\"['btn.add','btn.edit']\"");
 | 
					      throw new Error("need auths! Like v-auth=\"['btn.add','btn.edit']\"");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -29,9 +29,13 @@ const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
 | 
				
			|||||||
// 动态路由
 | 
					// 动态路由
 | 
				
			||||||
import { getAsyncRoutes } from "@/api/routes";
 | 
					import { getAsyncRoutes } from "@/api/routes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function handRank(ramk: number, name: string, path: string) {
 | 
					function handRank(routeInfo: any) {
 | 
				
			||||||
  return isAllEmpty(ramk) || (ramk === 0 && name !== "Home" && path !== "/")
 | 
					  const { name, path, parentId, meta } = routeInfo;
 | 
				
			||||||
    ? true
 | 
					  return isAllEmpty(parentId)
 | 
				
			||||||
 | 
					    ? isAllEmpty(meta?.rank) ||
 | 
				
			||||||
 | 
					      (meta?.rank === 0 && name !== "Home" && path !== "/")
 | 
				
			||||||
 | 
					      ? true
 | 
				
			||||||
 | 
					      : false
 | 
				
			||||||
    : false;
 | 
					    : false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,7 +43,7 @@ function handRank(ramk: number, name: string, path: string) {
 | 
				
			|||||||
function ascending(arr: any[]) {
 | 
					function ascending(arr: any[]) {
 | 
				
			||||||
  arr.forEach((v, index) => {
 | 
					  arr.forEach((v, index) => {
 | 
				
			||||||
    // 当rank不存在时,根据顺序自动创建,首页路由永远在第一位
 | 
					    // 当rank不存在时,根据顺序自动创建,首页路由永远在第一位
 | 
				
			||||||
    if (handRank(v?.meta?.rank, v.name, v.path)) v.meta.rank = index + 2;
 | 
					    if (handRank(v)) v.meta.rank = index + 2;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
  return arr.sort(
 | 
					  return arr.sort(
 | 
				
			||||||
    (a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
 | 
					    (a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
 | 
				
			||||||
@ -351,6 +355,7 @@ function hasAuth(value: string | Array<string>): boolean {
 | 
				
			|||||||
  if (!value) return false;
 | 
					  if (!value) return false;
 | 
				
			||||||
  /** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */
 | 
					  /** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */
 | 
				
			||||||
  const metaAuths = getAuths();
 | 
					  const metaAuths = getAuths();
 | 
				
			||||||
 | 
					  if (!metaAuths) return false;
 | 
				
			||||||
  const isAuths = isString(value)
 | 
					  const isAuths = isString(value)
 | 
				
			||||||
    ? metaAuths.includes(value)
 | 
					    ? metaAuths.includes(value)
 | 
				
			||||||
    : isIncludeAllChildren(value, metaAuths);
 | 
					    : isIncludeAllChildren(value, metaAuths);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user