From e423d8afcf5b9666e166565d0509b621ebab17e7 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 13 一月 2025 14:11:00 +0800
Subject: [PATCH] !172 合并 warmflow 功能分支 * update 优化 流程定义页面 点击复制之后跳转到未发布列表 * update 优化 流程定义页面 增加加载loading层 * fix: v-model处理有延迟 需要手动处理 * update 调整流程定义查询 * Merge remote-tracking branch 'origin/dev' into warm-flw-future * update 调整可驳回的节点 * update: 调整文案 * update: 激活/挂起改为switch操作 * update 优化 代码删除无用输出 * update 统一抄送人使用昵称展示 * update 调整分类接口 * update 统一业务id参数 * update 删除默认顶节点 * !168 优化流程分类 * update 恢复误删除代码 * update 优化流程分类 * update 修复 路由跳转未改全 * [update] * fix 修复一些问题 * update 重构流程分类表 * update 流程定义增加表单路径与编辑功能 修复一些其他bug * fix 修复 一些问题 * update 变量统一命名 * add 增加示例 * Merge branch 'warm-flw-future' of https://gitee.com/JavaLionLi/plus-ui… * update 调整办理人 * Merge remote-tracking branch 'origin/dev' into warm-flw-future * add 增加示例 * update 调整审批记录 添加流程导出 * remove 删除无用代码 * remove 删除无用代码 * [update] * [fix] * 流程干预删除委托 * 增加附件 * 附件修改 * 申请人查询修改 * 1.修改查询条件 * !167 fix 修复 import路径修改不全问题 * fix 修复 import路径修改不全问题 * !166 update 清除 ProcessPreview 引用 * update 清除 ProcessPreview 引用 * remove 删除 bpmn.js 设计器 * remove 删除 bpmn.js 设计器 * remove 删除 bpmn.js 设计器 * remove 删除 bpmn.js 设计器 * fix 修复 前端路径修改不全问题 * update 优化接口请求路径 * add 添加作废 * add 添加流程干预 * update 调整加签,减签 * update 调整加签,减签 * add 增加流程查看 * update 调整委托,转办 * update 调整流程变量显示 * update 调整办理人修改 * update 调整流程实例状态页面 * update 调整已办页面 * add 添加流程撤销 * update 调整任务,流程实例 ,流程定义页面 * Merge branch 'dev' into warm-flw-future * update 调整流程定义页面 * add 添加流程变量查看 * update 调整设计器路由名称 * update 调整办理人 * update 调整设计器uri * update 调整设计器请求uri 调整待办状态 * update 调整办理 驳回 终止等状态 * add 添加模型新增 * add 添加warm-ui设计器,删除无用代码 * Merge remote-tracking branch 'origin/dev' into warm-flw-future * add 添加流程设计 * update 调整驳回 * update 调整视图类型错误 * Merge branch 'warm-flw-future' of https://gitee.com/JavaLionLi/plus-ui… * 添加已办,未办 * Merge remote-tracking branch 'origin/dev' into warm-flw-future * update 调整流程实例,待办查询 * add 添加代办人,调整提交按钮校验 * update 调整流程定义查询 * add添加流程定义激活 挂起 * add 添加流程文件部署 调整流程发布 * update 优化 时间搜索组件统一 * Merge remote-tracking branch 'origin/dev' into warm-flw-future * fix 修复 用户管理编辑安全权限错误问题 * Merge remote-tracking branch 'origin/dev' into warm-flw-future * update 优化 类型报错问题 * update 优化 切换租户后刷新首页 * update 优化 实现表格行选中切换 * update 优化 使用 vueuse 重构 websocket 实现 * update 优化 使用 vueuse 重构 websocket 实现 * fix 修复 登出后重新登录 sse推送报错问题 * reset 回滚 代码修改 采用其他方案 * fix 修复 登出后重新登录 sse推送报错问题 * update 优化 删除无用代码 * update element-plus 2.7.5 => 2.7.8 * reset 回滚 错误修复 * update 优化 代码生成器编辑页禁用缓存 防止同步后页面不更新问题 * fix 修复 代码生成同步点击取消报错问题 * 初始化添加warm-flow

---
 src/components/ImageUpload/index.vue |  262 ++++++++++++++++++++++++++++------------------------
 1 files changed, 142 insertions(+), 120 deletions(-)

diff --git a/src/components/ImageUpload/index.vue b/src/components/ImageUpload/index.vue
index 01edc4f..0778121 100644
--- a/src/components/ImageUpload/index.vue
+++ b/src/components/ImageUpload/index.vue
@@ -1,6 +1,7 @@
 <template>
   <div class="component-upload-image">
     <el-upload
