user.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
  2. var Controller = {
  3. login: function () {
  4. //本地验证未通过时提示
  5. $("#login-form").data("validator-options", {
  6. invalid: function (form, errors) {
  7. $.each(errors, function (i, j) {
  8. Layer.alert(j);
  9. });
  10. },
  11. });
  12. //为表单绑定事件
  13. Form.api.bindevent($("#login-form"), function (data, ret) {
  14. setTimeout(function () {
  15. location.href = ret.url ? ret.url : "/";
  16. }, 1000);
  17. });
  18. Form.api.bindevent($("#resetpwd-form"), function (data) {
  19. Layer.closeAll();
  20. });
  21. $(document).on("click", ".btn-forgot", function () {
  22. var id = "resetpwdtpl";
  23. var content = Template(id, {});
  24. Layer.open({
  25. type: 1,
  26. title: "修改",
  27. area: ["450px", "auto"],
  28. content: content,
  29. success: function (layero) {
  30. Form.api.bindevent($("#resetpwd-form", layero), function (data) {
  31. Layer.closeAll();
  32. });
  33. }
  34. });
  35. });
  36. },
  37. register: function () {
  38. //本地验证未通过时提示
  39. $("#register-form").data("validator-options", {
  40. invalid: function (form, errors) {
  41. $.each(errors, function (i, j) {
  42. Layer.alert(j);
  43. });
  44. },
  45. });
  46. //为表单绑定事件
  47. Form.api.bindevent($("#register-form"), function (data, ret) {
  48. setTimeout(function () {
  49. location.href = ret.url ? ret.url : "/";
  50. }, 1000);
  51. });
  52. },
  53. changepwd: function () {
  54. //本地验证未通过时提示
  55. $("#resetpwd-form").data("validator-options", {
  56. invalid: function (form, errors) {
  57. $.each(errors, function (i, j) {
  58. Layer.alert(j);
  59. });
  60. },
  61. });
  62. //为表单绑定事件
  63. Form.api.bindevent($("#changepwd-form"), function (data, ret) {
  64. setTimeout(function () {
  65. location.href = ret.url ? ret.url : "/";
  66. }, 1000);
  67. });
  68. },
  69. profile: function () {
  70. // 给上传按钮添加上传成功事件
  71. $("#plupload-avatar").data("upload-success", function (data) {
  72. var url = Fast.api.cdnurl(data.url);
  73. $(".profile-user-img").prop("src", url);
  74. Toastr.success("上传成功!");
  75. });
  76. //为表单绑定事件
  77. Form.api.bindevent($("#profile-form"), function (data) {
  78. });
  79. Form.api.bindevent($("#email-form"), function (data) {
  80. Layer.closeAll();
  81. $("#basic-form #email").val($("#email").val());
  82. });
  83. Form.api.bindevent($("#mobile-form"), function (data) {
  84. Layer.closeAll();
  85. $("#basic-form #mobile").val($("#mobile").val());
  86. });
  87. $(document).on("click", ".btn-change", function () {
  88. var id = $(this).data("type") + "tpl";
  89. var content = Template(id, {});
  90. Layer.open({
  91. type: 1,
  92. title: "修改",
  93. area: ["450px", "auto"],
  94. content: content,
  95. });
  96. });
  97. }
  98. };
  99. return Controller;
  100. });