SysRole.cshtml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. 
  2. @using Microsoft.AspNetCore.Mvc.Rendering
  3. @using VberAdmin.Web.Models.Input
  4. @using VberAdmin.Web.Models.Modals
  5. @using VberAdmin.Web.Models.Search
  6. @using VberAdmin.Web.Models.Table
  7. @using VberZero
  8. @using VberZero.Session
  9. @using VberZero.Tools.StringModel
  10. @{ string activeMenu = PermissionNames.VberSystemMgRoleMg; //The menu item will be active for this page.
  11. ViewBag.ActiveMenu = activeMenu;
  12. ViewBag.Title = L("RoleTitle");
  13. string roleTypeSelect = ViewBag.RoleType, activeTypeSelect = ViewBag.IsActive, accountTypeSelect = ViewBag.AccountType;
  14. var accountType = AbpSession.GetAccountType();
  15. var searchItem = new List<VmSearchItem>()
  16. {
  17. new VmSearchItem("name", L("roleName")),
  18. new VmSearchItem("displayName", L("roleDisplayName")),
  19. new VmSearchItem("userType", L("roleType"), FType.I, EType.Equal).WithSelect(roleTypeSelect, true),
  20. };
  21. if (accountType == VzDefinition.AccountType.System)
  22. {
  23. searchItem.Add(new VmSearchItem("accountType", "账号类型", FType.I, EType.Equal).WithSelect(accountTypeSelect, true));
  24. }
  25. var searchForm = new VmSearch(searchItem);
  26. var table = new VmTable(VzConsts.ApiAppUrl + "Role/GetAll", activeMenu, searchForm).AddItems(new List<VmTableItem>()
  27. {
  28. new VmTableItem("name", L("roleName")),
  29. new VmTableItem("displayName", L("roleDisplayName")),
  30. new VmTableItem("userType", L("roleType"), "RoleTypeFormatter"),
  31. new VmTableItem("accountType", L("accountType"), "AccountTypeFormatter"),
  32. });
  33. var tab1 = new VmModalTab("role-info", "角色信息")
  34. .AddInputs(new List<VmInputBase>()
  35. {
  36. new VmInputHidden("id"),
  37. })
  38. .AddGroup(new List<VmInputBase>()
  39. {
  40. new VmInput("name", L("roleName")),
  41. new VmInput("displayName", L("roleDisplayName")).WithRequired(),
  42. });
  43. if (accountType == VzDefinition.AccountType.System)
  44. {
  45. tab1.AddGroup(new List<VmInputBase>()
  46. {
  47. new VmInput("userType", L("roleType")).WithSelect(roleTypeSelect),
  48. new VmInput("accountType", L("accountType")).WithSelect(accountTypeSelect),
  49. });
  50. }
  51. else
  52. {
  53. tab1.AddInputs(new List<VmInputBase>()
  54. {
  55. new VmInput("userType", L("roleType")).WithSelect(roleTypeSelect),
  56. new VmInputHidden("accountType").WithDefaultValue(accountType.ToStr())
  57. });
  58. }
  59. tab1.AddInput(new VmInputTextarea("description", L("roleDescription")));
  60. var modalBody = new VmModalBody()
  61. .AddTab(tab1)
  62. .AddTab("auth-info", "角色权限", "<div id=\"modal-auth-box\" data-init=\"false\"><div id=\"auth-tree\"></div></div>");
  63. var modal = new VmModal().WithHeaderAndFooter(L("role"), "").WithBody(modalBody);
  64. }
  65. @section styles{
  66. <style>
  67. #modal-auth-box {
  68. padding: 0 20%;
  69. }
  70. </style>
  71. <link href="/Metronic/assets/plugins/custom/jstree/jstree.bundle.css" rel="stylesheet" />
  72. }
  73. @await Html.PartialAsync("_Table", table)
  74. @await Html.PartialAsync("_Modal", modal)
  75. @section scripts
  76. {
  77. <script type="text/javascript">
  78. let $table = $('#table');
  79. $(function() {
  80. let curRoleId = 0;
  81. $('#tab-nav_auth-info').on('show.bs.tab.iwb',
  82. function() {
  83. if (!$("#modal-auth-box").data("init")) {
  84. $.vbAjax4({
  85. url: abp.appUrl + "role/GetPermissions?roleId=" + curRoleId,
  86. success: function(res) {
  87. $("#modal-auth-box").data("init", true);
  88. if (res) {
  89. AuthFormatter(res);
  90. }
  91. }
  92. });
  93. }
  94. });
  95. var funs = LoadTable();
  96. funs["btnCreate"] = function() {
  97. curRoleId = 0;
  98. $('#modal-auth-box').html('<div id="auth-tree"></div>').data("init", false);
  99. BtnCreate({
  100. data: { accountType: @(accountType.ToInt()),userType:@(VzDefinition.UserType.Ordinary.ToInt()) },
  101. dataFun: GetSaveData
  102. });
  103. };
  104. @{
  105. var disabled = AbpSession.GetUserType() == VzDefinition.UserType.Supper ? "" : ",userType";
  106. }
  107. funs["btnUpdate"] = function() {
  108. $('#modal-auth-box').html('<div id="auth-tree"></div>').data("init", false);
  109. var row = $table.VbTable("getSelection");
  110. if (row) {
  111. curRoleId = row.id;
  112. BtnUpdate({ disabled: "name,accountType,@(Html.Raw(disabled))", dataFun: GetSaveData });
  113. }
  114. };
  115. });
  116. function GetSaveData() {
  117. var data = $('#modal form').formSerialize();
  118. if ($('#modal-auth-box').data('init')) {
  119. var permissionNames = $('#auth-tree').jstree(true).get_selected(false)||[]; //获得所有选中节点,返回值为数组
  120. //console.log(1,permissionNames);
  121. //加上灰色的节点
  122. $(".jstree-undetermined").each(function () {
  123. permissionNames.push($(this).parent().parent().attr('id'));
  124. });
  125. data.permissionNames = permissionNames;
  126. }
  127. return data;
  128. }
  129. </script>
  130. <script src="/Metronic/assets/plugins/custom/jstree/jstree.bundle.js"></script>
  131. <script>
  132. function AuthFormatter(data) {
  133. var authData = [];
  134. authData.push(data);
  135. authData = AuthDataConvert(authData).authData;
  136. console.log(authData);
  137. $("#auth-tree").jstree("destroy");
  138. $("#auth-tree").jstree({
  139. plugins: ["wholerow", "checkbox", "types"],
  140. core: {
  141. themes: {
  142. responsive: false
  143. },
  144. data: authData
  145. },
  146. types: {
  147. default:
  148. {
  149. icon: "fa fa-folder m--font-warning"
  150. },
  151. file: {
  152. icon: "fa fa-file m--font-warning"
  153. }
  154. }
  155. });
  156. }
  157. function AuthDataConvert(data) {
  158. var authData = [], j = 0;
  159. for (var i = 0; i < data.length; i++) {
  160. var item = data[i], newItem = {};
  161. newItem["id"] = item.name;
  162. newItem["text"] = item.displayName;
  163. newItem["icon"] = item.icon + " m--font-warning ";
  164. newItem["state"] = {};
  165. newItem["state"].opened = item.isOpen;
  166. var childResult = { "authData": [], "isAuth": true };
  167. if (item.children && item.children.length > 0) {
  168. childResult = AuthDataConvert(item.children);
  169. newItem["children"] = childResult.authData;
  170. }
  171. if (!(item.isAuth && childResult.isAuth)) {
  172. j++;
  173. }
  174. newItem["state"].selected = item.isAuth && childResult.isAuth;
  175. authData.push(newItem);
  176. }
  177. var result = { "authData": authData, "isAuth": j === 0 };
  178. return result;
  179. }
  180. function GetAuthData(roleId) {
  181. var authData = { Id: roleId, PermissionNames: [] };
  182. var permissionNames = $('#auth-tree').jstree(true).get_selected(false); //获得所有选中节点,返回值为数组
  183. //console.log(1,permissionNames);
  184. //加上灰色的节点
  185. $(".jstree-undetermined").each(function () {
  186. permissionNames.push($(this).parent().parent().attr('id'));
  187. });
  188. //console.log(2,permissionNames);
  189. authData.PermissionNames = permissionNames;
  190. return authData;
  191. }
  192. </script>
  193. <script>
  194. function RoleTypeFormatter(v) {
  195. var name = $('#hid-roleType option[value="' + v + '"]').text();
  196. if (v === 1) {
  197. return '<span class="badge badge-light-danger">' + name + '</span>';
  198. } else if (v === 2) {
  199. return '<span class="badge badge-light-success">' + name + '</span>';
  200. } else if (v === 3) {
  201. return '<span class="badge badge-light-warning">' + name + '</span>';
  202. } else if (v === 4) {
  203. return '<span class="badge badge-light-primary">' + name + '</span>';
  204. }
  205. return v;
  206. }
  207. function AccountTypeFormatter(v) {
  208. var name = $('#hid-accountType option[value="' + v + '"]').text();
  209. if (v === 1) {
  210. return '<span class="badge badge-light-danger">' + name + '</span>';
  211. } else if (v === 2) {
  212. return '<span class="badge badge-light-success">' + name + '</span>';
  213. } else if (v === 3) {
  214. return '<span class="badge badge-light-primary">' + name + '</span>';
  215. }
  216. return v;
  217. }
  218. </script>
  219. }
  220. <section style="display: none">
  221. <select id="hid-accountType">
  222. @Html.Raw(accountTypeSelect)
  223. </select>
  224. <select id="hid-roleType">
  225. @Html.Raw(ViewBag.RoleTypeAll)
  226. </select>
  227. </section>