SysUsers.cshtml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. @using WeApp
  2. @using WeApp.Authorization
  3. @using WeApp.Configuration
  4. @using WeApp.Views.Shared.Modals
  5. @using WeApp.Views.Shared.SearchForm
  6. @using WeApp.Views.Shared.Table
  7. @{
  8. string activeMenu = PermissionNames.PagesSystemMgUserMg; //The menu item will be active for this page.
  9. ViewBag.ActiveMenu = activeMenu;
  10. ViewBag.Title = L("UserTitle");
  11. List<SelectListItem> userType = ViewBag.UserType;
  12. List<SelectListItem> activeType = ViewBag.IsActive;
  13. List<SelectListItem> accountType = ViewBag.AccountType;
  14. var searchItem = new List<SearchItem>()
  15. {
  16. new SearchItem("userName", L("userName")),
  17. new SearchItem("name", L("realName")),
  18. new SearchItem("userType", L("userType"), FieldType.I, ExpType.Equal).SetSelectItem(userType,true),
  19. new SearchItem("emailAddress", L("emailAddress")),
  20. new SearchItem("isActive", L("activeState"), FieldType.B, ExpType.Equal).SetSelectItem(activeType,true),
  21. //new SearchItem("lastLoginTime", "最后登陆时间", FieldType.Dn).SetDateItem(0),
  22. };
  23. if (AbpSession.AccountType == 1)
  24. {
  25. searchItem.Add(new SearchItem("accountType", L("accountType"), FieldType.In, ExpType.Equal).SetSelectItem(accountType, true));
  26. }
  27. var searchForm = new SearchFormViewModel(searchItem);
  28. var table = new TableViewModel(IwbConsts.ApiAppUrl + "Users/GetAll", activeMenu, searchForm).SetFields(new List<FieldItem>()
  29. {
  30. new FieldItem("userName", L("userName")),
  31. new FieldItem("name", L("realName")),
  32. new FieldItem("emailAddress", L("emailAddress")),
  33. new FieldItem("userType", L("userType"), "UserTypeFormatter"),
  34. new FieldItem("accountType", L("accountType"), "AccountTypeFormatter"),
  35. new FieldItem("", L("accountState"), "AccountStateFormatter"),
  36. new FieldItem("isActive", L("activeState"), "ActiveStateFormatter"),
  37. });
  38. }
  39. @section styles{
  40. <link href="~/Content/Libs/jstree/themes/default/style.min.css" rel="stylesheet" />
  41. }
  42. @Html.Partial("Table/_Table", table)
  43. @section modal{
  44. @{
  45. var inputs = new List<Input>()
  46. {
  47. new InputHide("id"),
  48. new InputHide("userName"),
  49. new Input("userType", L("userType")).SetSelectOptions(userType),
  50. new Input("name", L("realName")),
  51. new Input("emailAddress", L("emailAddress")),
  52. new Input("isActive", L("activeState")).SetSelectOptions(activeType)
  53. };
  54. if (AbpSession.AccountType == AccountTypeDefinition.System)
  55. {
  56. inputs.Add(new Input("accountType", L("accountType"))
  57. .SetSelectOptions(accountType));
  58. //inputs.Add(new Input("accountNo", InputTypes.List, "账号所属").SetNotRequired());
  59. }
  60. else
  61. {
  62. inputs.Add(new Input("accountType", value: AbpSession.AccountType + "", hide: true));
  63. inputs.Add(new Input("accountTypeName", L("accountType"), value: ViewBag.AccountTypeName).SetNotRequired());
  64. //inputs.Add(new Input("accountNo", InputTypes.List, "账号所属").SetNotRequired());
  65. }
  66. if (AbpSession.UserType == UsersAndRolesTypeDefinition.Supper || AbpSession.UserType == UsersAndRolesTypeDefinition.System)
  67. {
  68. inputs.Add(new Input("roleNames", L("roleInfos")).SetNotRequired()
  69. .SetSelectOptions((List<SelectListItem>)ViewBag.Roles, true));
  70. }
  71. var modal = new ModalViewModel(L("user"), new ModalBodyViewModel(inputs));
  72. }
  73. @Html.Partial("Modals/_Modal", modal)
  74. <section>
  75. <!--Auth Modal -->
  76. <div class="modal fade" id="auth_Modal" role="dialog" aria-labelledby="ModalLabel_AUTH" aria-hidden="true">
  77. <div class="modal-dialog" role="document" style="min-height: 700px; width: 500px;">
  78. <div class="modal-content" style="">
  79. @Html.Partial("Modals/_ModalHeader", new ModalHeaderViewModel(L("userAuthSetting"), ""))
  80. <form>
  81. <div class="modal-body" style=" padding: 10px 30px;">
  82. <div class="" id="auth-tree"></div>
  83. </div>
  84. </form>
  85. @Html.Partial("Modals/_ModalFooter", "0")
  86. </div>
  87. </div>
  88. </div>
  89. </section>
  90. }
  91. @section scripts
  92. {
  93. <script src="~/Content/Libs/jstree/jstree.min.js"></script>
  94. <script type="text/javascript">
  95. $(function() {
  96. var $table = LoadTable();
  97. var funs = window.iwbfuns || { none: function() { console.log("No type"); } };
  98. funs["btnCreate"] = function() {
  99. BtnCreate({
  100. data: { accountType: "@AbpSession.AccountType", accountTypeName: "@ViewBag.AccountTypeName" }
  101. });
  102. };
  103. @{
  104. var disabled = AbpSession.UserType == UsersAndRolesTypeDefinition.Supper ? "" : ",userType,accountType";
  105. }
  106. funs["btnUpdate"] = function() {
  107. var rows = $table.bootstrapTable("getSelections");
  108. if (rows.length === 1) {
  109. var userId = rows[0].id;
  110. $.iwbAjax4({
  111. url: abp.appUrl + 'Users/GetUserRoles?UserId=' + userId,
  112. dataType: "json",
  113. success: function(res) {
  114. var data = rows[0];
  115. data.roleNames = res;
  116. //console.log(data);
  117. //$("#accountType").off("change.accountType");
  118. BtnUpdate({ disabled: "userName@(Html.Raw(disabled))", data: data });
  119. //$("#accountType").on("change.accountType", ChangeAccountList);
  120. //ChangeAccountList(rows[0].accountNo);
  121. }
  122. });
  123. }
  124. };
  125. funs["btnResetLock"] = function(url) {
  126. var row = $table.bootstrapTable("getSelections")[0];
  127. if (row) {
  128. BtnConfirm(abp.localization.iwbZero("UserUnLockConfirmContent"), abp.localization.iwbZero("UserUnLockConfirm"), url, row);
  129. }
  130. };
  131. funs["btnAuth"] = function(url) {
  132. var rows = $table.bootstrapTable("getSelections");
  133. if (rows.length === 1) {
  134. abp.ui.setBusy();
  135. var userId = rows[0].id;
  136. $.iwbAjax4({
  137. url: abp.appUrl + 'Users/GetPermissions?userId=' + userId,
  138. success: function(res) {
  139. $("#auth_Modal").on('show.bs.modal',
  140. function() {
  141. AuthFormatter(res);
  142. $("#auth_Modal").find("button.save-btn").off("click").on("click",
  143. function() {
  144. var authData = GetAuthData(userId);
  145. $.iwbAjax1({
  146. url: url,
  147. success: function() { $("#auth_Modal").modal("hide"); },
  148. data: authData
  149. });
  150. });
  151. });
  152. $("#auth_Modal").modal("show");
  153. }
  154. });
  155. } else
  156. abp.message.warn(abp.localization.iwbZero("SelectRecordOperation"));
  157. };
  158. funs["btnResetPwd"] = function(url) {
  159. console.log("ResetPwd");
  160. var row = $table.bootstrapTable("getSelections")[0];
  161. if (row) {
  162. MsgConfirm(
  163. "确定重置 【" + row.name + "(" + row.userName + ") 】的密码吗?", "重置密码",
  164. function() {
  165. $.iwbAjax1({ url: url, data: { Id: row.id }, isValidate: false });
  166. });
  167. } else
  168. abp.message.warn(abp.localization.iwbZero("SelectRecordOperation"));
  169. };
  170. //ChangeAccountList(null,"@AbpSession.AccountType");
  171. // $("#accountType").on("change.accountType", ChangeAccountList);
  172. });
  173. //function ChangeAccountList(accountNo, accountType) {
  174. // accountType = accountType||$("#accountType").val();
  175. // if (accountType === "1") {
  176. // $("#accountNo").closest(".form-group-sm").css("display", "none");
  177. // } else {
  178. // var url = window.appUrl + (accountType === "2" ? "LawyerInfo/GetSelectStrForNoAccount" : "CustomerContact/GetSelectStrForNoAccount");
  179. // abp.ajax({
  180. // url: url,
  181. // type: 'POST',
  182. // dataType: "json",
  183. // success: function (res) {
  184. // console.log(res);
  185. // res = '<option value="">请选择...</option>' + res;
  186. // $("#accountNo").closest(".form-group-sm").css("display", "block");
  187. // if (accountNo) {
  188. // $("#accountNo").html(res).val(accountNo).select2();
  189. // } else {
  190. // $("#accountNo").html(res).select2();
  191. // }
  192. // }
  193. // });
  194. // }
  195. //}
  196. </script>
  197. <script>
  198. function AuthFormatter(data) {
  199. var authData = [];
  200. authData.push(data);
  201. authData = AuthDataConvert(authData).authData;
  202. console.log(authData);
  203. $("#auth-tree").jstree("destroy");
  204. $("#auth-tree").jstree({
  205. plugins: ["wholerow", "checkbox", "types"],
  206. core: {
  207. themes: {
  208. responsive: false
  209. },
  210. data: authData
  211. },
  212. types: {
  213. default:
  214. {
  215. icon: "fa fa-folder m--font-warning"
  216. },
  217. file: {
  218. icon: "fa fa-file m--font-warning"
  219. }
  220. }
  221. });
  222. //[{
  223. // text: "Same but with checkboxes",
  224. // children: [{
  225. // id:"",
  226. // text: "initially selected",
  227. // state: {
  228. // selected: !0
  229. // opened: !0
  230. // disabled: !0
  231. // }
  232. // }]
  233. // }]
  234. }
  235. function AuthDataConvert(data) {
  236. //console.log(data);
  237. var authData = [], j = 0;
  238. for (var i = 0; i < data.length; i++) {
  239. var item = data[i], newItem = {};
  240. newItem["id"] = item.name;
  241. newItem["text"] = item.permDisplayName;
  242. newItem["icon"] = item.icon + " m--font-warning ";
  243. newItem["state"] = {};
  244. newItem["state"].opened = item.isOpen;
  245. var childResult = { "authData": [], "isAuth": true };
  246. if (item.children && item.children.length > 0) {
  247. childResult = AuthDataConvert(item.children);
  248. newItem["children"] = childResult.authData;
  249. }
  250. if (!(item.isAuth && childResult.isAuth)) {
  251. j++;
  252. }
  253. newItem["state"].selected = item.isAuth && childResult.isAuth;
  254. authData.push(newItem);
  255. }
  256. var result = { "authData": authData, "isAuth": j === 0 };
  257. return result;
  258. }
  259. function GetAuthData(roleId) {
  260. var authData = { Id: roleId, PermissionNames: [] };
  261. var permissionNames = $('#auth-tree').jstree(true).get_selected(false); //获得所有选中节点,返回值为数组
  262. //console.log(1,permissionNames);
  263. //加上灰色的节点
  264. $(".jstree-undetermined").each(function() {
  265. permissionNames.push($(this).parent().parent().attr('id'));
  266. });
  267. //console.log(2,permissionNames);
  268. authData.PermissionNames = permissionNames;
  269. return authData;
  270. }
  271. </script>
  272. <script>
  273. function UserTypeFormatter(v) {
  274. var name = $('#modal #userType option[value="' + v + '"]').text();
  275. if (v === 0) {
  276. return '<span class="label label-danger">' + name + '</span>';
  277. } else if (v === 1) {
  278. return '<span class="label label-success">' + name + '</span>';
  279. } else if (v === 2) {
  280. return '<span class="label label-warning">' + name + '</span>';
  281. } else if (v === 3) {
  282. return '<span class="label label-primary">' + name + '</span>';
  283. }
  284. return v;
  285. }
  286. function AccountTypeFormatter(v) {
  287. var name = $('#hid-accountType option[value="' + v + '"]').text();
  288. if (v === 1) {
  289. return '<span class="label label-danger">' + name + '</span>';
  290. } else if (v === 2) {
  291. return '<span class="label label-success">' + name + '</span>';
  292. }
  293. return v;
  294. }
  295. function AccountStateFormatter(v, r) {
  296. if (r.accountType === 1) {
  297. return '<span class="label label-primary"> 不分配</span>';
  298. }
  299. if (v) {
  300. return '<span class="label label-success"> 已分配</span>';
  301. }
  302. return '<span class="label label-danger"> 未分配</span>';
  303. }
  304. function ActiveStateFormatter(v) {
  305. var name = $('#hid-activeType option[value="' + v + '"]').text();
  306. if (v) {
  307. return '<span class="label label-success"> ' + name + '</span>';
  308. }
  309. return '<span class="label label-danger"> ' + name + '</span>';
  310. }
  311. </script>
  312. }
  313. <section style="display:none">
  314. @Html.DropDownList("hid-accountType", accountType)
  315. @Html.DropDownList("hid-activeType", activeType)
  316. </section>