田源
2024-12-26 3457bf08eae9d9453c88dd62991c3e286eb1df4b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
  <div>
    <basic-container>
      <avue-form
        ref="form"
        v-model="form"
        :option="option"
        @submit="handleSubmit"
        @tab-click="handleTabClick">
        <template slot="avatar" slot-scope="{disabled,size}">
          <div>
            <userAvatar :avatar="form.avatar"/>
          </div>
        </template>
      </avue-form>
    </basic-container>
  </div>
</template>
 
<script>
import option from "@/option/user/info";
import {getUserInfo, updateInfo, updatePassword} from "@/api/system/user";
import func from "../../../util/func";
import {changePassword} from "../../../api/user"
import userAvatar from "./userAvatar";
import {resetRouter} from '../../../router/router'
import {mapGetters} from "vuex";
 
export default {
  components: {userAvatar,},
  data() {
    return {
      index: 0,
      option: option,
      form: {}
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  created() {
    this.handleWitch();
  },
  methods: {
    handleSubmit(form, done) {
      if (this.index === 0) {
        updateInfo(form).then(res => {
          if (res.data.success) {
            this.$message({
              type: "success",
              message: "修改信息成功!"
            });
          } else {
            this.$message({
              type: "error",
              message: res.data.msg
            });
          }
          done();
        }, error => {
          window.console.log(error);
          done();
        })
      } else {
        let userInfo = JSON.parse(localStorage.getItem('saber-userInfo'));
        let params = {
          userName: userInfo.content.userId,
          oldPassword: func.encryptData(form.oldPassword, 'daliantan0v0vcip'),
          password: func.encryptData(form.password, 'daliantan0v0vcip'),
          confirmPassword: func.encryptData(form.confirmPassword, 'daliantan0v0vcip'),
 
        }
        changePassword(params).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.msg);
            this.passwordVisible = false;
            this.$store.dispatch("LogOut").then(() => {
              resetRouter();
              this.$router.push({path: "/login"});
            });
          }
        }).catch(err => {
          console.log(err);
        })
      }
    },
    handleWitch() {
      if (this.index === 0) {
        this.form = {...this.userInfo};
        console.log(this.form);
      }
    },
    handleTabClick(tabs) {
      this.index = func.toInt(tabs.index);
      this.handleWitch();
      this.$refs.form.resetFields();
    }
  }
};
</script>
 
<style>
</style>