From 391eec3114a17e68652434c6eae610799d80290e Mon Sep 17 00:00:00 2001
From: ludc <ludc@vci-tech.com>
Date: 星期四, 16 一月 2025 11:13:43 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/plt-web/plt-web-ui/src/views/system/userInfo/userAvatar.vue |   52 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 37 insertions(+), 15 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 37864cc..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: {
     // 缂栬緫澶村儚
@@ -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,19 +140,21 @@
           this.options.img = reader.result;
           this.options.filename = file.name;
         };
+        this.$refs.cropper.refresh();
       }
     },
     // 涓婁紶鍥剧墖
     uploadImg() {
       this.$refs.cropper.getCropBlob(data => {
-        console.log(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;
         });
       });
@@ -156,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