Explorar el Código

feat: 驿站人员头像

zhangying hace 11 meses
padre
commit
a85dc1b418

+ 26 - 4
vue/src/layout/logo/index.vue

@@ -1,13 +1,16 @@
 <template>
   <div class="logo">
-    <img src="~@/assets/images/admin.png" alt="" />
-    <h2 v-show="!collapsed" class="title">{{userInfo.name}}</h2>
+    <img v-if="!avtImageUrl" src="~@/assets/images/admin.png" alt=""/>
+    <img v-else :src="avtImageUrl" alt="" style="border-radius: 50%"/>
+    <h2 v-show="!collapsed" class="title">{{ userInfo.name }}</h2>
   </div>
 </template>
 
 <script setup lang="ts">
-import {reactive, ref, toRef} from 'vue';
+import {onMounted, reactive, ref, toRef} from 'vue';
 import { useUserStore } from '@/store/modules/user';
+import {getFileBase64, getList} from "@/api/system/file";
+import {base64ToBlob} from "@/utils/imageUtils";
 
   defineProps({
     collapsed: {
@@ -16,10 +19,28 @@ import { useUserStore } from '@/store/modules/user';
   });
 
 const userStore = useUserStore();
-
 const userInfo=reactive(userStore.getUserInfo);
 
+const avtImageUrl = ref<any>("")
+
+function getAvtImag(fileRefID) {
+  getList({fileRefID}).then((res) => {
+    if (!res) {
+      avtImageUrl.value = false;
+    } else {
+      // 获取图片
+      getFileBase64({fileId: res[0].fileId}).then(data => {
+        if (data) {
+          avtImageUrl.value = URL.createObjectURL(base64ToBlob("data:image/png;base64," + data));
+        }
+      })
+    }
+  })
+}
 
+onMounted(() => {
+  getAvtImag(userInfo.userID);
+})
 </script>
 
 <style lang="less" scoped>
@@ -31,6 +52,7 @@ const userInfo=reactive(userStore.getUserInfo);
     line-height: 84px;
 
     img {
+      width: 32px;
       height: 32px;
       margin-right: 8px;
     }

+ 14 - 0
vue/src/utils/imageUtils.ts

@@ -0,0 +1,14 @@
+export function base64ToBlob(data: string) {
+  const arr = data.split(',');
+  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+  // @ts-ignore
+  const mime = arr[0].match(/:(.*?);/)[1];
+  const bstr = atob(arr[1]);
+  let n = bstr.length;
+  const u8arr = new Uint8Array(n);
+
+  while (n--) {
+    u8arr[n] = bstr.charCodeAt(n);
+  }
+  return new Blob([u8arr], {type: mime});
+}

+ 1 - 1
vue/src/views/baseSettings/siteUser/detail.vue

@@ -28,7 +28,7 @@
       <a-descriptions-item label="住址">{{ siteUserInfo.address }}</a-descriptions-item>
     </a-descriptions>
     <a-divider orientation="left">相片</a-divider>
-    <b-upload-file :fileRefId="siteUserInfo.siteUserID" :readonly="true" :multiple="true"
+    <b-upload-file :fileRefId="siteUserInfo.userID" :readonly="true" :multiple="false" :restrict="1"
                    :setFileList="setFileList" :accept="'.pdf,.png,.jpg'"></b-upload-file>
   </div>
 </template>

+ 1 - 1
vue/src/views/baseSettings/siteUser/edit.vue

@@ -149,7 +149,7 @@
         </a-col>
       </a-row>
       <a-divider orientation="left">相片</a-divider>
-      <b-upload-file :fileRefId="dataModel.siteUserID" :readonly="false" :multiple="true"
+      <b-upload-file :fileRefId="dataModel.userID" :readonly="false" :multiple="false" :restrict="1"
                      :setFileList="setFileList" :accept="'.pdf,.png,.jpg'" :disabled="opCategory==3"></b-upload-file>
       <a-form-item class="buttom-btns">
         <a-button @click="onClose">取消</a-button>