top-common.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //编辑基本资料
  2. function editUser(userId) {
  3. //清空数据
  4. $("#infoform")[0].reset();
  5. $.ajax({
  6. url: "user/editUser",
  7. data: {id: userId},
  8. dataType: "json",
  9. success: function (data) {
  10. data.userPass = "";
  11. $("#infoModal").modal('show');
  12. $("#infoform").setForm(data);
  13. }
  14. });
  15. }
  16. //更新基本资料
  17. function updateUser() {
  18. var flag = $("#infoform").valid();
  19. var dataArr = $("#infoform").serializeArray();
  20. if (dataArr && flag) {
  21. var param = {};
  22. $.each(dataArr, function (i, obj) {
  23. param[obj.name] = obj.value;
  24. });
  25. $.ajax({
  26. url: "user/updateUser",
  27. type: "post",
  28. contentType:"application/json;charset=utf-8",
  29. data: JSON.stringify(param),
  30. success: function (data) {
  31. if (data.success) {
  32. $("#infoModal").modal('hide');
  33. swal({title: "修改成功", text: "数据已修改", type: "success", confirmButtonColor: "#1ab394"});
  34. } else {
  35. swal({title: "修改失败", text: data.msg, type: "error", confirmButtonColor: "#1ab394"});
  36. }
  37. }
  38. });
  39. }
  40. }
  41. //编辑账户密码
  42. function editAcount(userId) {
  43. $.validator.addMethod("checkPwd", function (value, element, params) {
  44. return this.optional(element) || /^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8,16}$/.test(value);
  45. }, "密码至少包一个大写字母、一个小写字母及一个数字,长度至少8位");
  46. $("#accountform").validate({
  47. rules: {
  48. password: {
  49. required: true,
  50. checkPwd: true
  51. },
  52. repassword: {
  53. required: true,
  54. rangelength: [8, 15],
  55. equalTo: "#password"
  56. }
  57. },
  58. messages: {
  59. password: {
  60. required: '请输入新密码',
  61. regexPassword: "密码至少包一个大写字母、一个小写字母及一个数字,长度至少8位",
  62. },
  63. repassword: {
  64. required: "请输入确认密码",
  65. rangelength: "确认密码不能小于8个字符",
  66. equalTo: "两次输入密码不一致"
  67. }
  68. }
  69. });
  70. $("#accountform")[0].reset();
  71. $("#accountform").find("input[name='id']").val(userId);
  72. $("#accountModal").modal('show');
  73. }
  74. //更新账户密码
  75. function updateAccount() {
  76. var flag = $("#accountform").valid();
  77. var dataArr = $("#accountform").serializeArray();
  78. if (flag && dataArr) {
  79. var param = {};
  80. $.each(dataArr, function (i, obj) {
  81. param[obj.name] = obj.value;
  82. });
  83. $.ajax({
  84. url: "user/updatePsw",
  85. type: "post",
  86. contentType:"application/json;charset=utf-8",
  87. data: JSON.stringify(param),
  88. success: function (data) {
  89. if (data.success) {
  90. $("#accountModal").modal('hide');
  91. swal({title: "修改成功", text: "数据已修改", type: "success", confirmButtonColor: "#1ab394"});
  92. } else {
  93. swal({title: "修改失败", text: data.msg, type: "error", confirmButtonColor: "#1ab394"});
  94. }
  95. }
  96. });
  97. }
  98. }
  99. //渲染top中信息图标
  100. window.onload=function() {
  101. var userId=$("#p_userId").html();
  102. /*getNoReadMessage(userId);*/
  103. }