From ab4b75fe30f9a3cf08e3ced667c3ec8c711ca939 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 06 九月 2021 09:59:28 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev
---
ruoyi-ui/src/views/system/user/profile/userAvatar.vue | 61 +++++++++++++++++++++++++-----
1 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/ruoyi-ui/src/views/system/user/profile/userAvatar.vue b/ruoyi-ui/src/views/system/user/profile/userAvatar.vue
index 9bb5d4a..3d1b9ef 100644
--- a/ruoyi-ui/src/views/system/user/profile/userAvatar.vue
+++ b/ruoyi-ui/src/views/system/user/profile/userAvatar.vue
@@ -1,7 +1,7 @@
<template>
<div>
- <img v-bind:src="options.img" @click="editCropper()" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" />
- <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
+ <div class="user-info-head" @click="editCropper()"><img v-bind:src="options.img" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" /></div>
+ <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @opened="modalOpened" @close="closeDialog()">
<el-row>
<el-col :xs="24" :md="12" :style="{height: '350px'}">
<vue-cropper
@@ -13,6 +13,7 @@
:autoCropHeight="options.autoCropHeight"
:fixedBox="options.fixedBox"
@realTime="realTime"
+ v-if="visible"
/>
</el-col>
<el-col :xs="24" :md="12" :style="{height: '350px'}">
@@ -26,7 +27,7 @@
<el-col :lg="2" :md="2">
<el-upload action="#" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUpload">
<el-button size="small">
- 涓婁紶
+ 閫夋嫨
<i class="el-icon-upload el-icon--right"></i>
</el-button>
</el-upload>
@@ -67,6 +68,8 @@
return {
// 鏄惁鏄剧ず寮瑰嚭灞�
open: false,
+ // 鏄惁鏄剧ずcropper
+ visible: false,
// 寮瑰嚭灞傛爣棰�
title: "淇敼澶村儚",
options: {
@@ -74,7 +77,8 @@
autoCrop: true, // 鏄惁榛樿鐢熸垚鎴浘妗�
autoCropWidth: 200, // 榛樿鐢熸垚鎴浘妗嗗搴�
autoCropHeight: 200, // 榛樿鐢熸垚鎴浘妗嗛珮搴�
- fixedBox: true // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
+ fixedBox: true, // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
+ filename: ''
},
previews: {}
};
@@ -83,6 +87,10 @@
// 缂栬緫澶村儚
editCropper() {
this.open = true;
+ },
+ // 鎵撳紑寮瑰嚭灞傜粨鏉熸椂鐨勫洖璋�
+ modalOpened() {
+ this.visible = true;
},
// 瑕嗙洊榛樿鐨勪笂浼犺涓�
requestUpload() {
@@ -109,6 +117,7 @@
reader.readAsDataURL(file);
reader.onload = () => {
this.options.img = reader.result;
+ this.options.filename = file.name;
};
}
},
@@ -116,21 +125,51 @@
uploadImg() {
this.$refs.cropper.getCropBlob(data => {
let formData = new FormData();
- formData.append("avatarfile", data);
+ console.log(this.options.filename)
+ formData.append("avatarfile", data, this.options.filename);
uploadAvatar(formData).then(response => {
- if (response.code === 200) {
- this.open = false;
- this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
- this.msgSuccess("淇敼鎴愬姛");
- }
- this.$refs.cropper.clearCrop();
+ this.open = false;
+ this.options.img = response.data.imgUrl;
+ store.commit('SET_AVATAR', this.options.img);
+ this.msgSuccess("淇敼鎴愬姛");
+ this.visible = false;
});
});
},
// 瀹炴椂棰勮
realTime(data) {
this.previews = data;
+ },
+ // 鍏抽棴绐楀彛
+ closeDialog() {
+ this.options.img = store.getters.avatar
+ this.visible = false;
}
}
};
</script>
+<style scoped lang="scss">
+.user-info-head {
+ position: relative;
+ display: inline-block;
+ height: 120px;
+}
+
+.user-info-head:hover:after {
+ content: '+';
+ position: absolute;
+ left: 0;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ color: #eee;
+ background: rgba(0, 0, 0, 0.5);
+ font-size: 24px;
+ font-style: normal;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ cursor: pointer;
+ line-height: 110px;
+ border-radius: 50%;
+}
+</style>
--
Gitblit v1.9.3