Commit ebe8c9bd authored by renjintao's avatar renjintao

setUserAvatar

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