Przeglądaj źródła

Merge branch 'cc-dev' into 'dev'

修改文件上传name

See merge request product-group-fe/sfy-safety-group/sfy-safety!111
陈昶 10 miesięcy temu
rodzic
commit
740e6d2938

+ 8 - 1
src/views/disaster/disaster-control/PageDisposalRectificationItem.vue

@@ -98,8 +98,15 @@
   };
   const formatFileList = async (file: FileItem) => {
     if (!file.file) return file;
+    const uuid = Math.random().toString(36).substring(2, 9);
+    const timestamp = Date.now().toString();
+    const random = Math.random().toString(36).substring(2, 4);
     const fileName = file.fileName;
-    const res = await uploadFileApi({ bizType: UPLOAD_BIZ_TYPE.ATTACHMENT, fileName, file: file.file });
+    const res = await uploadFileApi({
+      bizType: UPLOAD_BIZ_TYPE.ATTACHMENT,
+      fileName: `${uuid}-${timestamp}-${random}`,
+      file: file.file,
+    });
     const fileType = file.fileType;
     const fileSize = file.fileSize;
     const fileId = file.fileId;

+ 14 - 5
src/views/disaster/utils/download.ts

@@ -8,16 +8,16 @@ export const downloadFile = (url: string | undefined, name: string): void => {
   // 创建XMLHttpRequest请求
   const request = new XMLHttpRequest();
   request.responseType = "blob";
-  
+
   // 打开请求
   request.open("GET", encodeURI(url));
-  
+
   // 设置onload回调函数
   request.onload = function () {
     if (this.status === 200) {
       // 创建Blob URL
       const blobUrl = window.URL.createObjectURL(this.response);
-      
+
       // 创建a标签
       const link = document.createElement('a');
       // 设置下载链接
@@ -36,12 +36,21 @@ export const downloadFile = (url: string | undefined, name: string): void => {
       window.URL.revokeObjectURL(blobUrl);
     }
   };
-  
+
   // 添加错误处理
   request.onerror = function() {
     console.error('下载文件失败');
   };
-  
+
   // 发送请求
   request.send();
 };
+// export const downloadFile = (url: string | undefined, name: string): void => {
+//   if (!url) return;
+//   const link = document.createElement('a');
+//   link.href = url;
+//   link.download = name;
+//   document.body.appendChild(link);
+//   link.click();
+//   document.body.removeChild(link);
+// };