From b92ea6fb8b4a75a0d7c561bd045f1a8b1720ddd1 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 02 七月 2025 14:47:15 +0800
Subject: [PATCH] 人员管理-在职员工台账、合同管理联调

---
 src/views/system/user/profile/userAvatar.vue |   96 +++++++++++++++++++++---------------------------
 1 files changed, 42 insertions(+), 54 deletions(-)

diff --git a/src/views/system/user/profile/userAvatar.vue b/src/views/system/user/profile/userAvatar.vue
index b99f58d..ff1c9ef 100644
--- a/src/views/system/user/profile/userAvatar.vue
+++ b/src/views/system/user/profile/userAvatar.vue
@@ -4,18 +4,9 @@
     <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"
-            :autoCrop="options.autoCrop"
-            :autoCropWidth="options.autoCropWidth"
-            :autoCropHeight="options.autoCropHeight"
-            :fixedBox="options.fixedBox"
-            :outputType="options.outputType"
-            @realTime="realTime"
-            v-if="visible"
-          />
+          <vue-cropper ref="cropper" :img="options.img" :info="true" :autoCrop="options.autoCrop"
+            :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">
@@ -26,15 +17,12 @@
       <br />
       <el-row>
         <el-col :lg="2" :md="2">
-          <el-upload
-            action="#"
-            :http-request="requestUpload"
-            :show-file-list="false"
-            :before-upload="beforeUpload"
-          >
+          <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-icon class="el-icon--right">
+                <Upload />
+              </el-icon>
             </el-button>
           </el-upload>
         </el-col>
@@ -59,17 +47,17 @@
 </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 userStore = useUserStore()
+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({
@@ -81,75 +69,75 @@
   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.filename = file.name;
-    };
+      options.img = reader.result
+      options.filename = file.name
+    }
   }
 }
 
 /** 涓婁紶鍥剧墖 */
 function uploadImg() {
   proxy.$refs.cropper.getCropBlob(data => {
-    let formData = new FormData();
-    formData.append("avatarfile", data, options.filename);
+    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 + '/profile/' + 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>
 

--
Gitblit v1.9.3