+      ref="imageUpload"
       multiple
       :action="uploadImgUrl"
       list-type="picture-card"
@@ -9,7 +10,6 @@
       :limit="limit"
       :on-error="handleUploadError"
       :on-exceed="handleExceed"
-      ref="imageUpload"
       :before-remove="handleDelete"
       :show-file-list="true"
       :headers="headers"
@@ -22,13 +22,13 @@
       </el-icon>
     </el-upload>
     <!-- 涓婁紶鎻愮ず -->
-    <div class="el-upload__tip" v-if="showTip">
+    <div v-if="showTip" class="el-upload__tip">
       璇蜂笂浼�
       <template v-if="fileSize">
         澶у皬涓嶈秴杩� <b style="color: #f56c6c">{{ fileSize }}MB</b>
       </template>
       <template v-if="fileType">
-        鏍煎紡涓� <b style="color: #f56c6c">{{ fileType.join("/") }}</b>
+        鏍煎紡涓� <b style="color: #f56c6c">{{ fileType.join('/') }}</b>
       </template>
       鐨勬枃浠�
     </div>
@@ -40,177 +40,199 @@
 </template>
 
 <script setup lang="ts">
-import { getToken } from "@/utils/auth";
-import { listByIds, delOss } from "@/api/system/oss";
-import { ComponentInternalInstance, PropType } from "vue";
-import { OssVO } from "@/api/system/oss/types";
+import { listByIds, delOss } from '@/api/system/oss';
+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: [String, Object, Array],
-    // 鍥剧墖鏁伴噺闄愬埗
-    limit: propTypes.number.def(5),
-    // 澶у皬闄愬埗(MB)
-    fileSize: propTypes.number.def(5),
-    // 鏂囦欢绫诲瀷, 渚嬪['png', 'jpg', 'jpeg']
-    fileType: propTypes.array.def(["png", "jpg", "jpeg"]),
-    // 鏄惁鏄剧ず鎻愮ず
-    isShowTip: {
-        type: Boolean,
-        default: true
-    },
+  modelValue: {
+    type: [String, Object, Array],
+    default: () => []
+  },
+  // 鍥剧墖鏁伴噺闄愬埗
+  limit: propTypes.number.def(5),
+  // 澶у皬闄愬埗(MB)
+  fileSize: propTypes.number.def(5),
+  // 鏂囦欢绫诲瀷, 渚嬪['png', 'jpg', 'jpeg']
+  fileType: propTypes.array.def(['png', 'jpg', 'jpeg']),
+  // 鏄惁鏄剧ず鎻愮ず
+  isShowTip: {
+    type: Boolean,
+    default: true
+  },
+  // 鏄惁鏀寔鍘嬬缉锛岄粯璁ゅ惁
+  compressSupport: {
+    type: Boolean,
+    default: false
+  },
+  // 鍘嬬缉鐩爣澶у皬锛屽崟浣岾B銆傞粯璁�300KB浠ヤ笂鏂囦欢鎵嶅帇缂╋紝骞跺帇缂╄嚦300KB浠ュ唴
+  compressTargetSize: propTypes.number.def(300)
 });
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const emit = defineEmits(['update:modelValue']);
 const number = ref(0);
 const uploadList = ref<any[]>([]);
-const dialogImageUrl = ref("");
+const dialogImageUrl = ref('');
 const dialogVisible = ref(false);
 
 const baseUrl = import.meta.env.VITE_APP_BASE_API;
-const uploadImgUrl = ref(baseUrl + "/resource/oss/upload"); // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃
-const headers = ref({ Authorization: "Bearer " + getToken() });
+const uploadImgUrl = ref(baseUrl + '/resource/oss/upload'); // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃
+const headers = ref(globalHeaders());
 
 const fileList = ref<any[]>([]);
-const showTip = computed(
-    () => props.isShowTip && (props.fileType || props.fileSize)
-);
+const showTip = computed(() => props.isShowTip && (props.fileType || props.fileSize));
 
 const imageUploadRef = ref<ElUploadInstance>();
 
