From e181f04c642204e79749af93fa921875ff6c21ba Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期二, 20 五月 2025 10:46:35 +0800
Subject: [PATCH] refactor(qms): 重构趋势图展示逻辑

---
 src/components/ImageUpload/index.vue |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/components/ImageUpload/index.vue b/src/components/ImageUpload/index.vue
index 6b7a39b..0778121 100644
--- a/src/components/ImageUpload/index.vue
+++ b/src/components/ImageUpload/index.vue
@@ -44,6 +44,7 @@
 import { OssVO } from '@/api/system/oss/types';
 import { propTypes } from '@/utils/propTypes';
 import { globalHeaders } from '@/utils/request';
+import { compressAccurately } from 'image-conversion';
 
 const props = defineProps({
   modelValue: {
@@ -60,7 +61,14 @@
   isShowTip: {
     type: Boolean,
     default: true
-  }
+  },
+  // 鏄惁鏀寔鍘嬬缉锛岄粯璁ゅ惁
+  compressSupport: {
+    type: Boolean,
+    default: false
+  },
+  // 鍘嬬缉鐩爣澶у皬锛屽崟浣岾B銆傞粯璁�300KB浠ヤ笂鏂囦欢鎵嶅帇缂╋紝骞跺帇缂╄嚦300KB浠ュ唴
+  compressTargetSize: propTypes.number.def(300)
 });
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@@ -81,14 +89,14 @@
 
 watch(
   () => props.modelValue,
-  async (val) => {
+  async (val: string) => {
     if (val) {
       // 棣栧厛灏嗗�艰浆涓烘暟缁�
       let list: OssVO[] = [];
       if (Array.isArray(val)) {
         list = val as OssVO[];
       } else {
-        const res = await listByIds(val as string);
+        const res = await listByIds(val);
         list = res.data;
       }
       // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁�
@@ -131,6 +139,10 @@
     proxy?.$modal.msgError(`鏂囦欢鏍煎紡涓嶆纭�, 璇蜂笂浼�${props.fileType.join('/')}鍥剧墖鏍煎紡鏂囦欢!`);
     return false;
   }
+  if (file.name.includes(',')) {
+    proxy?.$modal.msgError('鏂囦欢鍚嶄笉姝g‘锛屼笉鑳藉寘鍚嫳鏂囬�楀彿!');
+    return false;
+  }
   if (props.fileSize) {
     const isLt = file.size / 1024 / 1024 < props.fileSize;
     if (!isLt) {
@@ -138,8 +150,16 @@
       return false;
     }
   }
-  proxy?.$modal.loading('姝e湪涓婁紶鍥剧墖锛岃绋嶅��...');
-  number.value++;
+
+  //鍘嬬缉鍥剧墖锛屽紑鍚帇缂╁苟涓斿ぇ浜庢寚瀹氱殑鍘嬬缉澶у皬鏃舵墠鍘嬬缉
+  if (props.compressSupport && file.size / 1024 > props.compressTargetSize) {
+    proxy?.$modal.loading('姝e湪涓婁紶鍥剧墖锛岃绋嶅��...');
+    number.value++;
+    return compressAccurately(file, props.compressTargetSize);
+  } else {
+    proxy?.$modal.loading('姝e湪涓婁紶鍥剧墖锛岃绋嶅��...');
+    number.value++;
+  }
 };
 
 // 鏂囦欢涓暟瓒呭嚭

--
Gitblit v1.9.3