SysRoles.cshtml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. @using WePlatform
  2. @using WePlatform.Authorization
  3. @using WePlatform.Configuration
  4. @using WePlatform.Views.Shared.Modals
  5. @using WePlatform.Views.Shared.SearchForm
  6. @using WePlatform.Views.Shared.Table
  7. @{
  8. string activeMenu = PermissionNames.PagesSystemMgRoleMg; //The menu item will be active for this page.
  9. ViewBag.ActiveMenu = activeMenu;
  10. ViewBag.Title = L("RoleTitle");
  11. List<SelectListItem> roleType = ViewBag.RoleType;
  12. List<SelectListItem> activeType = ViewBag.IsActive;
  13. List<SelectListItem> accountType = ViewBag.AccountType;
  14. var searchItem = new List<SearchItem>()
  15. {
  16. new SearchItem("name", L("roleName")),
  17. new SearchItem("displayName", L("roleDisplayName")),
  18. new SearchItem("roleType", L("roleType"), FieldType.I,ExpType.Equal).SetSelectItem(roleType,true),
  19. };
  20. if (AbpSession.AccountType == 1)
  21. {
  22. searchItem.Add(new SearchItem("accountType", "账号类型", FieldType.I, ExpType.Equal).SetSelectItem(accountType));
  23. }
  24. var searchForm = new SearchFormViewModel(searchItem);
  25. var table = new TableViewModel(IwbConsts.ApiAppUrl + "Roles/GetAll", activeMenu, searchForm).SetFields(new List<FieldItem>()
  26. {
  27. new FieldItem("name", L("roleName")),
  28. new FieldItem("displayName", L("roleDisplayName")),
  29. new FieldItem("roleType", L("roleType"),"RoleTypeFormatter"),
  30. new FieldItem("accountType", L("accountType"),"AccountTypeFormatter"),
  31. });
  32. }
  33. @section styles{
  34. <link href="~/Content/Libs/jstree/themes/default/style.min.css" rel="stylesheet" />
  35. }
  36. @Html.Partial("Table/_Table", table)
  37. @section modal{
  38. @{
  39. var inputs = new List<Input>()
  40. {
  41. new InputHide("id"),
  42. new Input("name", L("roleName")),
  43. new Input("displayName", L("roleDisplayName")),
  44. new Input("roleType", L("roleType")).SetSelectOptions(roleType),
  45. new InputTextarea("description", L("roleDescription")).SetNotRequired()
  46. };
  47. if (AbpSession.AccountType == 1)
  48. {
  49. inputs.Add(new Input("accountType", L("accountType"))
  50. .SetSelectOptions(accountType));
  51. //inputs.Add(new Input("accountNo", InputTypes.List, "账号所属").SetNotRequired());
  52. }
  53. else
  54. {
  55. inputs.Add(new Input("accountType", value: AbpSession.AccountType + "", hide: true));
  56. inputs.Add(new Input("accountTypeName", L("accountType"), value: ViewBag.AccountTypeName).SetNotRequired());
  57. //inputs.Add(new Input("accountNo", InputTypes.List, "账号所属").SetNotRequired());
  58. }
  59. var modal = new ModalViewModel(L("role"), new ModalBodyViewModel(inputs));
  60. @Html.Partial("Modals/_Modal", modal)
  61. }
  62. <section>
  63. <!--Auth Modal -->
  64. <div class="modal fade" id="auth_Modal" role="dialog" aria-labelledby="ModalLabel_AUTH" aria-hidden="true">
  65. <div class="modal-dialog" role="document" style="min-height: 700px;width: 500px;">
  66. <div class="modal-content" style="">
  67. @Html.Partial("Modals/_ModalHeader", new ModalHeaderViewModel(L("roleAuthSetting"), ""))
  68. <form>
  69. <div class="modal-body" style=" padding: 10px 30px;">
  70. <div class="" id="auth-tree"></div>
  71. </div>
  72. </form>
  73. @Html.Partial("Modals/_ModalFooter", "0")
  74. </div>
  75. </div>
  76. </div>
  77. </section>
  78. }
  79. @section scripts
  80. {
  81. <script src="~/Content/Libs/jstree/jstree.min.js"></script>
  82. <script type="text/javascript">
  83. $(function () {
  84. var $table = LoadTable();
  85. var funs = window.iwbfuns || { none: function () { console.log("No type"); } };
  86. funs["btnCreate"] = function() {
  87. BtnCreate({
  88. data: { accountType: "@AbpSession.AccountType" }
  89. });
  90. };
  91. @{
  92. var disabled = AbpSession.UserType == UsersAndRolesTypeDefinition.Supper ? "" : ",roleType,accountType";
  93. }
  94. funs["btnUpdate"] = function () { BtnUpdate({ disabled: "name,accountTypeName@(Html.Raw(disabled))" }); };
  95. funs["btnAuth"] = function (url) {
  96. var row = $table.bootstrapTable("getSelections")[0];
  97. if (row) {
  98. abp.ui.setBusy();
  99. var roleId = row.id;
  100. $.iwbAjax4({
  101. url: abp.appUrl + 'Roles/GetPermissions?roleId=' + roleId,
  102. success: function (res) {
  103. $("#auth_Modal").on('show.bs.modal', function () {
  104. AuthFormatter(res);
  105. $("#auth_Modal").find("button.save-btn").off("click").on("click", function () {
  106. var authData = GetAuthData(roleId);
  107. $.iwbAjax1({
  108. url: url,
  109. success: function () { $("#auth_Modal").modal("hide"); },
  110. data: authData
  111. });
  112. });
  113. });
  114. $("#auth_Modal").modal("show");
  115. }
  116. });
  117. } else
  118. abp.message.warn(abp.localization.iwbZero("SelectRecordOperation"));
  119. };
  120. //ChangeAccountList(null,"@AbpSession.AccountType");
  121. // $("#accountType").on("change.accountType", ChangeAccountList);
  122. });
  123. //function ChangeAccountList(accountNo, accountType) {
  124. // accountType = accountType||$("#accountType").val();
  125. // if (accountType === "1") {
  126. // $("#accountNo").closest(".form-group-sm").css("display", "none");
  127. // } else {
  128. // var url = window.appUrl + (accountType === "2" ? "LawyerInfo/GetSelectStrForNoAccount" : "CustomerContact/GetSelectStrForNoAccount");
  129. // abp.ajax({
  130. // url: url,
  131. // type: 'POST',
  132. // dataType: "json",
  133. // success: function (res) {
  134. // console.log(res);
  135. // res = '<option value="">请选择...</option>' + res;
  136. // $("#accountNo").closest(".form-group-sm").css("display", "block");
  137. // if (accountNo) {
  138. // $("#accountNo").html(res).val(accountNo).select2();
  139. // } else {
  140. // $("#accountNo").html(res).select2();
  141. // }
  142. // }
  143. // });
  144. // }
  145. //}
  146. </script>
  147. <script>
  148. function AuthFormatter(data) {
  149. var authData = [];
  150. authData.push(data);
  151. authData = AuthDataConvert(authData).authData;
  152. console.log(authData);
  153. $("#auth-tree").jstree("destroy");
  154. $("#auth-tree").jstree({
  155. plugins: ["wholerow", "checkbox", "types"],
  156. core: {
  157. themes: {
  158. responsive: false
  159. },
  160. data: authData
  161. },
  162. types: {
  163. default:
  164. {
  165. icon: "fa fa-folder m--font-warning"
  166. },
  167. file: {
  168. icon: "fa fa-file m--font-warning"
  169. }
  170. }
  171. });
  172. //[{
  173. // text: "Same but with checkboxes",
  174. // children: [{
  175. // id:"",
  176. // text: "initially selected",
  177. // state: {
  178. // selected: !0
  179. // opened: !0
  180. // disabled: !0
  181. // }
  182. // }]
  183. // }]
  184. }
  185. function AuthDataConvert(data) {
  186. //console.log(data);
  187. var authData = [], j = 0;
  188. for (var i = 0; i < data.length; i++) {
  189. var item = data[i], newItem = {};
  190. newItem["id"] = item.name;
  191. newItem["text"] = item.permDisplayName;
  192. newItem["icon"] = item.icon + " m--font-warning";
  193. newItem["state"] = {};
  194. newItem["state"].opened = item.isOpen;
  195. var childResult = { "authData": [], "isAuth": true };
  196. if (item.children && item.children.length > 0) {
  197. childResult = AuthDataConvert(item.children);
  198. newItem["children"] = childResult.authData;
  199. }
  200. if (!(item.isAuth && childResult.isAuth)) {
  201. j++;
  202. }
  203. newItem["state"].selected = item.isAuth && childResult.isAuth;
  204. authData.push(newItem);
  205. }
  206. var result = { "authData": authData, "isAuth": j === 0 };
  207. return result;
  208. }
  209. function GetAuthData(roleId) {
  210. var authData = { Id: roleId, PermissionNames: [] };
  211. var permissionNames = $('#auth-tree').jstree(true).get_selected(false);//获得所有选中节点,返回值为数组
  212. //console.log(1,permissionNames);
  213. //加上灰色的节点
  214. $(".jstree-undetermined").each(function () {
  215. permissionNames.push($(this).parent().parent().attr('id'));
  216. });
  217. //console.log(2,permissionNames);
  218. authData.PermissionNames = permissionNames;
  219. return authData;
  220. }
  221. </script>
  222. <script>
  223. function RoleTypeFormatter(v) {
  224. var name = $('#modal #roleType option[value="' + v + '"]').text();
  225. if (v === 0) {
  226. return '<span class="label label-danger">' + name + '</span>';
  227. } else if (v === 1) {
  228. return '<span class="label label-success">' + name + '</span>';
  229. } else if (v === 2) {
  230. return '<span class="label label-warning">' + name + '</span>';
  231. } else if (v === 3) {
  232. return '<span class="label label-primary">' + name + '</span>';
  233. }
  234. return v;
  235. }
  236. function AccountTypeFormatter(v) {
  237. var name = $('#hid-accountType option[value="' + v + '"]').text();
  238. if (v === 1) {
  239. return '<span class="label label-danger">' + name + '</span>';
  240. } else if (v === 2) {
  241. return '<span class="label label-success">' + name + '</span>';
  242. }
  243. return v;
  244. }
  245. </script>
  246. }
  247. <section style="display:none">
  248. @Html.DropDownList("hid-accountType", accountType)
  249. </section>