Selaa lähdekoodia

Merge branch 'master' of http://47.107.245.0:3000/xiongxing/kyj-yanglao-web-new

xiongxing 1 viikko sitten
vanhempi
commit
a2054c6d0e

+ 1 - 1
src/components/UploadFile/src/TableUpload.vue

@@ -124,7 +124,7 @@ const httpRequest = (options: any) => {
         fileList.value.push({
           fileUrl: res.data,
           fileName: rawFile.name,
-          fileSize: rawFile.size,
+          fileSize: res.compressedSize ?? rawFile.size,
           createTime: formatDateTime(new Date(), 'yyyy-MM-dd HH:mm:ss')
         })
         emit('success', fileList.value)

+ 7 - 5
src/components/UploadFile/src/useUpload.ts

@@ -201,7 +201,7 @@ const compressPdf = async (file: File, options: CompressOptions = {}): Promise<F
   for (let i = 1; i <= pdfDocument.numPages; i++) {
     const page = await pdfDocument.getPage(i)
     // 基础 scale 2.0,文字更清晰;再根据最大尺寸等比缩放
-    const baseScale = 1.2
+    const baseScale = 1.5
     const baseViewport = page.getViewport({ scale: baseScale })
 
     let renderWidth = baseViewport.width
@@ -271,12 +271,13 @@ export const useUpload = (menu: string = '', elder: any = { elderId: '', elderNa
     // 上传前压缩:图片/PDF 大于 5MB 时压缩
     const file = await compressFile(options.file, { maxSize: 5 * 1024 * 1024 })
 
-    // 模式一:前端上传
-    if (isClientUpload) {
+    // 模式一:前端上传//因为上传很慢,!isClientUpload这里用前端上传
+    if (!isClientUpload) {
       // 1.1 生成文件名称
       const fileName = generateFileName(file)
       // 1.2 获取文件预签名地址
       const presignedInfo = await FileApi.getFilePresignedUrl(fileName)
+      //console.log("AAAA",presignedInfo)
       // 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持)
       return axios
         .put(presignedInfo.uploadUrl, file, {
@@ -289,7 +290,7 @@ export const useUpload = (menu: string = '', elder: any = { elderId: '', elderNa
           // 1.4. 记录文件信息到后端(异步)
           createFile(presignedInfo, fileName, file)
           // 通知成功,数据格式保持与后端上传的返回结果一致
-          return { data: presignedInfo.url }
+          return { code: 0, data: presignedInfo.url, compressedSize: file.size, msg: '' }
         })
     } else {
       // 模式二:后端上传
@@ -305,7 +306,8 @@ export const useUpload = (menu: string = '', elder: any = { elderId: '', elderNa
             if (res.code === 0) {
               resolve({
                 ...res,
-                fileName: file.name
+                fileName: file.name,
+                compressedSize: file.size
               })
             } else {
               reject({