frontend.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. define(['fast'], function (Fast) {
  2. var Frontend = {
  3. api: Fast.api,
  4. init: function () {
  5. //发送邮箱验证码
  6. $(document).on("click", ".btn-email", function (e) {
  7. var email = $(this).closest("form").find("#email");
  8. if (email.val() == "") {
  9. Layer.alert("邮箱不能为空!");
  10. return false;
  11. }
  12. var that = this;
  13. email.isValid(function (v) {
  14. if (v) {
  15. Frontend.api.ajax({url: "sms/sendemail", data: {type: $(that).data("type"), email: email.val()}}, function () {
  16. $(that).val("已发送");
  17. });
  18. } else {
  19. Layer.alert("请确认已经输入了正解的邮箱!");
  20. }
  21. });
  22. return false;
  23. });
  24. //发送手机验证码
  25. $(document).on("click", ".btn-captcha", function (e) {
  26. var mobile = $(this).closest("form").find("#mobile");
  27. if (mobile.val() == "") {
  28. Layer.alert("手机号码不能为空!");
  29. return false;
  30. } else if (!mobile.val().match(/^1[3-9]\d{9}$/)) {
  31. Layer.alert("请输入正确的手机号码!");
  32. return false;
  33. }
  34. var that = this;
  35. mobile.isValid(function (v) {
  36. if (v) {
  37. $(that).addClass("disabled", true).text("获取中...");
  38. var si;
  39. Frontend.api.ajax({url: "sms/send", data: {type: $(that).data("type"), mobile: mobile.val()}}, function () {
  40. Layer.msg("验证码已发送");
  41. clearInterval(si);
  42. var seconds = 60;
  43. si = setInterval(function () {
  44. seconds--;
  45. if (seconds <= 0) {
  46. clearInterval(si);
  47. $(that).removeClass("disabled", false).text("获取验证码");
  48. } else {
  49. $(that).addClass("disabled", true).text(seconds + "秒后可再次发送");
  50. }
  51. }, 1000);
  52. });
  53. } else {
  54. Layer.alert("请确认已经输入了正解的手机号!");
  55. }
  56. });
  57. return false;
  58. });
  59. }
  60. };
  61. Frontend.api = $.extend(Fast.api, Frontend.api);
  62. //将Frontend渲染至全局,以便于在子框架中调用
  63. window.Frontend = Frontend;
  64. Frontend.init();
  65. return Frontend;
  66. });