|
@@ -2,7 +2,10 @@
|
|
|
<Header />
|
|
|
<div class="root">
|
|
|
<div class="content">
|
|
|
- <div class="avatar"><el-avatar :size="100" :src="App.user.avatar ? App.user.avatar : ''" /></div>
|
|
|
+ <el-upload class="avatar" :action="apiUrl" :show-file-list="false" :on-success="handleAvatarSuccess"
|
|
|
+ :on-error="handleAvatarFail" :before-upload="beforeAvatarUpload" name="avatar">
|
|
|
+ <el-avatar :src="App.user.avatar" :size="130" />
|
|
|
+ </el-upload>
|
|
|
|
|
|
<el-form :model="form" ref="formRef" label-width="auto" :label-position="'right'" style>
|
|
|
<el-form-item label="用户名" prop="username">
|
|
@@ -40,6 +43,7 @@ import { useRouter } from 'vue-router';
|
|
|
import { ServerAPI } from '../../../app/lib/ServerAPI';
|
|
|
|
|
|
let router = useRouter();
|
|
|
+const apiUrl = import.meta.env.VITE_API_URL + `/User/UploadAvatar/${App.user.uuid}/${App.user.session}`;
|
|
|
|
|
|
if (!App.hasUser()) {
|
|
|
ElMessage.error('请登录!')
|
|
@@ -62,6 +66,29 @@ let BindWXWork = function () {
|
|
|
window.location.href = res.data.url
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+const beforeAvatarUpload = (rawFile) => {
|
|
|
+ if (rawFile.type !== 'image/jpeg' && rawFile.type !== 'image/png') {
|
|
|
+ ElMessage.error('请上传jpg或png格式的图片!');
|
|
|
+ return false
|
|
|
+ } else if (rawFile.size / 1024 / 1024 > 3) {
|
|
|
+ ElMessage.error('请上传大小不超过3MBd的头像!');
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+const handleAvatarSuccess = (res) => {
|
|
|
+ if(!res || res.code != 0)
|
|
|
+ return ElMessage.error(`头像上传失败!${res.msg || ''}`);
|
|
|
+ ElMessage.success('头像上传成功!');
|
|
|
+ App.refershUser(res.data);
|
|
|
+ router.go(0);
|
|
|
+}
|
|
|
+
|
|
|
+const handleAvatarFail = () => {
|
|
|
+ ElMessage.error('头像上传失败!请稍后再试');
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
@@ -70,7 +97,6 @@ let BindWXWork = function () {
|
|
|
}
|
|
|
|
|
|
.avatar {
|
|
|
- margin-top: -20px;
|
|
|
margin-bottom: 20px;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|