SysUsers.cshtml 15 KB

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