Account.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <el-form>
  3. <el-form-item label="用户名">
  4. <el-input v-model.trim="user.name" readonly />
  5. </el-form-item>
  6. <el-form-item label="密码">
  7. <el-input v-model.trim="user.password" type="password" placeholder="不修改请留空" />
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" @click="submit">修改</el-button>
  11. </el-form-item>
  12. </el-form>
  13. </template>
  14. <script>
  15. import { updateData } from '@/api/sys/user/user'
  16. export default {
  17. props: {
  18. user: {
  19. type: Object,
  20. default: () => {
  21. return {
  22. password: ''
  23. }
  24. }
  25. }
  26. },
  27. methods: {
  28. async logout() {
  29. await this.$store.dispatch('user/logout')
  30. this.$router.push('/login')
  31. },
  32. async submit() {
  33. // 验证密码是否合法
  34. const validReg = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~@#$%^&+=])(?=\S+$).{8,}$/
  35. if (!this.user.password) {
  36. this.$notify.error({
  37. title: '错误',
  38. message: '密码不能为空',
  39. duration: 2000
  40. })
  41. return
  42. } else if (!validReg.test(this.user.password)) {
  43. this.$notify.error({
  44. title: '错误',
  45. message: '密码必须包含大小写字母、数字和特殊字符且不能小于8位',
  46. duration: 2000
  47. })
  48. return
  49. }
  50. updateData(this.user).then(() => {
  51. this.$notify({
  52. title: '成功',
  53. message: '用户资料保存成功!!',
  54. type: 'success',
  55. duration: 2000
  56. })
  57. this.logout()
  58. })
  59. }
  60. }
  61. }
  62. </script>