<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>
|