华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

  1. <template>
  2. <el-form ref="form" :model="user" :rules="rules" label-width="80px">
  3. <el-form-item label="旧密码" prop="oldPassword">
  4. <el-input v-model="user.oldPassword" placeholder="请输入旧密码" type="password" show-password/>
  5. </el-form-item>
  6. <el-form-item label="新密码" prop="newPassword">
  7. <el-input v-model="user.newPassword" placeholder="请输入新密码" type="password" show-password/>
  8. </el-form-item>
  9. <el-form-item label="确认密码" prop="confirmPassword">
  10. <el-input v-model="user.confirmPassword" placeholder="请确认新密码" type="password" show-password/>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" @click="submit">保存</el-button>
  14. <el-button type="danger" @click="close">关闭</el-button>
  15. </el-form-item>
  16. </el-form>
  17. </template>
  18. <script>
  19. import { updateUserPwd } from "@/api/system/user"
  20. export default {
  21. data() {
  22. const equalToPassword = (rule, value, callback) => {
  23. if (this.user.newPassword !== value) {
  24. callback(new Error("两次输入的密码不一致"))
  25. } else {
  26. callback()
  27. }
  28. }
  29. return {
  30. user: {
  31. oldPassword: undefined,
  32. newPassword: undefined,
  33. confirmPassword: undefined
  34. },
  35. // 表单校验
  36. rules: {
  37. oldPassword: [
  38. { required: true, message: "旧密码不能为空", trigger: "blur" }
  39. ],
  40. newPassword: [
  41. { required: true, message: "新密码不能为空", trigger: "blur" },
  42. { min: 6, max: 20, message: "长度在 6 到 20 个字符", trigger: "blur" },
  43. { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" }
  44. ],
  45. confirmPassword: [
  46. { required: true, message: "确认密码不能为空", trigger: "blur" },
  47. { required: true, validator: equalToPassword, trigger: "blur" }
  48. ]
  49. }
  50. }
  51. },
  52. methods: {
  53. submit() {
  54. this.$refs["form"].validate(valid => {
  55. if (valid) {
  56. updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => {
  57. this.$modal.msgSuccess("修改成功")
  58. this.$store.dispatch('LogOut').then(() => {
  59. location.href = '/'
  60. })
  61. })
  62. }
  63. })
  64. },
  65. close() {
  66. this.$tab.closePage()
  67. }
  68. }
  69. }
  70. </script>