You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
4.1 KiB

  1. define(['fast', 'template', 'moment'], function (Fast, Template, Moment) {
  2. var Frontend = {
  3. api: Fast.api,
  4. init: function () {
  5. var si = {};
  6. //发送验证码
  7. $(document).on("click", ".btn-captcha", function (e) {
  8. var type = $(this).data("type") ? $(this).data("type") : 'mobile';
  9. var btn = this;
  10. Frontend.api.sendcaptcha = function (btn, type, data, callback) {
  11. $(btn).addClass("disabled", true).text("发送中...");
  12. Frontend.api.ajax({url: $(btn).data("url"), data: data}, function (data, ret) {
  13. clearInterval(si[type]);
  14. var seconds = 60;
  15. si[type] = setInterval(function () {
  16. seconds--;
  17. if (seconds <= 0) {
  18. clearInterval(si);
  19. $(btn).removeClass("disabled").text("发送验证码");
  20. } else {
  21. $(btn).addClass("disabled").text(seconds + "秒后可再次发送");
  22. }
  23. }, 1000);
  24. if (typeof callback == 'function') {
  25. callback.call(this, data, ret);
  26. }
  27. }, function () {
  28. $(btn).removeClass("disabled").text('发送验证码');
  29. });
  30. };
  31. if (['mobile', 'email'].indexOf(type) > -1) {
  32. var element = $(this).data("input-id") ? $("#" + $(this).data("input-id")) : $("input[name='" + type + "']", $(this).closest("form"));
  33. var text = type === 'email' ? '邮箱' : '手机号码';
  34. if (element.val() === "") {
  35. Layer.msg(text + "不能为空!");
  36. element.focus();
  37. return false;
  38. } else if (type === 'mobile' && !element.val().match(/^1[3-9]\d{9}$/)) {
  39. Layer.msg("请输入正确的" + text + "!");
  40. element.focus();
  41. return false;
  42. } else if (type === 'email' && !element.val().match(/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/)) {
  43. Layer.msg("请输入正确的" + text + "!");
  44. element.focus();
  45. return false;
  46. }
  47. element.isValid(function (v) {
  48. if (v) {
  49. var data = {event: $(btn).data("event")};
  50. data[type] = element.val();
  51. Frontend.api.sendcaptcha(btn, type, data);
  52. } else {
  53. Layer.msg("请确认已经输入了正确的" + text + "!");
  54. }
  55. });
  56. } else {
  57. var data = {event: $(btn).data("event")};
  58. Frontend.api.sendcaptcha(btn, type, data, function (data, ret) {
  59. Layer.open({title: false, area: ["400px", "430px"], content: "<img src='" + data.image + "' width='400' height='400' /><div class='text-center panel-title'>扫一扫关注公众号获取验证码</div>", type: 1});
  60. });
  61. }
  62. return false;
  63. });
  64. //tooltip和popover
  65. if (!('ontouchstart' in document.documentElement)) {
  66. $('body').tooltip({selector: '[data-toggle="tooltip"]'});
  67. }
  68. $('body').popover({selector: '[data-toggle="popover"]'});
  69. }
  70. };
  71. Frontend.api = $.extend(Fast.api, Frontend.api);
  72. //将Template渲染至全局,以便于在子框架中调用
  73. window.Template = Template;
  74. //将Moment渲染至全局,以便于在子框架中调用
  75. window.Moment = Moment;
  76. //将Frontend渲染至全局,以便于在子框架中调用
  77. window.Frontend = Frontend;
  78. Frontend.init();
  79. return Frontend;
  80. });