From 31f4cb4c98684b3324399b5468d955919fc8de88 Mon Sep 17 00:00:00 2001
From: wangting <wangting@vci-tech.com>
Date: 星期四, 16 一月 2025 10:41:03 +0800
Subject: [PATCH] 调整样式,修改流程模板定义
---
Source/plt-web/plt-web-ui/src/views/system/userInfo/userAvatar.vue | 61 +++++++++++++++++++++---------
1 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/Source/plt-web/plt-web-ui/src/views/system/userInfo/userAvatar.vue b/Source/plt-web/plt-web-ui/src/views/system/userInfo/userAvatar.vue
index 1ee2aea..ce25b08 100644
--- a/Source/plt-web/plt-web-ui/src/views/system/userInfo/userAvatar.vue
+++ b/Source/plt-web/plt-web-ui/src/views/system/userInfo/userAvatar.vue
@@ -61,7 +61,9 @@
<script>
import store from "@/store";
import { VueCropper } from "vue-cropper";
-import { uploadAvatar } from "@/api/system/user";
+import {getUserPhoto, updateUserPhoto} from "@/api/user";
+import {mapGetters} from "vuex";
+import {setStore} from '@/util/store'
export default {
components: { VueCropper },
@@ -74,18 +76,23 @@
visible: false,
// 寮瑰嚭灞傛爣棰�
title: "淇敼澶村儚",
- options: {
- img: this.avatar, //瑁佸壀鍥剧墖鐨勫湴鍧�
+ previews: {},
+ resizeHandler: null
+ };
+ },
+ computed: {
+ ...mapGetters(["userInfo"]),
+ options() {
+ return {
+ img: this.userInfo.avatar, //瑁佸壀鍥剧墖鐨勫湴鍧�
autoCrop: true, // 鏄惁榛樿鐢熸垚鎴浘妗�
autoCropWidth: 200, // 榛樿鐢熸垚鎴浘妗嗗搴�
autoCropHeight: 200, // 榛樿鐢熸垚鎴浘妗嗛珮搴�
fixedBox: true, // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
outputType:"png", // 榛樿鐢熸垚鎴浘涓篜NG鏍煎紡
filename: 'avatar' // 鏂囦欢鍚嶇О
- },
- previews: {},
- resizeHandler: null
- };
+ }
+ }
},
methods: {
// 缂栬緫澶村儚
@@ -95,11 +102,11 @@
// 鎵撳紑寮瑰嚭灞傜粨鏉熸椂鐨勫洖璋�
modalOpened() {
this.visible = true;
- if (!this.resizeHandler) {
- this.resizeHandler = debounce(() => {
- this.refresh()
- }, 100)
- }
+ // if (!this.resizeHandler) {
+ // this.resizeHandler = debounce(() => {
+ // this.refresh()
+ // }, 100)
+ // }
window.addEventListener("resize", this.resizeHandler)
},
// 鍒锋柊缁勪欢
@@ -125,7 +132,7 @@
// 涓婁紶棰勫鐞�
beforeUpload(file) {
if (file.type.indexOf("image/") == -1) {
- this.$modal.msgError("鏂囦欢鏍煎紡閿欒锛岃涓婁紶鍥剧墖绫诲瀷,濡傦細JPG锛孭NG鍚庣紑鐨勬枃浠躲��");
+ this.$message.error("鏂囦欢鏍煎紡閿欒锛岃涓婁紶鍥剧墖绫诲瀷,濡傦細JPG锛孭NG鍚庣紑鐨勬枃浠躲��");
} else {
const reader = new FileReader();
reader.readAsDataURL(file);
@@ -133,18 +140,21 @@
this.options.img = reader.result;
this.options.filename = file.name;
};
+ this.$refs.cropper.refresh();
}
},
// 涓婁紶鍥剧墖
uploadImg() {
this.$refs.cropper.getCropBlob(data => {
+
let formData = new FormData();
- formData.append("avatarfile", data, this.options.filename);
- uploadAvatar(formData).then(response => {
+ formData.append("file", data, this.options.filename);
+ formData.append("username",this.userInfo.userId);
+
+ updateUserPhoto(formData).then(response => {
this.open = false;
- this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
- store.commit('SET_AVATAR', this.options.img);
- this.$modal.msgSuccess("淇敼鎴愬姛");
+ this.$message.success('淇敼鎴愬姛锛�');
+ this.getUserInfo();
this.visible = false;
});
});
@@ -155,9 +165,22 @@
},
// 鍏抽棴绐楀彛
closeDialog() {
- this.options.img = store.getters.avatar
+ this.options.img = this.userInfo.avatar; // 鍏抽棴绐楀彛鏇存柊涓虹紦瀛樹腑鐨勫ご鍍忓湴鍧� 濡備慨鏀规垚鍔熸洿鏂颁负鏈�鏂扮殑 濡備慨鏀瑰悗鏈繚瀛樻洿鏂颁负缂撳瓨涓殑
this.visible = false;
window.removeEventListener("resize", this.resizeHandler)
+ },
+ // 鏇存柊缂撳瓨鍐呭
+ getUserInfo(){
+ getUserPhoto().then(res => {
+ // 灏� Blob 杞崲涓� Base64
+ const reader = new FileReader();
+ reader.onloadend = (result) => {
+ this.userInfo.avatar = reader.result; // 瀛樺偍 Base64 瀛楃涓�
+
+ setStore({ name: 'userInfo', content: this.userInfo });
+ };
+ reader.readAsDataURL(res.data); // 璋冪敤reader鏂规硶
+ });
}
}
};
--
Gitblit v1.9.3