user.js 4.0 KB

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