change-password.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. (function() {
  2. Vue.component('change-password', {
  3. template: '<div id="password" class="pl30 hidden">\
  4. <div class="pb10 c-border-b c-f20">修改密码\</div>\
  5. <form id="passwordForm" class="" onsubmit="return false">\
  6. <div class="w3-row mt25 form-group">\
  7. <div class="w3-col c-f16 m5 c-t-right c-909090" style="width:80px;">旧密码</div>\
  8. <div class="w3-rest pl15">\
  9. <input id="oldpassword" type="password" class="form-control" style="width:310px;" name="oldpassword" autocomplete="off" maxlength="16" minlength="8" v-model="oldPassword">\
  10. </div>\
  11. </div>\
  12. <div class="w3-row mt25 form-group">\
  13. <div class="w3-col c-f16 m5 c-t-right c-909090" style="width:80px;">新密码</div>\
  14. <div class="w3-rest pl15">\
  15. <input id="newpassword" type="password" class="form-control" style="width:310px;" name="newpassword" autocomplete="off" maxlength="16" minlength="8" v-model="newPassword">\
  16. <p class="remark">8-16位,不允许空格</p>\
  17. </div>\
  18. </div>\
  19. <div class="w3-row mt25 form-group">\
  20. <div class="w3-col c-f16 m5 c-t-right c-909090" style="width:80px;">确认密码</div>\
  21. <div class="w3-rest pl15">\
  22. <input id="confirm_password" type="password" class="form-control" style="width:310px;" name="confirm_password" autocomplete="off" maxlength="16" minlength="8" v-model="confirmPassword">\
  23. </div>\
  24. </div>\
  25. <div class="c-t-center mt50">\
  26. <button type="submit" class="btn btn-theme c-f16" style="width:144px;height: 50px;" @click="changePassword()">确 定</button>\
  27. <button type="button" class="btn btn-default c-f16 ml20" style="width:144px;height: 50px;" @click="gotosetting()">取 消</button>\
  28. </div>\
  29. </form>\
  30. </div>',
  31. props: [],
  32. data: function() {
  33. return {
  34. oldPassword:"",
  35. newPassword:"",
  36. confirmPassword:"",
  37. }
  38. },
  39. mounted: function() {
  40. },
  41. methods: {
  42. gotosetting: function() {
  43. $("#password").addClass("hidden")
  44. $("#security").removeClass("hidden")
  45. },
  46. changePassword:function(){
  47. var vm = this
  48. var flag = $("#passwordForm").valid();
  49. if(!flag) {
  50. //没有通过验证
  51. return;
  52. }
  53. var oauthInfo = JSON.parse(sessionStorage.getItem("oauthInfo"));
  54. mineAPI.checkOldPass({
  55. password:this.oldPassword
  56. }).then(function(res){
  57. mineAPI.passwordReset({
  58. userId: oauthInfo.id,
  59. password: vm.confirmPassword
  60. }).then(function(res) {
  61. if(res) {
  62. toastr.success("密码修改成功,请重新登录系统");
  63. vm.existUser();
  64. } else {
  65. toastr.error("密码修改失败");
  66. }
  67. }).catch(function(err){
  68. toastr.error("密码修改失败");
  69. })
  70. }).catch(function(err){
  71. toastr.error("原密码错误!");
  72. })
  73. },
  74. existUser: function() {
  75. sessionStorage.removeItem("oauthInfo");
  76. sessionStorage.removeItem("userAgent");
  77. window.location.href="../../../page/login/html/login.html"
  78. }
  79. },
  80. watch: {
  81. oldPassword: function(newVal, oldVal) {
  82. var val = newVal.toString();
  83. var reg = /\s+/g; //去除空格
  84. if(reg.test(val)) {
  85. this.oldPassword = oldVal;
  86. }
  87. },
  88. newPassword: function(newVal, oldVal) {
  89. var val = newVal.toString();
  90. var reg = /\s+/g; //去除空格
  91. if(reg.test(val)) {
  92. this.newPassword = oldVal;
  93. }
  94. },
  95. confirmPassword: function(newVal, oldVal) {
  96. var val = newVal.toString();
  97. var reg = /\s+/g; //去除空格
  98. if(reg.test(val)) {
  99. this.confirmPassword = oldVal;
  100. }
  101. }
  102. }
  103. })
  104. })()