-watch(() => props.modelValue, async val => {
+watch(
+  () => props.modelValue,
+  async (val: string) => {
     if (val) {
-        // 棣栧厛灏嗗�艰浆涓烘暟缁�
-        let list: OssVO[] = [];
-        if (Array.isArray(val)) {
-            list = val as OssVO[];
+      // 棣栧厛灏嗗�艰浆涓烘暟缁�
+      let list: OssVO[] = [];
+      if (Array.isArray(val)) {
+        list = val as OssVO[];
+      } else {
+        const res = await listByIds(val);
+        list = res.data;
+      }
+      // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁�
+      fileList.value = list.map((item) => {
+        // 瀛楃涓插洖鏄惧鐞� 濡傛灉姝ゅ瀛樼殑鏄痷rl鍙洿鎺ュ洖鏄� 濡傛灉瀛樼殑鏄痠d闇�瑕佽皟鐢ㄦ帴鍙f煡鍑烘潵
+        let itemData;
+        if (typeof item === 'string') {
+          itemData = { name: item, url: item };
         } else {
-            const res = await listByIds(val as string)
-            list = res.data
+          // 姝ゅname浣跨敤ossId 闃叉鍒犻櫎鍑虹幇閲嶅悕
+          itemData = { name: item.ossId, url: item.url, ossId: item.ossId };
         }
-        // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁�
-        fileList.value = list.map(item => {
-            // 瀛楃涓插洖鏄惧鐞� 濡傛灉姝ゅ瀛樼殑鏄痷rl鍙洿鎺ュ洖鏄� 濡傛灉瀛樼殑鏄痠d闇�瑕佽皟鐢ㄦ帴鍙f煡鍑烘潵
-            let itemData;
-            if (typeof item === "string") {
-                itemData = { name: item, url: item };
-            } else {
-                // 姝ゅname浣跨敤ossId 闃叉鍒犻櫎鍑虹幇閲嶅悕
-                itemData = { name: item.ossId, url: item.url, ossId: item.ossId };
-            }
-            return itemData;
-        });
+        return itemData;
+      });
     } else {
-        fileList.value = [];
-        return [];
+      fileList.value = [];
+      return [];
     }
-}, { deep: true, immediate: true });
+  },
+  { deep: true, immediate: true }
+);
 
 /** 涓婁紶鍓峫oading鍔犺浇 */
 const handleBeforeUpload = (file: any) => {
-    let isImg = false;
-    if (props.fileType.length) {
-        let fileExtension = "";
-        if (file.name.lastIndexOf(".") > -1) {
-            fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
-        }
-        isImg = props.fileType.some((type: any) => {
-            if (file.type.indexOf(type) > -1) return true;
-            if (fileExtension && fileExtension.indexOf(type) > -1) return true;
-            return false;
-        });
-    } else {
-        isImg = file.type.indexOf("image") > -1;
+  let isImg = false;
+  if (props.fileType.length) {
+    let fileExtension = '';
+    if (file.name.lastIndexOf('.') > -1) {
+      fileExtension = file.name.slice(file.name.lastIndexOf('.') + 1);
     }
-    if (!isImg) {
-        proxy?.$modal.msgError(
-            `鏂囦欢鏍煎紡涓嶆纭�, 璇蜂笂浼�${props.fileType.join("/")}鍥剧墖鏍煎紡鏂囦欢!`
-        );
-        return false;
+    isImg = props.fileType.some((type: any) => {
+      if (file.type.indexOf(type) > -1) return true;
+      if (fileExtension && fileExtension.indexOf(type) > -1) return true;
+      return false;
+    });
+  } else {
+    isImg = file.type.indexOf('image') > -1;
+  }
+  if (!isImg) {
+    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) {
+      proxy?.$modal.msgError(`涓婁紶澶村儚鍥剧墖澶у皬涓嶈兘瓒呰繃 ${props.fileSize} MB!`);
+      return false;
     }
-    if (props.fileSize) {
-        const isLt = file.size / 1024 / 1024 < props.fileSize;
-        if (!isLt) {
-            proxy?.$modal.msgError(`涓婁紶澶村儚鍥剧墖澶у皬涓嶈兘瓒呰繃 ${props.fileSize} MB!`);
-            return false;
-        }
-    }
-    proxy?.$modal.loading("姝e湪涓婁紶鍥剧墖锛岃绋嶅��...");
+  }
+
+  //鍘嬬缉鍥剧墖锛屽紑鍚帇缂╁苟涓斿ぇ浜庢寚瀹氱殑鍘嬬缉澶у皬鏃舵墠鍘嬬缉
+  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++;
+  }
+};
 
 // 鏂囦欢涓暟瓒呭嚭
 const handleExceed = () => {
-    proxy?.$modal.msgError(`涓婁紶鏂囦欢鏁伴噺涓嶈兘瓒呰繃 ${props.limit} 涓�!`);
-}
+  proxy?.$modal.msgError(`涓婁紶鏂囦欢鏁伴噺涓嶈兘瓒呰繃 ${props.limit} 涓�!`);
+};
 
 // 涓婁紶鎴愬姛鍥炶皟
 const handleUploadSuccess = (res: any, file: UploadFile) => {
-    if (res.code === 200) {
-        uploadList.value.push({ name: res.data.fileName, url: res.data.url, ossId: res.data.ossId });
-        uploadedSuccessfully();
-    } else {
-        number.value--;
-        proxy?.$modal.closeLoading();
-        proxy?.$modal.msgError(res.msg);
-        imageUploadRef.value?.handleRemove(file);
-        uploadedSuccessfully();
-    }
-}
+  if (res.code === 200) {
+    uploadList.value.push({ name: res.data.fileName, url: res.data.url, ossId: res.data.ossId });
+    uploadedSuccessfully();
+  } else {
+    number.value--;
+    proxy?.$modal.closeLoading();
+    proxy?.$modal.msgError(res.msg);
+    imageUploadRef.value?.handleRemove(file);
+    uploadedSuccessfully();
+  }
+};
 
 // 鍒犻櫎鍥剧墖
 const handleDelete = (file: UploadFile): boolean => {
-    const findex = fileList.value.map(f => f.name).indexOf(file.name);
-    if (findex > -1 && uploadList.value.length === number.value) {
-        let ossId = fileList.value[findex].ossId;
-        delOss(ossId);
-        fileList.value.splice(findex, 1);
-        emit("update:modelValue", listToString(fileList.value));
-        return false;
-    }
-    return true;
-}
+  const findex = fileList.value.map((f) => f.name).indexOf(file.name);
+  if (findex > -1 && uploadList.value.length === number.value) {
+    let ossId = fileList.value[findex].ossId;
+    delOss(ossId);
+    fileList.value.splice(findex, 1);
+    emit('update:modelValue', listToString(fileList.value));
+    return false;
+  }
+  return true;
+};
 
 // 涓婁紶缁撴潫澶勭悊
 const uploadedSuccessfully = () => {
-    if (number.value > 0 && uploadList.value.length === number.value) {
-        fileList.value = fileList.value.filter(f => f.url !== undefined).concat(uploadList.value);
-        uploadList.value = [];
-        number.value = 0;
-        emit("update:modelValue", listToString(fileList.value));
-        proxy?.$modal.closeLoading();
-    }
-}
+  if (number.value > 0 && uploadList.value.length === number.value) {
+    fileList.value = fileList.value.filter((f) => f.url !== undefined).concat(uploadList.value);
+    uploadList.value = [];
+    number.value = 0;
+    emit('update:modelValue', listToString(fileList.value));
+    proxy?.$modal.closeLoading();
+  }
+};
 
 // 涓婁紶澶辫触
 const handleUploadError = () => {
-    proxy?.$modal.msgError("涓婁紶鍥剧墖澶辫触");
-    proxy?.$modal.closeLoading();
-}
+  proxy?.$modal.msgError('涓婁紶鍥剧墖澶辫触');
+  proxy?.$modal.closeLoading();
+};
 
 // 棰勮
 const handlePictureCardPreview = (file: any) => {
-    dialogImageUrl.value = file.url;
-    dialogVisible.value = true;
-}
+  dialogImageUrl.value = file.url;
+  dialogVisible.value = true;
+};
 
 // 瀵硅薄杞垚鎸囧畾瀛楃涓插垎闅�
 const listToString = (list: any[], separator?: string) => {
-    let strs = "";
-    separator = separator || ",";
-    for (let i in list) {
-        if (undefined !== list[i].ossId && list[i].url.indexOf("blob:") !== 0) {
-            strs += list[i].ossId + separator;
-        }
+  let strs = '';
+  separator = separator || ',';
+  for (let i in list) {
+    if (undefined !== list[i].ossId && list[i].url.indexOf('blob:') !== 0) {
+      strs += list[i].ossId + separator;
     }
-    return strs != "" ? strs.substring(0, strs.length - 1) : "";
-}
+  }
+  return strs != '' ? strs.substring(0, strs.length - 1) : '';
+};
 </script>
 
 <style scoped lang="scss">
 // .el-upload--picture-card 鎺у埗鍔犲彿閮ㄥ垎
 :deep(.hide .el-upload--picture-card) {
-    display: none;
+  display: none;
 }
 </style>

--
Gitblit v1.9.3