ResetPwd.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. :show-close="false"
  12. @open="visibleChange"
  13. >
  14. <el-form
  15. ref="modalFormComp"
  16. :model="modalForm"
  17. :rules="resetRules"
  18. label-width="90px"
  19. >
  20. <el-form-item prop="password" label="新密码:">
  21. <el-input
  22. type="password"
  23. v-model="modalForm.password"
  24. placeholder="请输入新密码"
  25. clearable
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item prop="rePassword" label="再次密码:">
  29. <el-input
  30. type="password"
  31. v-model="modalForm.rePassword"
  32. placeholder="请再次输入新密码"
  33. clearable
  34. ></el-input>
  35. </el-form-item>
  36. </el-form>
  37. <div slot="footer">
  38. <el-button type="primary" :disabled="isSubmit" @click="submit"
  39. >确认</el-button
  40. >
  41. <el-button @click="cancel">取消</el-button>
  42. </div>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. import { resetPwd } from "../api";
  47. import { password } from "@/plugins/formRules";
  48. const initModalForm = {
  49. password: "",
  50. rePassword: ""
  51. };
  52. export default {
  53. name: "reset-pwd",
  54. data() {
  55. const equalToPswd = (rule, value, callback) => {
  56. if (this.modalForm.rePassword !== this.modalForm.password) {
  57. callback(new Error("两次输入的密码不一致"));
  58. } else {
  59. callback();
  60. }
  61. };
  62. return {
  63. modalIsShow: false,
  64. isSubmit: false,
  65. modalForm: { ...initModalForm },
  66. resetRules: {
  67. password: [...password],
  68. rePassword: [
  69. ...password,
  70. {
  71. validator: equalToPswd,
  72. trigger: "change"
  73. }
  74. ]
  75. }
  76. };
  77. },
  78. methods: {
  79. initData() {
  80. this.modalForm = { ...initModalForm };
  81. },
  82. visibleChange() {
  83. this.initData();
  84. },
  85. cancel() {
  86. this.modalIsShow = false;
  87. },
  88. open() {
  89. this.modalIsShow = true;
  90. },
  91. async submit() {
  92. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  93. if (!valid) return;
  94. if (this.isSubmit) return;
  95. this.isSubmit = true;
  96. const data = await resetPwd(this.modalForm.password).catch(() => {
  97. this.isSubmit = false;
  98. });
  99. if (!data) return;
  100. this.isSubmit = false;
  101. this.$message.success("修改成功!");
  102. this.$emit("modified", data);
  103. this.modalIsShow = false;
  104. }
  105. }
  106. };
  107. </script>