ResetPwd.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <el-dialog
  3. class="reset-pwd"
  4. :visible.sync="modalIsShow"
  5. title="修改密码"
  6. top="10vh"
  7. width="448px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="resetRules"
  17. label-position="top"
  18. >
  19. <el-form-item prop="password" label="新密码:">
  20. <el-input
  21. type="password"
  22. v-model="modalForm.password"
  23. placeholder="请输入新密码"
  24. clearable
  25. ></el-input>
  26. </el-form-item>
  27. <el-form-item prop="rePassword" label="再次密码:">
  28. <el-input
  29. type="password"
  30. v-model="modalForm.rePassword"
  31. placeholder="请再次输入新密码"
  32. clearable
  33. ></el-input>
  34. </el-form-item>
  35. </el-form>
  36. <div slot="footer">
  37. <el-button type="primary" :disabled="isSubmit" @click="submit"
  38. >确认</el-button
  39. >
  40. <el-button @click="cancel">取消</el-button>
  41. </div>
  42. </el-dialog>
  43. </template>
  44. <script>
  45. import { resetUserPassword } from "@/api/system-user";
  46. const initModalForm = {
  47. id: "",
  48. password: "",
  49. rePassword: "",
  50. };
  51. export default {
  52. name: "reset-pwd",
  53. data() {
  54. const equalToPswd = (rule, value, callback) => {
  55. if (value !== this.modalForm.password) {
  56. callback(new Error("两次输入的密码不一致"));
  57. } else {
  58. callback();
  59. }
  60. };
  61. const password = [
  62. {
  63. required: true,
  64. pattern: /^[a-zA-Z0-9_]{6,20}$/,
  65. message: "密码只能由数字、字母和下划线组成,长度6-20个字符",
  66. trigger: "change",
  67. },
  68. ];
  69. return {
  70. modalIsShow: false,
  71. isSubmit: false,
  72. nameWaitTime: "resetpwd",
  73. isFetchingCode: false,
  74. modalForm: { ...initModalForm },
  75. resetRules: {
  76. password: [...password],
  77. rePassword: [
  78. ...password,
  79. {
  80. validator: equalToPswd,
  81. trigger: "change",
  82. },
  83. ],
  84. },
  85. };
  86. },
  87. methods: {
  88. visibleChange() {
  89. this.modalForm = { ...initModalForm };
  90. this.modalForm.id = this.$store.state.user.id;
  91. },
  92. cancel() {
  93. this.modalIsShow = false;
  94. },
  95. open() {
  96. this.modalIsShow = true;
  97. },
  98. async submit() {
  99. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  100. if (!valid) return;
  101. if (this.isSubmit) return;
  102. this.isSubmit = true;
  103. let datas = {
  104. id: this.modalForm.id,
  105. password: this.modalForm.password,
  106. };
  107. const data = await resetUserPassword(datas).catch(() => {
  108. this.isSubmit = false;
  109. });
  110. if (!data) return;
  111. this.isSubmit = false;
  112. this.$message.success("修改成功!");
  113. this.cancel();
  114. },
  115. },
  116. };
  117. </script>