login.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. $(function () {
  2. window.$body = $("body");
  3. /*! 后台加密登录处理 */
  4. $body.find("[data-login-form]").map(function (that) {
  5. (that = this),
  6. require(["md5"], function (md5) {
  7. $("form").vali(function (data) {
  8. data["password"] = md5.hash(md5.hash(data["password"]) + data["uniqid"]);
  9. $.form.load(
  10. location.href,
  11. data,
  12. "post",
  13. function (ret) {
  14. if (parseInt(ret.code) !== 1) {
  15. $(that).find("[data-captcha]").trigger("click");
  16. $(that).find(".verify.layui-hide").removeClass("layui-hide");
  17. }
  18. },
  19. null,
  20. null,
  21. "false"
  22. );
  23. });
  24. });
  25. });
  26. /*! 登录图形验证码刷新 */
  27. $body.on("click", "[data-captcha]", function () {
  28. var $that = $(this),
  29. $form = $that.parents("form");
  30. var action = this.dataset.captcha || location.href;
  31. if (action.length < 5) return $.msg.tips("请设置验证码请求及验证地址");
  32. var type = this.dataset.captchaType || "captcha-type",
  33. token = this.dataset.captchaToken || "captcha-token";
  34. var uniqid = this.dataset.fieldUniqid || "captcha-uniqid",
  35. verify = this.dataset.fieldVerify || "captcha-verify";
  36. $.form.load(
  37. action,
  38. { type: type, token: token },
  39. "post",
  40. function (ret) {
  41. if (ret.code) {
  42. $that
  43. .html('<img alt="img" src="' + ret.data.image + '"><input type="hidden">')
  44. .find("input")
  45. .attr("name", uniqid)
  46. .val(ret.data.uniqid || "");
  47. $form
  48. .find('[name="' + verify + '"]')
  49. .attr("value", ret.data.code || "")
  50. .val(ret.data.code || "");
  51. return ret.data.code || $form.find(".verify.layui-hide").removeClass("layui-hide"), false;
  52. }
  53. },
  54. false
  55. );
  56. });
  57. /*! 初始化登录图形 */
  58. $("[data-captcha]").map(function () {
  59. $(this).trigger("click");
  60. });
  61. });