user.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var areaData = "[12,34]";//省数据
  2. var form;
  3. var $;
  4. var userInfo = layui.sessionData(window.hywa.sessionTable.tableName);
  5. if (JSON.stringify(userInfo) == '{}') {
  6. parent.location.href = window.hywa.jumpPage.login;
  7. } else {
  8. try {
  9. userInfo = userInfo.userData;
  10. } catch (err) {
  11. parent.location.href = window.hywa.jumpPage.login;
  12. }
  13. }
  14. layui.config({
  15. base: "../../js/"
  16. }).use(['form', 'layer', 'laytpl','md5'], function () {
  17. form = layui.form;
  18. var layer = layui.layer,
  19. laytpl = layui.laytpl,
  20. $ = layui.jquery,
  21. md5 = layui.md5;
  22. //添加验证规则
  23. form.verify({
  24. newPwd: [
  25. /^[\S]{6,12}$/,
  26. '密码必须6到12位,且不能出现空格'
  27. ],
  28. confirmPwd: function (value) {
  29. if ($("#oldPwd").val() != value) {
  30. return "两次输入密码不一致,请重新输入!";
  31. }
  32. }
  33. })
  34. userInfo.password = null;
  35. form.val("changePwd", userInfo);
  36. //修改密码
  37. form.on("submit(changePwdSub)", function (data) {
  38. var index = layer.msg('提交中,请稍候', {
  39. icon: 16,
  40. time: false,
  41. shade: 0.8
  42. });
  43. dataJson = $.extend({},userInfo,data.field);
  44. dataJson.guid = dataJson.userId;
  45. var time = 'b8d11ee289394be688ef3a4f6968efed';
  46. var result = btoa(dataJson.oldPasswd);
  47. time = time.substring(0, 8);
  48. var pass = md5.calcMD5(time);
  49. pass = pass.substring(0, 5);
  50. dataJson.oldPasswd = pass + result;
  51. delete dataJson.menus;
  52. $.ajax({
  53. type: 'post',
  54. url: 'changePassword',
  55. data: JSON.stringify(dataJson),
  56. contentType: 'application/json',
  57. success: function (res) {
  58. layer.close(index);
  59. if (!(res.code - 0)) {
  60. layer.msg(res.msg, {
  61. icon: 1
  62. });
  63. layer.close(index);
  64. }
  65. $(".pwd").val('');
  66. }
  67. });
  68. return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
  69. })
  70. var getTpl = demo.innerHTML,
  71. view = document.getElementById('view');
  72. laytpl(getTpl).render(userInfo, function (html) {
  73. view && (view.innerHTML = html);
  74. });
  75. })