SysUser.cshtml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. @using VberZero.Session
  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.Tools.StringModel
  9. @{
  10. string activeMenu = PermissionNames.VberSystemMgUserMg; //The menu item will be active for this page.
  11. ViewBag.ActiveMenu = activeMenu;
  12. ViewBag.Title = L("UserTitle");
  13. string userTypeSelect = ViewBag.UserType, activeTypeSelect = ViewBag.IsActive, accountTypeSelect = ViewBag.AccountType, gender = ViewBag.Gender;
  14. string[] gender2 = ViewBag.Gender2,activeTypeSelect2=ViewBag.IsActive2;
  15. var accountType = AbpSession.GetAccountType();
  16. var userType = AbpSession.GetUserType();
  17. var userName = AbpSession.GetUserName();
  18. var searchItem = new List<VmSearchItem>()
  19. {
  20. new VmSearchItem("userName", L("userName")),
  21. new VmSearchItem("surname", L("realName")),
  22. new VmSearchItem("phoneNumber", L("phoneNumber")),
  23. new VmSearchItem("emailAddress", L("emailAddress")),
  24. new VmSearchItem("gender", L("genderType"), FType.I, EType.Equal).WithRadio(gender2),
  25. new VmSearchItem("isActive", L("activeState"), FType.B, EType.Equal).WithRadio(activeTypeSelect2 ),
  26. new VmSearchItem("userType", L("userType"), FType.I, EType.Equal).WithSelect(userTypeSelect ),
  27. //new SearchItem("lastLoginTime", "最后登陆时间", FieldType.Dn).SetDateItem(0),
  28. };
  29. if (accountType == VzDefinition.AccountType.System)
  30. {
  31. searchItem.Add(new VmSearchItem("accountType", L("accountType"), FType.In, EType.Equal).WithSelect(accountTypeSelect, true));
  32. }
  33. var searchForm = new VmSearch(searchItem);
  34. var table = new VmTable(VzConsts.ApiAppUrl + "User/GetAll", activeMenu, searchForm).AddItems(new List<VmTableItem>()
  35. {
  36. new VmTableItem("userName", L("userName")).WithSort(),
  37. new VmTableItem("surname", L("realName")),
  38. new VmTableItem("emailAddress", L("emailAddress")),
  39. new VmTableItem("phoneNumber", L("phoneNumber")),
  40. new VmTableItem("gender", L("genderType"), "GenderFormatter").WithSort(),
  41. new VmTableItem("userType", L("userType"), "UserTypeFormatter").WithSort(),
  42. new VmTableItem("accountType", L("accountType"), "AccountTypeFormatter").WithSort(),
  43. new VmTableItem("accountNo", L("accountState"), "AccountStateFormatter").WithSort(),
  44. new VmTableItem("isActive", L("activeState"), "ActiveStateFormatter").WithSort(),
  45. });
  46. var modalBody = new VmModalBody();
  47. modalBody.AddTab(new VmModalTab("base-info", "用户信息")
  48. .AddInputs( new List<VmInputBase>()
  49. {
  50. new VmInputHidden("id"),
  51. new VmInputHidden("userName"),
  52. })
  53. .AddGroup(new List<VmInputBase>
  54. {
  55. new VmInput("surname", L("realName")).WithRequired(),
  56. new VmInput("emailAddress", L("emailAddress")).WithRequired(),
  57. new VmInput("phoneNumber", L("phoneNumber")),
  58. },3)
  59. .AddGroup( new List<VmInputBase>()
  60. {
  61. new VmInput("accountType", L("accountType"))
  62. .WithSelect(accountTypeSelect)
  63. .WithRequired(),
  64. new VmInput("userType", L("userType"))
  65. .WithSelect(userTypeSelect)
  66. .WithRequired()
  67. })
  68. .AddGroup(new List<VmInputBase>
  69. {
  70. new VmInput("gender", L("genderType")).WithRadio(gender2).WithDefaultValue(VzDefinition.GenderType.Man.ToStr()),
  71. new VmInput("isActive", L("activeState")).WithRadio(activeTypeSelect2)
  72. })
  73. );
  74. if (userType == VzDefinition.UserType.Supper || userType == VzDefinition.UserType.System)
  75. {
  76. modalBody.AddTab("role-info", "用户角色", "<div id=\"modal-role-box\" data-init=\"false\"><div class=\"row\"></div></div>");
  77. }
  78. modalBody.AddTab("auth-info", "用户权限", "<div id=\"modal-auth-box\" data-init=\"false\"><div id=\"auth-tree\"></div></div>");
  79. var modal = new VmModal()
  80. .WithHeaderAndFooter(L("user"),"")
  81. .WithBody(modalBody);
  82. }
  83. @await Html.PartialAsync("_Table", table)
  84. @await Html.PartialAsync("_Modal", modal)
  85. @section styles
  86. {
  87. <style>
  88. .tab-pane {
  89. min-height: 250px;
  90. }
  91. #vb-tab_base-info {
  92. padding: 0;
  93. }
  94. #modal-role-box, #modal-auth-box {
  95. padding: 0 20%;
  96. }
  97. #modal-role-box {
  98. padding-right: 5%;
  99. }
  100. </style>
  101. <link href="/Metronic/assets/plugins/custom/jstree/jstree.bundle.css" rel="stylesheet" />
  102. }
  103. @section scripts
  104. {
  105. <script>
  106. var $table=$('#table'), curUserId = 0;
  107. $(function() {
  108. window.funs = LoadTable({
  109. table:$table
  110. });
  111. $('#tab-nav_role-info').on('show.bs.tab.iwb',
  112. function() {
  113. if (!$("#modal-role-box").data("init")) {
  114. $.vbAjax4({
  115. url: abp.appUrl + "user/GetRoles?userId=" + curUserId,
  116. success: function(res) {
  117. $("#modal-role-box").data("init", true);
  118. if (res && res.items && res.items.length) {
  119. var str = "";
  120. res.items.forEach(function(v) {
  121. str +=
  122. `<label class="form-check form-check-custom form-check-solid form-check-sm col-md-6 mb-2"><input class="form-check-input" name="role" type="checkbox" data-id="${v.id}" data-name="${v.name}" title="${v.name}" ${v.isCheck ? "checked" : ""}><span class="form-check-label">${v.displayName}</span></label>`;
  123. });
  124. $("#modal-role-box .row").html(str);
  125. }
  126. }
  127. });
  128. }
  129. });
  130. $('#tab-nav_auth-info').on('show.bs.tab.iwb',
  131. function() {
  132. if (!$("#modal-auth-box").data("init")) {
  133. $.vbAjax4({
  134. url: abp.appUrl + "user/GetPermissions?userId=" + curUserId,
  135. success: function(res) {
  136. $("#modal-auth-box").data("init", true);
  137. if (res) {
  138. AuthFormatter(res);
  139. }
  140. }
  141. });
  142. }
  143. });
  144. funs["btnCreate"] = function(url) {
  145. curUserId = 0;
  146. $('#modal-role-box').html('<div class="row"></div>').data("init", false);
  147. $('#modal-auth-box').html('<div id="auth-tree"></div>').data("init", false);
  148. BtnCreate({
  149. url: url,
  150. data: { accountType: @(accountType.ToInt()),userType:@(VzDefinition.UserType.Ordinary.ToInt()), isActive: 'true' },
  151. dataFun: GetSaveData
  152. });
  153. };
  154. funs["btnUpdate"] = function(url) {
  155. $('#modal-role-box').html('<div class="row"></div>').data("init", false);
  156. $('#modal-auth-box').html('<div id="auth-tree"></div>').data("init", false);
  157. var row = $table.VbTable("getSelection");
  158. if (row) {
  159. curUserId = row.id;
  160. BtnUpdate({
  161. url: url,
  162. disabled: "@Html.Raw(accountType==VzDefinition.AccountType.System&&userType.ToInt()<VzDefinition.UserType.Advanced.ToInt()?"":"userType,")@Html.Raw(userName== VberZero.BaseSystem.Users.User.AdminUserName||userName== VberZero.BaseSystem.Users.User.SystemUserName?"":"accountType,")userName",
  163. dataFun: GetSaveData
  164. },
  165. row);
  166. }
  167. };
  168. funs["btnResetLock"] = function(url) {
  169. console.log("ResetLock");
  170. var row = $table.VbTable("getSelection");
  171. if (row) {
  172. BtnConfirm(abp.localization.VberZero("UserUnLockConfirmContent"),
  173. abp.localization.VberZero("UserUnLockConfirm"),
  174. url,
  175. row);
  176. }
  177. };
  178. funs["btnResetPwd"] = function (url) {
  179. console.log("ResetPwd");
  180. var row = $table.VbTable("getSelection");
  181. if (row) {
  182. MsgConfirm(
  183. "确定重置 【" + row.name + "(" + row.userName + ") 】的密码吗?", "重置密码",
  184. function () {
  185. $(document).IwbModal("create",
  186. {
  187. url: url,
  188. data: { userName: row.userName, name: row.name, userId: row.id },
  189. title: "重置密码",
  190. modalBody: `
  191. <div class="modal-body"><form class="form-horizontal iwb-form">
  192. <input class="form-control " id="userId" name="userId" type="hidden" />
  193. <div class="form-group row">
  194. <label class="col-sm-3 col-md-2 iwb-label " for="name">用户名</label>
  195. <div class="col-sm-9 col-md-10">
  196. <div class="input-group input-group-sm " style="position: relative">
  197. <input class="form-control " id="userName" name="userName" type="text" placeholder="请输入用户名..." disabled style="width:100%" />
  198. </div>
  199. </div>
  200. </div>
  201. <div class="form-group row">
  202. <label class="col-sm-3 col-md-2 iwb-label " for="name">姓名</label>
  203. <div class="col-sm-9 col-md-10">
  204. <div class="input-group input-group-sm " style="position: relative">
  205. <input class="form-control " id="name" name="name" type="text" placeholder="请输入姓名..." disabled style="width:100%" />
  206. </div>
  207. </div>
  208. </div>
  209. <div class="form-group row">
  210. <label class="col-sm-3 col-md-2 iwb-label iwb-label-sm iwb-label-required" for="adminPassword">管理员密码</label>
  211. <div class="col-sm-9 col-md-10">
  212. <div class="input-group input-group-sm " style="position: relative">
  213. <input class="form-control required" id="adminPassword" name="adminPassword" type="password" placeholder="请输入管理员密码..." style="width:100%"/>
  214. </div>
  215. </div>
  216. </div>
  217. <div class="form-group row">
  218. <label class="col-sm-3 col-md-2 iwb-label iwb-label-sm iwb-label-required" for="newPassword">新密码</label>
  219. <div class="col-sm-9 col-md-10">
  220. <div class="input-group input-group-sm " style="position: relative">
  221. <input class="form-control required" id="newPassword" name="newPassword" type="text" placeholder="请输入新密码..." style="width:100%"/>
  222. </div>
  223. </div>
  224. </div>
  225. </form></div>`
  226. });
  227. });
  228. } else
  229. abp.message.warn(abp.localization.VberZero("SelectRecordOperation"));
  230. };
  231. funs["btnActivate"] = function(url) {
  232. console.log("Activate");
  233. var row = $table.VbTable("getSelection");
  234. if (row) {
  235. if (!row.isActive) {
  236. BtnConfirm("确定激活 【" + row.name + "(" + row.userName + ") 】用户吗?", "激活用户", url, $table, row);
  237. } else {
  238. abp.message.warn("用户已激活,请问重复操作!");
  239. }
  240. }
  241. };
  242. funs["btnDeActivate"] = function(url) {
  243. console.log("DeActivate");
  244. var row = $table.VbTable("getSelection");
  245. if (row) {
  246. if (row.isActive) {
  247. BtnConfirm("确定锁定 【" + row.name + "(" + row.userName + ") 】用户吗?", "锁定用户", url, $table, row);
  248. } else {
  249. abp.message.warn("用户已锁定,请问重复操作!");
  250. }
  251. }
  252. };
  253. });
  254. function GetSaveData() {
  255. var data = $('#modal form').formSerialize();
  256. if ($('#modal-role-box').data('init')) {
  257. var roleNames = [];
  258. $('#modal-role-box input[name="role"]').each(function() {
  259. if ($(this).is(":checked")) {
  260. roleNames.push($(this).data("name"));
  261. }
  262. });
  263. data.roleNames = roleNames;
  264. }
  265. if ($('#modal-auth-box').data('init')) {
  266. var permissionNames = $('#auth-tree').jstree(true).get_selected(false) || []; //获得所有选中节点,返回值为数组
  267. //console.log(1,permissionNames);
  268. //加上灰色的节点
  269. $(".jstree-undetermined").each(function() {
  270. permissionNames.push($(this).parent().parent().attr('id'));
  271. });
  272. data.permissionNames = permissionNames;
  273. }
  274. return data;
  275. }
  276. </script>
  277. <script src="/Metronic/assets/plugins/custom/jstree/jstree.bundle.js"></script>
  278. <script>
  279. function AuthFormatter(data) {
  280. var authData = [];
  281. authData.push(data);
  282. authData = AuthDataConvert(authData).authData;
  283. console.log(authData);
  284. $("#auth-tree").jstree("destroy");
  285. $("#auth-tree").jstree({
  286. plugins: ["wholerow", "checkbox", "types"],
  287. core: {
  288. themes: {
  289. responsive: false
  290. },
  291. data: authData
  292. },
  293. types: {
  294. default:
  295. {
  296. icon: "fa fa-folder m--font-warning"
  297. },
  298. file: {
  299. icon: "fa fa-file m--font-warning"
  300. }
  301. }
  302. });
  303. }
  304. function AuthDataConvert(data) {
  305. //console.log(data);
  306. var authData = [], j = 0;
  307. for (var i = 0; i < data.length; i++) {
  308. var item = data[i], newItem = {};
  309. newItem["id"] = item.name;
  310. newItem["text"] = item.displayName;
  311. newItem["icon"] = item.icon + " m--font-warning ";
  312. newItem["state"] = {};
  313. newItem["state"].opened = item.isOpen;
  314. var childResult = { "authData": [], "isAuth": true };
  315. if (item.children && item.children.length > 0) {
  316. childResult = AuthDataConvert(item.children);
  317. newItem["children"] = childResult.authData;
  318. }
  319. if (!(item.isAuth && childResult.isAuth)) {
  320. j++;
  321. }
  322. newItem["state"].selected = item.isAuth && childResult.isAuth;
  323. authData.push(newItem);
  324. }
  325. var result = { "authData": authData, "isAuth": j === 0 };
  326. return result;
  327. }
  328. function GetAuthData(id) {
  329. var authData = { Id: id, PermissionNames: [] };
  330. var permissionNames = $('#auth-tree').jstree(true).get_selected(false); //获得所有选中节点,返回值为数组
  331. //console.log(1,permissionNames);
  332. //加上灰色的节点
  333. $(".jstree-undetermined").each(function() {
  334. permissionNames.push($(this).parent().parent().attr('id'));
  335. });
  336. //console.log(2,permissionNames);
  337. authData.PermissionNames = permissionNames;
  338. return authData;
  339. }
  340. </script>
  341. <script>
  342. function UserTypeFormatter(v) {
  343. var name = $('#hid-userType option[value="' + v + '"]').text();
  344. if (v === 1) {
  345. return '<span class="badge badge-light-danger">' + name + '</span>';
  346. } else if (v === 2) {
  347. return '<span class="badge badge-light-success">' + name + '</span>';
  348. } else if (v === 3) {
  349. return '<span class="badge badge-light-warning">' + name + '</span>';
  350. } else if (v === 4) {
  351. return '<span class="badge badge-light-primary">' + name + '</span>';
  352. }
  353. return v;
  354. }
  355. function AccountTypeFormatter(v) {
  356. var name = $('#hid-accountType option[value="' + v + '"]').text();
  357. if (v === 1) {
  358. return '<span class="badge badge-light-danger">' + name + '</span>';
  359. } else if (v === 2) {
  360. return '<span class="badge badge-light-primary">' + name + '</span>';
  361. } else if (v === 3) {
  362. return '<span class="badge badge-light-success">' + name + '</span>';
  363. }
  364. return name;
  365. }
  366. function GenderFormatter(v) {
  367. var name = $('#hid-gender option[value="' + v + '"]').text();
  368. if (v === 1) {
  369. return '<span class="badge badge-light-success">' + name + '</span>';
  370. } else if (v === 2) {
  371. return '<span class="badge badge-light-danger">' + name + '</span>';
  372. } else {
  373. return '<span class="badge badge-light-success">' + name + '</span>';
  374. }
  375. //return name;
  376. }
  377. function AccountStateFormatter(v, r) {
  378. if (r.accountType === 1) {
  379. return '<span class="badge badge-light-primary"> 不分配</span>';
  380. }
  381. if (v) {
  382. return '<span class="badge badge-light-success"> 已分配</span>';
  383. }
  384. return '<span class="badge badge-light-danger"> 未分配</span>';
  385. }
  386. function ActiveStateFormatter(v) {
  387. var name = $('#hid-activeType option[value="' + v + '"]').text();
  388. if (v) {
  389. return '<span class="badge badge-success"> ' + name + '</span>';
  390. }
  391. return '<span class="badge badge-danger"> ' + name + '</span>';
  392. }
  393. </script>
  394. }
  395. <section style="display: none">
  396. <select id="hid-accountType">
  397. @Html.Raw(accountTypeSelect)
  398. </select>
  399. <select id="hid-gender">
  400. @Html.Raw(gender)
  401. </select>
  402. <select id="hid-activeType">
  403. @Html.Raw(activeTypeSelect)
  404. </select>
  405. <select id="hid-userType">
  406. @Html.Raw(ViewBag.UserTypeAll)
  407. </select>
  408. </section>