changePasswordForAdmin.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div id="changePassword" v-loading="isLoging">
  3. <el-dialog
  4. title="修改密码"
  5. width="40%"
  6. top="2rem"
  7. :close-on-click-modal="false"
  8. :visible.sync="showDialog"
  9. :destroy-on-close="true"
  10. @close="close()"
  11. >
  12. <div id="shared" style="margin-right: 20px;">
  13. <el-form ref="passwordForm" :rules="rules" status-icon label-width="80px">
  14. <el-form-item label="新密码" prop="newPassword" >
  15. <el-input v-model="newPassword" autocomplete="off"></el-input>
  16. </el-form-item>
  17. <el-form-item label="确认密码" prop="confirmPassword">
  18. <el-input v-model="confirmPassword" autocomplete="off"></el-input>
  19. </el-form-item>
  20. <el-form-item>
  21. <div style="float: right;">
  22. <el-button type="primary" @click="onSubmit">保存</el-button>
  23. <el-button @click="close">取消</el-button>
  24. </div>
  25. </el-form-item>
  26. </el-form>
  27. </div>
  28. </el-dialog>
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. name: "changePasswordForAdmin",
  34. props: {},
  35. computed: {},
  36. created() {},
  37. data() {
  38. let validatePass1 = (rule, value, callback) => {
  39. if (value === '') {
  40. callback(new Error('请输入新密码'));
  41. } else {
  42. if (this.confirmPassword !== '') {
  43. this.$refs.passwordForm.validateField('confirmPassword');
  44. }
  45. callback();
  46. }
  47. };
  48. let validatePass2 = (rule, value, callback) => {
  49. if (this.confirmPassword === '') {
  50. callback(new Error('请再次输入密码'));
  51. } else if (this.confirmPassword !== this.newPassword) {
  52. callback(new Error('两次输入密码不一致!'));
  53. } else {
  54. callback();
  55. }
  56. };
  57. return {
  58. newPassword: null,
  59. confirmPassword: null,
  60. userId: null,
  61. showDialog: false,
  62. isLoging: false,
  63. listChangeCallback: null,
  64. form: {},
  65. rules: {
  66. newPassword: [{ required: true, validator: validatePass1, trigger: "blur" }, {
  67. pattern: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{8,20}$/,
  68. message: "密码长度在8-20位之间,由字母+数字+特殊字符组成",
  69. },],
  70. confirmPassword: [{ required: true, validator: validatePass2, trigger: "blur" }],
  71. },
  72. };
  73. },
  74. methods: {
  75. openDialog: function (row, callback) {
  76. console.log(row)
  77. this.showDialog = true;
  78. this.listChangeCallback = callback;
  79. if (row != null) {
  80. this.form = row;
  81. }
  82. },
  83. onSubmit: function () {
  84. this.$axios({
  85. method: 'post',
  86. url:"./api/user/changePasswordForAdmin",
  87. params: {
  88. password: this.newPassword,
  89. userId: this.form.id,
  90. }
  91. }).then((res)=> {
  92. if (res.data.code === 0) {
  93. this.$message({
  94. showClose: true,
  95. message: '修改成功',
  96. type: 'success'
  97. });
  98. this.showDialog = false;
  99. }else {
  100. this.$message({
  101. showClose: true,
  102. message: '修改密码失败,是否已登录(接口鉴权关闭无法修改密码)',
  103. type: 'error'
  104. });
  105. }
  106. }).catch((error)=> {
  107. console.error(error)
  108. });
  109. },
  110. close: function () {
  111. this.showDialog = false;
  112. this.newPassword = null;
  113. this.confirmPassword = null;
  114. this.userId=null;
  115. this.adminId=null;
  116. },
  117. },
  118. };
  119. </script>