ModifyPsw.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div>
  3. <div class="right-modifyPsw">
  4. <div class="right-modifyPsw-title">
  5. <span style="font-size: 18px;font-weight: bold">修改密码</span>
  6. </div>
  7. <div style="background-color: rgba(233,239,249,1);padding: 10px">
  8. <i class="el-icon-warning" style="color: rgba(0, 117, 203, 1);font-size: 18px"></i>
  9. <span style="font-size: 16px">安全提醒:请妥善保管密码,众测服务平台人员不会以任何理由向您索取密码。</span>
  10. </div>
  11. <el-form ref="modifyForm" :rules="rules" :model="modifyForm" label-width="80px" style="margin-top: 20px; width: 40%;">
  12. <el-form-item label="当前密码" prop="oldPassword">
  13. <el-input v-model="modifyForm.oldPassword" type="password"></el-input>
  14. </el-form-item>
  15. <el-form-item label="新密码" prop="password">
  16. <el-input v-model="modifyForm.password" type="password"></el-input>
  17. </el-form-item>
  18. <el-form-item label="确认密码" prop="password2">
  19. <el-input v-model="modifyForm.password2" type="password"></el-input>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" @click="ModifyPassword">确认修改</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import Http from '@/js/http.js'
  30. import {storageGet,logout} from '@/js/index'
  31. import {notify} from '@/constants/index'
  32. export default {
  33. name: "ModifyPsw",
  34. data(){
  35. return {
  36. user:{},
  37. modifyForm: {
  38. oldPassword:'',
  39. password:'',
  40. password2:'',
  41. },
  42. rules: {
  43. oldPassword: [
  44. {required: true, message: '当前密码不可为空', trigger: 'blur'},
  45. {min: 6, max: 16, message: '密码长度在 6 到 16 个字符', trigger: 'blur'}
  46. ],
  47. password: [
  48. {required: true, message: '新密码不可为空', trigger: 'blur'},
  49. {min: 6, max: 16, message: '密码长度在 6 到 16 个字符', trigger: 'blur'}
  50. ],
  51. password2: [
  52. {required: true, message: '确认密码不可为空', trigger: 'blur'},
  53. {min: 6, max: 16, message: '密码长度在 6 到 16 个字符', trigger: 'blur'}
  54. ]
  55. }
  56. }
  57. },
  58. methods:{
  59. setUserInfo() {
  60. this.user = storageGet('user') && storageGet('user').userVO;
  61. },
  62. ModifyPassword(){
  63. this.$refs['modifyForm'].validate(valid => {
  64. if (valid) {
  65. let params = {
  66. id:this.user.id.toString(),
  67. ...this.modifyForm
  68. }
  69. if(this.modifyForm.password != this.modifyForm.password2){
  70. notify('error', '两次密码不一致,请重新输入!')
  71. return ;
  72. }
  73. Http.put(`/api/password/reset`,params).then(res=>{
  74. // notify('success', '密码修改成功,请重新登录!')
  75. window.alert('密码修改成功,请重新登录');
  76. logout().then((res) => {
  77. window.location.href = process.env.LOGIN_URL;
  78. // this.$router.push('/home')
  79. })
  80. }).catch(err=>{
  81. notify('error', '修改密码失败:' + err.data)
  82. })
  83. }
  84. })
  85. }
  86. },
  87. mounted() {
  88. this.setUserInfo();
  89. }
  90. }
  91. </script>
  92. <style scoped lang="less">
  93. .right-modifyPsw {
  94. padding: 20px;
  95. background: rgba(255, 255, 255, 1);
  96. box-shadow: 0px 1px 6px 0px rgba(8, 6, 6, 0.13);
  97. .right-modifyPsw-title {
  98. padding: 10px;
  99. border-bottom: 1px solid #ccc;
  100. margin-bottom: 20px;
  101. }
  102. }
  103. </style>