ABP开发手记13 - 更新菜单
程序员文章站
2023-10-27 09:31:52
点这里进入ABP开发手记目录 菜单更新 在展示层(即JD.CRS.Web.Mvc)的Startup下打开CRSNavigationProvider.cs //用以存放菜单相关信息 修改如下 1 using Abp.Application.Navigation; 2 using Abp.Localiz ......
菜单更新
在展示层(即jd.crs.web.mvc)的startup下打开crsnavigationprovider.cs //用以存放菜单相关信息
修改如下
1 using abp.application.navigation; 2 using abp.localization; 3 using jd.crs.authorization; 4 5 namespace jd.crs.web.startup 6 { 7 /// <summary> 8 /// this class defines menus for the application. 9 /// </summary> 10 public class crsnavigationprovider : navigationprovider 11 { 12 public override void setnavigation(inavigationprovidercontext context) 13 { 14 context.manager.mainmenu 15 .additem( //一级菜单 - 首页 16 new menuitemdefinition( 17 pagenames.home, 18 l("homepage"), 19 url: "", 20 icon: "home", 21 requiredpermissionname: permissionnames.pages_home 22 ) 23 ) 24 .additem( //一级菜单 - 基础数据 25 new menuitemdefinition( 26 "data", 27 l("data"), 28 icon: "storage" 29 ).additem( //二级菜单 - 办公室设置 30 new menuitemdefinition( 31 pagenames.office, 32 l("office"), 33 url: "office", 34 requiredpermissionname: permissionnames.pages_office 35 ) 36 ).additem( //二级菜单 - 院系设置 37 new menuitemdefinition( 38 pagenames.department, 39 l("department"), 40 url: "department", 41 requiredpermissionname: permissionnames.pages_department 42 ) 43 ).additem( //二级菜单 - 课程设置 44 new menuitemdefinition( 45 pagenames.course, 46 l("course"), 47 url: "course", 48 requiredpermissionname: permissionnames.pages_course 49 ) 50 ).additem( //二级菜单 - 教职员设置 51 new menuitemdefinition( 52 pagenames.instructor, 53 l("instructor"), 54 url: "instructor", 55 requiredpermissionname: permissionnames.pages_instructor 56 ) 57 ).additem( //二级菜单 - 学生设置 58 new menuitemdefinition( 59 pagenames.student, 60 l("student"), 61 url: "student", 62 requiredpermissionname: permissionnames.pages_student 63 ) 64 ) 65 ) 66 .additem( //一级菜单 - 综合服务 67 new menuitemdefinition( 68 "operation", 69 l("operation"), 70 icon: "business" 71 ).additem( //二级菜单 - 教职员办公室设置 72 new menuitemdefinition( 73 pagenames.officeinstructor, 74 l("officeinstructor"), 75 url: "officeinstructor" 76 ) 77 ).additem( //二级菜单 - 院系主任设置 78 new menuitemdefinition( 79 pagenames.departmentinstructor, 80 l("departmentinstructor"), 81 url: "departmentinstructor" 82 ) 83 ).additem( //二级菜单 - 院系课程设置 84 new menuitemdefinition( 85 pagenames.departmentcourse, 86 l("departmentcourse"), 87 url: "departmentcourse" 88 ) 89 ).additem( //二级菜单 - 教职员课程设置 90 new menuitemdefinition( 91 pagenames.instructorcourse, 92 l("instructorcourse"), 93 url: "instructorcourse" 94 ) 95 ).additem( //二级菜单 - 学生课程设置 96 new menuitemdefinition( 97 pagenames.studentcourse, 98 l("studentcourse"), 99 url: "studentcourse" 100 ) 101 ) 102 ) 103 .additem( //一级菜单 - 管理报表 104 new menuitemdefinition( 105 "report", 106 l("report"), 107 icon: "poll" 108 ).additem( //二级菜单 - 办公室报表 109 new menuitemdefinition( 110 pagenames.officereport, 111 l("officereport"), 112 url: "officereport", 113 requiredpermissionname: permissionnames.pages_officereport 114 ) 115 ).additem( //二级菜单 - 院系报表 116 new menuitemdefinition( 117 pagenames.departmentreport, 118 l("departmentreport"), 119 url: "departmentreport", 120 requiredpermissionname: permissionnames.pages_departmentreport 121 ) 122 ).additem( //二级菜单 - 课程报表 123 new menuitemdefinition( 124 pagenames.coursereport, 125 l("coursereport"), 126 url: "coursereport", 127 requiredpermissionname: permissionnames.pages_coursereport 128 ) 129 ).additem( //二级菜单 - 教职员报表 130 new menuitemdefinition( 131 pagenames.instructorreport, 132 l("instructorreport"), 133 url: "instructorreport", 134 requiredpermissionname: permissionnames.pages_instructorreport 135 ) 136 ).additem( //二级菜单 - 学生报表 137 new menuitemdefinition( 138 pagenames.studentreport, 139 l("studentreport"), 140 url: "studentreport", 141 requiredpermissionname: permissionnames.pages_studentreport 142 ) 143 ) 144 ) 145 .additem( //一级菜单 - 系统设置 146 new menuitemdefinition( 147 "setting", 148 l("setting"), 149 icon: "settings" 150 ).additem( //二级菜单 - 租户管理 151 new menuitemdefinition( 152 pagenames.tenants, 153 l("tenants"), 154 url: "tenants", 155 requiredpermissionname: permissionnames.pages_tenants 156 ) 157 ).additem( //二级菜单 - 用户管理 158 new menuitemdefinition( 159 pagenames.users, 160 l("users"), 161 url: "users", 162 requiredpermissionname: permissionnames.pages_users 163 ) 164 ).additem( //二级菜单 - 角色管理 165 new menuitemdefinition( 166 pagenames.roles, 167 l("roles"), 168 url: "roles", 169 requiredpermissionname: permissionnames.pages_roles 170 ) 171 ) 172 ) 173 .additem( //一级菜单 - 关于 174 new menuitemdefinition( 175 pagenames.about, 176 l("about"), 177 url: "about", 178 icon: "info", 179 requiresauthentication: true 180 ) 181 ); 182 } 183 184 private static ilocalizablestring l(string name) 185 { 186 return new localizablestring(name, crsconsts.localizationsourcename); 187 } 188 } 189 }
权限更新
在领域层(即jd.crs.core)的authorization下打开crsauthorizationprovider.cs //用以存放权限相关信息
修改如下
1 using abp.authorization; 2 using abp.localization; 3 using abp.multitenancy; 4 5 namespace jd.crs.authorization 6 { 7 public class crsauthorizationprovider : authorizationprovider 8 { 9 private static ilocalizablestring l(string name) 10 { 11 return new localizablestring(name, crsconsts.localizationsourcename); 12 } 13 public override void setpermissions(ipermissiondefinitioncontext context) 14 { 15 context.createpermission(permissionnames.pages_home, l("home")); 16 context.createpermission(permissionnames.pages_office, l("office")); 17 context.createpermission(permissionnames.pages_department, l("department")); 18 context.createpermission(permissionnames.pages_course, l("course")); 19 context.createpermission(permissionnames.pages_instructor, l("instructor")); 20 context.createpermission(permissionnames.pages_student, l("student")); 21 context.createpermission(permissionnames.pages_officeinstructor, l("officeinstructor")); 22 context.createpermission(permissionnames.pages_departmentinstructor, l("departmentinstructor")); 23 context.createpermission(permissionnames.pages_departmentcourse, l("departmentcourse")); 24 context.createpermission(permissionnames.pages_instructorcourse, l("instructorcourse")); 25 context.createpermission(permissionnames.pages_studentcourse, l("studentcourse")); 26 context.createpermission(permissionnames.pages_officereport, l("officereport")); 27 context.createpermission(permissionnames.pages_departmentreport, l("departmentreport")); 28 context.createpermission(permissionnames.pages_coursereport, l("coursereport")); 29 context.createpermission(permissionnames.pages_instructorreport, l("instructorreport")); 30 context.createpermission(permissionnames.pages_studentreport, l("studentreport")); 31 context.createpermission(permissionnames.pages_tenants, l("tenants"), multitenancysides: multitenancysides.host); 32 context.createpermission(permissionnames.pages_users, l("users")); 33 context.createpermission(permissionnames.pages_roles, l("roles")); 34 } 35 } 36 }
关联更新
与菜单/权限关联的两个静态类也需要更新
jd.crs.web.mvc\startup\pagenames.cs //用以存放菜单相关静态信息
1 namespace jd.crs.web.startup 2 { 3 public class pagenames 4 { 5 public const string home = "home"; 6 public const string office = "office"; 7 public const string department = "department"; 8 public const string course = "course"; 9 public const string instructor = "instructor"; 10 public const string student = "student"; 11 public const string officeinstructor = "officeinstructor"; 12 public const string departmentinstructor = "departmentinstructor"; 13 public const string departmentcourse = "departmentcourse"; 14 public const string instructorcourse = "instructorcourse"; 15 public const string studentcourse = "studentcourse"; 16 public const string officereport = "officereport"; 17 public const string departmentreport = "departmentreport"; 18 public const string coursereport = "coursereport"; 19 public const string instructorreport = "instructorreport"; 20 public const string studentreport = "studentreport"; 21 public const string tenants = "tenants"; 22 public const string users = "users"; 23 public const string roles = "roles"; 24 public const string about = "about"; 25 } 26 }
jd.crs.core\authorization\permissionnames.cs //用以存放权限相关静态信息
1 namespace jd.crs.authorization 2 { 3 public static class permissionnames 4 { 5 public const string pages_home = "pages.home"; 6 public const string pages_data = "menu.data"; 7 public const string pages_operation = "menu.operation"; 8 public const string pages_report = "menu.report"; 9 public const string pages_setting = "menu.setting"; 10 public const string pages_about = "pages.about"; 11 public const string pages_office = "pages.office"; 12 public const string pages_department = "pages.department"; 13 public const string pages_course = "pages.course"; 14 public const string pages_instructor = "pages.instructor"; 15 public const string pages_student = "pages.student"; 16 public const string pages_officeinstructor = "pages.officeinstructor"; 17 public const string pages_departmentinstructor = "pages.departmentinstructor"; 18 public const string pages_departmentcourse = "pages.departmentcourse"; 19 public const string pages_instructorcourse = "pages.instructorcourse"; 20 public const string pages_studentcourse = "pages.studentcourse"; 21 public const string pages_officereport = "pages.officereport"; 22 public const string pages_departmentreport = "pages.departmentreport"; 23 public const string pages_coursereport = "pages.coursereport"; 24 public const string pages_instructorreport = "pages.instructorreport"; 25 public const string pages_studentreport = "pages.studentreport"; 26 public const string pages_tenants = "pages.tenants"; 27 public const string pages_users = "pages.users"; 28 public const string pages_roles = "pages.roles"; 29 } 30 }