login.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // +----------------------------------------------------------------------
  2. // | ThinkAdmin
  3. // +----------------------------------------------------------------------
  4. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  5. // +----------------------------------------------------------------------
  6. // | 官方网站: https://thinkadmin.top
  7. // +----------------------------------------------------------------------
  8. // | 开源协议 ( https://mit-license.org )
  9. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. $(function () {
  15. window.$body = $('body');
  16. /*! 后台加密登录处理 */
  17. $body.find('[data-login-form]').map(function (that) {
  18. (that = this), require(["md5"], function (md5) {
  19. $("form").vali(function (data) {
  20. data['password'] = md5.hash(md5.hash(data['password']) + data['uniqid']);
  21. $.form.load(location.href, data, "post", function (ret) {
  22. if (parseInt(ret.code) !== 1) {
  23. $(that).find('[data-captcha]').trigger('click');
  24. $(that).find('.verify.layui-hide').removeClass('layui-hide');
  25. }
  26. }, null, null, 'false');
  27. });
  28. });
  29. });
  30. /*! 登录图形验证码刷新 */
  31. $body.on('click', '[data-captcha]', function () {
  32. var $that = $(this), $form = $that.parents('form');
  33. var action = this.dataset.captcha || location.href;
  34. if (action.length < 5) return $.msg.tips('请设置验证码请求及验证地址');
  35. var type = this.dataset.captchaType || 'captcha-type', token = this.dataset.captchaToken || 'captcha-token';
  36. var uniqid = this.dataset.fieldUniqid || 'captcha-uniqid', verify = this.dataset.fieldVerify || 'captcha-verify';
  37. $.form.load(action, {type: type, token: token}, 'post', function (ret) {
  38. if (ret.code) {
  39. $that.html('<img alt="img" src="' + ret.data.image + '"><input type="hidden">').find('input').attr('name', uniqid).val(ret.data.uniqid || '');
  40. $form.find('[name="' + verify + '"]').attr('value', ret.data.code || '').val(ret.data.code || '');
  41. return (ret.data.code || $form.find('.verify.layui-hide').removeClass('layui-hide')), false;
  42. }
  43. }, false);
  44. });
  45. /*! 初始化登录图形 */
  46. $('[data-captcha]').map(function () {
  47. $(this).trigger('click');
  48. });
  49. });