From 10d4c82e729694bd49a29f589d607690dc4b71f8 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 26 五月 2025 16:42:49 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 src/views/system/user/profile/userAvatar.vue |  197 +++++++++++++++++++++++++++----------------------
 1 files changed, 108 insertions(+), 89 deletions(-)

diff --git a/src/views/system/user/profile/userAvatar.vue b/src/views/system/user/profile/userAvatar.vue
index 8e9982a..ae36e39 100644
--- a/src/views/system/user/profile/userAvatar.vue
+++ b/src/views/system/user/profile/userAvatar.vue
@@ -1,9 +1,10 @@
 <template>
-  <div class="user-info-head" @click="editCropper()"><img :src="options.img" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" /></div>
-  <el-dialog :title="title" v-model="open" width="800px" append-to-body @opened="modalOpened"  @close="closeDialog">
-    <el-row>
-      <el-col :xs="24" :md="12" :style="{height: '350px'}">
-        <vue-cropper
+  <div class="user-info-head" @click="editCropper()">
+    <img :src="options.img" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" />
+    <el-dialog :title="title" v-model="open" width="800px" append-to-body @opened="modalOpened" @close="closeDialog">
+      <el-row>
+        <el-col :xs="24" :md="12" :style="{ height: '350px' }">
+          <vue-cropper
             ref="cropper"
             :img="options.img"
             :info="true"
@@ -11,127 +12,145 @@
             :autoCropWidth="options.autoCropWidth"
             :autoCropHeight="options.autoCropHeight"
             :fixedBox="options.fixedBox"
+            :outputType="options.outputType"
             @realTime="realTime"
             v-if="visible"
-        />
-      </el-col>
-      <el-col :xs="24" :md="12" :style="{height: '350px'}">
-        <div class="avatar-upload-preview">
-          <img :src="options.previews.url" :style="options.previews.img"/>
-        </div>
-      </el-col>
-    </el-row>
-    <br/>
-    <el-row>
-      <el-col :lg="2" :md="2">
-        <el-upload action="#" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUpload">
-          <el-button>
-            閫夋嫨
-            <el-icon class="el-icon--right"><Upload /></el-icon>
-          </el-button>
-        </el-upload>
-      </el-col>
-      <el-col :lg="{span: 1, offset: 2}" :md="2">
-        <el-button icon="Plus" @click="changeScale(1)"></el-button>
-      </el-col>
-      <el-col :lg="{span: 1, offset: 1}" :md="2">
-        <el-button icon="Minus" @click="changeScale(-1)"></el-button>
-      </el-col>
-      <el-col :lg="{span: 1, offset: 1}" :md="2">
-        <el-button icon="RefreshLeft" @click="rotateLeft()"></el-button>
-      </el-col>
-      <el-col :lg="{span: 1, offset: 1}" :md="2">
-        <el-button icon="RefreshRight" @click="rotateRight()"></el-button>
-      </el-col>
-      <el-col :lg="{span: 2, offset: 6}" :md="2">
-        <el-button type="primary" @click="uploadImg()">鎻� 浜�</el-button>
-      </el-col>
-    </el-row>
-  </el-dialog>
+          />
+        </el-col>
+        <el-col :xs="24" :md="12" :style="{ height: '350px' }">
+          <div class="avatar-upload-preview">
+            <img :src="options.previews.url" :style="options.previews.img" />
+          </div>
+        </el-col>
+      </el-row>
+      <br />
+      <el-row>
+        <el-col :lg="2" :md="2">
+          <el-upload
+            action="#"
+            :http-request="requestUpload"
+            :show-file-list="false"
+            :before-upload="beforeUpload"
+          >
+            <el-button>
+              閫夋嫨
+              <el-icon class="el-icon--right"><Upload /></el-icon>
+            </el-button>
+          </el-upload>
+        </el-col>
+        <el-col :lg="{ span: 1, offset: 2 }" :md="2">
+          <el-button icon="Plus" @click="changeScale(1)"></el-button>
+        </el-col>
+        <el-col :lg="{ span: 1, offset: 1 }" :md="2">
+          <el-button icon="Minus" @click="changeScale(-1)"></el-button>
+        </el-col>
+        <el-col :lg="{ span: 1, offset: 1 }" :md="2">
+          <el-button icon="RefreshLeft" @click="rotateLeft()"></el-button>
+        </el-col>
+        <el-col :lg="{ span: 1, offset: 1 }" :md="2">
+          <el-button icon="RefreshRight" @click="rotateRight()"></el-button>
+        </el-col>
+        <el-col :lg="{ span: 2, offset: 6 }" :md="2">
+          <el-button type="primary" @click="uploadImg()">鎻� 浜�</el-button>
+        </el-col>
+      </el-row>
+    </el-dialog>
+  </div>
 </template>
 
 <script setup>
-import "vue-cropper/dist/index.css";
-import { VueCropper } from "vue-cropper";
-import { uploadAvatar } from "@/api/system/user";
-import useUserStore from '@/store/modules/user'
+import "vue-cropper/dist/index.css"
+import { VueCropper } from "vue-cropper"
+import { uploadAvatar } from "@/api/system/user"
+import useUserStore from "@/store/modules/user"
 
 const userStore = useUserStore()
