zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.jeecg.modules.system.util;
 
import java.util.List;
 
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysPermission;
 
/**
 * @Author: scott
 * @Date: 2019-04-03
 */
public class PermissionDataUtil {
 
    /**
     * 智能处理错误数据,简化用户失误操作
     * 
     * @param permission
     */
    public static SysPermission intelligentProcessData(SysPermission permission) {
        if (permission == null) {
            return null;
        }
 
        // 组件
        if (oConvertUtils.isNotEmpty(permission.getComponent())) {
            String component = permission.getComponent();
            if (component.startsWith("/")) {
                component = component.substring(1);
            }
            if (component.startsWith("views/")) {
                component = component.replaceFirst("views/", "");
            }
            if (component.startsWith("src/views/")) {
                component = component.replaceFirst("src/views/", "");
            }
            if (component.endsWith(".vue")) {
                component = component.replace(".vue", "");
            }
            permission.setComponent(component);
        }
        
        // 请求URL
        if (oConvertUtils.isNotEmpty(permission.getUrl())) {
            String url = permission.getUrl();
            if (url.endsWith(".vue")) {
                url = url.replace(".vue", "");
            }
            if (!url.startsWith("http") && !url.startsWith("/")&&!url.trim().startsWith("{{")) {
                url = "/" + url;
            }
            permission.setUrl(url);
        }
        
        // 一级菜单默认组件
        if (0 == permission.getMenuType() && oConvertUtils.isEmpty(permission.getComponent())) {
            // 一级菜单默认组件
            permission.setComponent("layouts/RouteView");
        }
        return permission;
    }
    
    /**
     * 如果没有index页面 需要new 一个放到list中
     * @param metaList
     */
    public static void addIndexPage(List<SysPermission> metaList) {
        boolean hasIndexMenu = false;
        for (SysPermission sysPermission : metaList) {
            if("首页".equals(sysPermission.getName())) {
                hasIndexMenu = true;
                break;
            }
        }
        if(!hasIndexMenu) {
            metaList.add(0,new SysPermission(true));
        }
    }
 
    /**
     * 判断是否授权首页
     * @param metaList
     * @return
     */
    public static boolean hasIndexPage(List<SysPermission> metaList){
        boolean hasIndexMenu = false;
        for (SysPermission sysPermission : metaList) {
            if("首页".equals(sysPermission.getName())) {
                hasIndexMenu = true;
                break;
            }
        }
        return hasIndexMenu;
    }
    
}