user-add.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * 用户页面js
  3. */
  4. $("#form-add").validate({
  5. rules:{
  6. username:{
  7. required:true,
  8. minlength: 2,
  9. maxlength: 20,
  10. remote: {
  11. url: rootPath + "/UserVueController/checkLoginNameUnique",
  12. type: "post",
  13. dataType: "json",
  14. dataFilter: function(data, type) {
  15. if (data == "0")
  16. return true;
  17. else
  18. return false;
  19. }
  20. }
  21. },
  22. deptName:{
  23. required:true,
  24. },
  25. password:{
  26. required:true,
  27. minlength: 5,
  28. maxlength: 20
  29. },
  30. email:{
  31. required:true,
  32. email:true,
  33. remote: {
  34. url:rootPath + "/UserVueController/checkEmailUnique",
  35. type: "post",
  36. dataType: "json",
  37. data: {
  38. name: function () {
  39. return $.trim($("#email").val());
  40. }
  41. },
  42. dataFilter: function (data, type) {
  43. if (data == "0") return true;
  44. else return false;
  45. }
  46. }
  47. },
  48. phonenumber:{
  49. required:true,
  50. isPhone:true,
  51. remote: {
  52. url: rootPath + "/system/user/checkPhoneUnique",
  53. type: "post",
  54. dataType: "json",
  55. data: {
  56. name: function () {
  57. return $.trim($("#phonenumber").val());
  58. }
  59. },
  60. dataFilter: function (data, type) {
  61. if (data == "0") return true;
  62. else return false;
  63. }
  64. }
  65. },
  66. },
  67. messages: {
  68. "username": {
  69. remote: "用户已经存在"
  70. },
  71. "email": {
  72. remote: "Email已经存在"
  73. },
  74. "phonenumber":{
  75. remote: "手机号码已经存在"
  76. }
  77. },
  78. submitHandler:function(form){
  79. add();
  80. }
  81. });
  82. /**
  83. * 用户添加方法
  84. */
  85. function add() {
  86. var dataFormJson=$("#form-add").serialize();
  87. $.ajax({
  88. cache : true,
  89. type : "POST",
  90. url : rootPath + "/UserVueController/add",
  91. data : dataFormJson,
  92. async : false,
  93. error : function(request) {
  94. $.modal.alertError("系统错误");
  95. },
  96. success : function(data) {
  97. $.operate.saveSuccess(data);
  98. }
  99. });
  100. }