-const { proxy } = getCurrentInstance();
+const { proxy } = getCurrentInstance()
 
-const open = ref(false);
-const visible = ref(false);
-const title = ref("淇敼澶村儚");
+const open = ref(false)
+const visible = ref(false)
+const title = ref("淇敼澶村儚")
 
 //鍥剧墖瑁佸壀鏁版嵁
 const options = reactive({
-  img: userStore.avatar, // 瑁佸壀鍥剧墖鐨勫湴鍧�
-  autoCrop: true, // 鏄惁榛樿鐢熸垚鎴浘妗�
-  autoCropWidth: 200, // 榛樿鐢熸垚鎴浘妗嗗搴�
-  autoCropHeight: 200, // 榛樿鐢熸垚鎴浘妗嗛珮搴�
-  fixedBox: true, // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
-  previews: {} //棰勮鏁版嵁
-});
+  img: userStore.avatar,     // 瑁佸壀鍥剧墖鐨勫湴鍧�
+  autoCrop: true,            // 鏄惁榛樿鐢熸垚鎴浘妗�
+  autoCropWidth: 200,        // 榛樿鐢熸垚鎴浘妗嗗搴�
+  autoCropHeight: 200,       // 榛樿鐢熸垚鎴浘妗嗛珮搴�
+  fixedBox: true,            // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
+  outputType: "png",         // 榛樿鐢熸垚鎴浘涓篜NG鏍煎紡
+  filename: 'avatar',        // 鏂囦欢鍚嶇О
+  previews: {}               //棰勮鏁版嵁
+})
 
 /** 缂栬緫澶村儚 */
 function editCropper() {
-  open.value = true;
-};
+  open.value = true
+}
+
 /** 鎵撳紑寮瑰嚭灞傜粨鏉熸椂鐨勫洖璋� */
 function modalOpened() {
-  visible.value = true;
-};
+  visible.value = true
+}
+
 /** 瑕嗙洊榛樿涓婁紶琛屼负 */
-function requestUpload() {
-};
+function requestUpload() {}
+
 /** 鍚戝乏鏃嬭浆 */
 function rotateLeft() {
-  proxy.$refs.cropper.rotateLeft();
-};
+  proxy.$refs.cropper.rotateLeft()
+}
+
 /** 鍚戝彸鏃嬭浆 */
 function rotateRight() {
-  proxy.$refs.cropper.rotateRight();
-};
+  proxy.$refs.cropper.rotateRight()
+}
+
 /** 鍥剧墖缂╂斁 */
 function changeScale(num) {
-  num = num || 1;
-  proxy.$refs.cropper.changeScale(num);
-};
+  num = num || 1
+  proxy.$refs.cropper.changeScale(num)
+}
+
 /** 涓婁紶棰勫鐞� */
 function beforeUpload(file) {
   if (file.type.indexOf("image/") == -1) {
-    proxy.$modal.msgError("鏂囦欢鏍煎紡閿欒锛岃涓婁紶鍥剧墖绫诲瀷,濡傦細JPG锛孭NG鍚庣紑鐨勬枃浠躲��");
+    proxy.$modal.msgError("鏂囦欢鏍煎紡閿欒锛岃涓婁紶鍥剧墖绫诲瀷,濡傦細JPG锛孭NG鍚庣紑鐨勬枃浠躲��")
   } else {
-    const reader = new FileReader();
-    reader.readAsDataURL(file);
+    const reader = new FileReader()
+    reader.readAsDataURL(file)
     reader.onload = () => {
-      options.img = reader.result;
-    };
+      options.img = reader.result
+      options.filename = file.name
+    }
   }
-};
+}
+
 /** 涓婁紶鍥剧墖 */
 function uploadImg() {
   proxy.$refs.cropper.getCropBlob(data => {
-    let formData = new FormData();
-    formData.append("avatarfile", data);
+    let formData = new FormData()
+    formData.append("avatarfile", data, options.filename)
     uploadAvatar(formData).then(response => {
-      open.value = false;
-      options.img = import.meta.env.VITE_APP_BASE_API + response.imgUrl;
-      userStore.avatar = options.img;
-      proxy.$modal.msgSuccess("淇敼鎴愬姛");
-      visible.value = false;
-    });
-  });
-};
+      open.value = false
+      options.img = import.meta.env.VITE_APP_BASE_API + response.imgUrl
+      userStore.avatar = options.img
+      proxy.$modal.msgSuccess("淇敼鎴愬姛")
+      visible.value = false
+    })
+  })
+}
+
 /** 瀹炴椂棰勮 */
 function realTime(data) {
-  options.previews = data;
-};
+  options.previews = data
+}
+
 /** 鍏抽棴绐楀彛 */
 function closeDialog() {
-  options.img = userStore.avatar;
-  options.visible = false;
-};
+  options.img = userStore.avatar
+  options.visible = false
+}
 </script>
 
 <style lang='scss' scoped>

--
Gitblit v1.9.3