Commit ebe8c9bd authored by renjintao's avatar renjintao

setUserAvatar

parent ff844428
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<Avatar :src="avatorPath" size="150" /> <Avatar :src="avatorPath" size="150" />
</p> </p>
<p style="text-align:center;padding:10px;"> <p style="text-align:center;padding:10px;">
<Button @click="openModalAvatar">修改头像</Button> <Button @click="openModalAvatar">修改头像</Button>
</p> </p>
</div> </div>
</Card> </Card>
...@@ -92,107 +92,105 @@ ...@@ -92,107 +92,105 @@
</div> </div>
</template> </template>
<script> <script>
import Api from '../user/api' import Api from "../user/api";
import avatar from '@/assets/images/avatar.png' import avatar from "@/assets/images/avatar.png";
import inputFiles from '@/components/page/inputFile.vue' import inputFiles from "@/components/page/inputFile.vue";
export default { export default {
components: { components: {
inputFiles inputFiles
}, },
data() { data() {
return { return {
parms: 'app=user&eid=23&name=avatarUrl', parms: "app=user&eid=23&name=avatarUrl",
cardWidth: '600px', cardWidth: "600px",
userId:0, userId: 0,
pwdModel: { pwdModel: {
id: null, id: null,
oldPwd: '', oldPwd: "",
newPwd: '', newPwd: "",
confirmPwd: '' confirmPwd: ""
}, },
modalAvatar: false, modalAvatar: false,
mid: '', mid: "",
userInfo: { userInfo: {
id: 0, id: 0,
cardNo: '', cardNo: "",
userName: '', userName: "",
gender: 0, gender: 0,
birthday: '', birthday: "",
degreeId: 0, degreeId: 0,
titile: 0, titile: 0,
workLicense: 0, workLicense: 0,
employeeNo: '', employeeNo: "",
jobName: '', jobName: "",
phone: '', phone: "",
email: '', email: "",
departmentId: 0, departmentId: 0,
departmentTitle: '', departmentTitle: "",
status: 0, status: 0,
remark: '', remark: "",
avatarUrl: '' avatarUrl: ""
}, },
imageModel: { imageModel: {
id: null, id: null,
avatar_Url: '', avatar_Url: "",
name: '' name: ""
}, },
imgName: '', imgName: "",
avatorPath: '', avatorPath: "",
oldImgName: '' oldImgName: ""
} };
}, },
created() { created() {
this.userId=this.$store.state.userInfo.userId this.userId = this.$store.state.userInfo.userId;
this.cardWidth = window.innerWidth - 620 + 'px' this.cardWidth = window.innerWidth - 620 + "px";
}, },
async fetch({ store, params }) { async fetch({ store, params }) {
await store.dispatch('loadDictionary') // 加载数据字典 await store.dispatch("loadDictionary"); // 加载数据字典
}, },
methods: { methods: {
pwdOk() { pwdOk() {
if (!this.pwdModel.oldPwd) { if (!this.pwdModel.oldPwd) {
this.$Message.warning('请输入初始密码!') this.$Message.warning("请输入初始密码!");
return return;
} }
if (!this.pwdModel.newPwd) { if (!this.pwdModel.newPwd) {
this.$Message.warning('请输入新密码!') this.$Message.warning("请输入新密码!");
return return;
} }
if (this.pwdModel.newPwd !== this.pwdModel.confirmPwd) { if (this.pwdModel.newPwd !== this.pwdModel.confirmPwd) {
this.$Message.warning('两次密码不一致!') this.$Message.warning("两次密码不一致!");
return return;
} }
if (this.pwdModel.newPwd === this.pwdModel.oldPwd) { if (this.pwdModel.newPwd === this.pwdModel.oldPwd) {
this.$Message.warning('新旧密码相同!') this.$Message.warning("新旧密码相同!");
return return;
} }
this.pwdModel.id = userId this.pwdModel.id = userId;
let params = { let params = {
accountId: this.userInfo.accountId, accountId: this.userInfo.accountId,
userId: this.userInfo.id, userId: this.userInfo.id,
newPassword: this.pwdModel.newPwd, newPassword: this.pwdModel.newPwd,
oldPassword: this.pwdModel.oldPwd oldPassword: this.pwdModel.oldPwd
} };
Api.authChangepassword(params).then((res) => { Api.authChangepassword(params).then(res => {
if (res.success) { if (res.success) {
this.$Message.success('修改成功!') this.$Message.success("修改成功!");
} } else {
else this.$Message.error("修改失败!");
{
this.$Message.error('修改失败!')
} }
}) });
}, },
pwdModelReset() { pwdModelReset() {
this.pwdModel = { this.pwdModel = {
oldPwd: '', oldPwd: "",
newPwd: '', newPwd: "",
confirmPwd: '' confirmPwd: ""
} };
}, },
openModalAvatar() { openModalAvatar() {
this.modalAvatar = true this.modalAvatar = true;
}, },
//单个文件选择后赋值方法 //单个文件选择后赋值方法
// inputChangedFile(val) { // inputChangedFile(val) {
...@@ -203,70 +201,68 @@ export default { ...@@ -203,70 +201,68 @@ export default {
//获取用户基本信息 //获取用户基本信息
initUserInfo() { initUserInfo() {
let parma = { let parma = {
Id: userId Id: this.userId
} };
this.$http.sysUser.getuserinfo(parma).then((res) => { this.$http.sysUser.getuserinfo(parma).then(res => {
if (res.result) { if (res.result) {
this.userInfo = res.result this.userInfo = res.result;
this.imageModel.id = this.userInfo.id this.imageModel.id = this.userInfo.id;
if ( if (
res.result.avatarUrl && res.result.avatarUrl &&
res.result.avatarUrl != '' && res.result.avatarUrl != "" &&
res.result.avatarUrl != null res.result.avatarUrl != null
) { ) {
this.userInfo.avatarUrl = res.result.avatarUrl this.userInfo.avatarUrl = res.result.avatarUrl;
this.avatorPath = fileUrlDown + res.result.avatarUrl this.avatorPath = fileUrlDown + res.result.avatarUrl;
this.oldImgName = fileUrlDown + res.result.avatarUrl this.oldImgName = fileUrlDown + res.result.avatarUrl;
} else { } else {
this.userInfo.avatarUrl = avatar this.userInfo.avatarUrl = avatar;
} }
} else { } else {
this.$Message.error('查询失败!') this.$Message.error("查询失败!");
} }
}) });
}, },
cancelAvatar() { cancelAvatar() {
this.modalAvatar = false this.modalAvatar = false;
this.avatorPath = this.oldImgName this.avatorPath = this.oldImgName;
}, },
upAvatar() { upAvatar() {
if (this.imageModel.avatar_Url != '') { if (this.imageModel.avatar_Url != "") {
this.$http.sysUser.changeavatar(this.imageModel).then((res) => { this.$http.sysUser.changeavatar(this.imageModel).then(res => {
if (res.success) { if (res.success) {
this.$Message.success('修改成功!') this.$Message.success("修改成功!");
this.modalAvatar = false this.modalAvatar = false;
this.$store.commit( this.userInfo.avatarUrl = fileUrlDown + this.imageModel.avatar_Url;
'setUserAvatar', this.$store.commit("admin/user/setUserAvatar", this.userInfo);
fileUrlDown + this.imageModel.avatar_Url
)
} else { } else {
this.$Message.error('修改失败!') this.$Message.error("修改失败!");
} }
}) });
} else { } else {
this.$Message.warning('请选择上传图片!') this.$Message.warning("请选择上传图片!");
} }
}, },
reload() { reload() {
this.isRouterAlive = false //先关闭, this.isRouterAlive = false; //先关闭,
this.$nextTick(function() { this.$nextTick(function() {
this.isRouterAlive = true //再打开 this.isRouterAlive = true; //再打开
}) });
} }
}, },
computed: {}, computed: {},
mounted() { mounted() {
this.initUserInfo() this.initUserInfo();
}, },
watch: { watch: {
imgName(newName, oldName) { imgName(newName, oldName) {
const imgPathsArr = JSON.parse(newName) const imgPathsArr = JSON.parse(newName);
this.userInfo.avatarUrl = imgPathsArr[0].filePath this.userInfo.avatarUrl = imgPathsArr[0].filePath;
this.imageModel.avatar_Url = imgPathsArr[0].filePath this.imageModel.avatar_Url = imgPathsArr[0].filePath;
this.avatorPath = fileUrlDown + imgPathsArr[0].filePath this.avatorPath = fileUrlDown + imgPathsArr[0].filePath;
} }
} }
} };
</script> </script>
<style lang="less" > <style lang="less" >
.ivu-card-body { .ivu-card-body {
...@@ -299,9 +295,9 @@ export default { ...@@ -299,9 +295,9 @@ export default {
.ivu-form-itemNo { .ivu-form-itemNo {
margin-bottom: 4px; margin-bottom: 4px;
} }
.user_info_right{ .user_info_right {
float:left; float: left;
margin-left:20px; margin-left: 20px;
width: calc(78% - 20px); width: calc(78% - 20px);
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment