Bläddra i källkod

档案下载有问题

unknown 1 vecka sedan
förälder
incheckning
d6ab1ed240

+ 17 - 9
src/components/Table2/index.vue

@@ -552,7 +552,6 @@ const parsingJSON = (row) => {
     return []
     return []
   }else {
   }else {
     let json = JSON.parse(row)
     let json = JSON.parse(row)
-    console.log("JSON",json)
     return json
     return json
   }
   }
 
 
@@ -567,14 +566,23 @@ const handleSelectable = (row) => {
 
 
 
 
 const handleDownload = (row: FileItem) => {
 const handleDownload = (row: FileItem) => {
-  const a = document.createElement('a')
-  a.href = row.fileUrl
-  a.download = row.fileName
-  a.target = '_blank'
-  a.rel = 'noopener noreferrer'
-  document.body.appendChild(a)
-  a.click()
-  document.body.removeChild(a)
+  console.log(row)
+  fetch(row.fileUrl)
+    .then((response) => {
+      if (!response.ok) throw new Error('下载失败')
+      return response.blob()
+    })
+    .then((blob) => {
+      const url = URL.createObjectURL(blob)
+      const a = document.createElement('a')
+      a.href = url
+      a.download = row.fileName
+      document.body.appendChild(a)
+      a.click()
+      document.body.removeChild(a)
+      URL.revokeObjectURL(url)
+    })
+    .catch((error) => console.error('下载失败:', error))
 }
 }
 
 
 const getDictLabelArr = (dictArr, field) => {
 const getDictLabelArr = (dictArr, field) => {

+ 5 - 9
src/components/UploadFile/src/SelectUpload.vue

@@ -307,25 +307,21 @@ const handlePreview = (item) => {
 
 
 const handleDownLoad = (item) => {
 const handleDownLoad = (item) => {
   fetch(item.fileUrl)
   fetch(item.fileUrl)
-    .then((response) => response.blob())
+    .then((response) => {
+      if (!response.ok) throw new Error('下载失败')
+      return response.blob()
+    })
     .then((blob) => {
     .then((blob) => {
-      // 创建一个指向Blob的URL
       const url = URL.createObjectURL(blob)
       const url = URL.createObjectURL(blob)
-
-      // 创建一个a标签用于下载
       const a = document.createElement('a')
       const a = document.createElement('a')
       a.href = url
       a.href = url
-      // 尝试设置下载文件名
       a.download = item.fileName
       a.download = item.fileName
-      // 触发下载
       document.body.appendChild(a)
       document.body.appendChild(a)
       a.click()
       a.click()
-
-      // 清理
       document.body.removeChild(a)
       document.body.removeChild(a)
       URL.revokeObjectURL(url)
       URL.revokeObjectURL(url)
     })
     })
-    .catch((error) => console.error('Error downloading the file:', error))
+    .catch((error) => console.error('下载失败:', error))
 }
 }
 
 
 const showFile = (item) => {
 const showFile = (item) => {

+ 19 - 8
src/components/UploadFile/src/TableUpload.vue

@@ -158,14 +158,25 @@ const handleRemove = (index: number, row: FileItem) => {
 }
 }
 
 
 const handleDownload = (row: FileItem) => {
 const handleDownload = (row: FileItem) => {
-  const a = document.createElement('a')
-  a.href = row.fileUrl
-  a.download = row.fileName
-  a.target = '_blank'
-  a.rel = 'noopener noreferrer'
-  document.body.appendChild(a)
-  a.click()
-  document.body.removeChild(a)
+  fetch(row.fileUrl)
+    .then((response) => {
+      if (!response.ok) throw new Error('下载失败')
+      return response.blob()
+    })
+    .then((blob) => {
+      const url = URL.createObjectURL(blob)
+      const a = document.createElement('a')
+      a.href = url
+      a.download = row.fileName
+      document.body.appendChild(a)
+      a.click()
+      document.body.removeChild(a)
+      URL.revokeObjectURL(url)
+    })
+    .catch((error) => {
+      console.error('下载失败:', error)
+      message.error('下载失败,请重试')
+    })
 }
 }
 
 
 watch(
 watch(

+ 17 - 0
src/components/UploadFile/src/useUpload.ts

@@ -70,6 +70,23 @@ export const isImageFile = (url: string): boolean => {
   return /\.(jpg|jpeg|png|gif|bmp|webp|ico)(\?.*)?$/i.test(url)
   return /\.(jpg|jpeg|png|gif|bmp|webp|ico)(\?.*)?$/i.test(url)
 }
 }
 
 
+/**
+ * 构建带下载文件名的 URL
+ * 利用阿里云 OSS 的 response-content-disposition 参数,
+ * 解决跨域下载时 download 属性不生效、文件名错乱的问题
+ */
+export const buildDownloadUrl = (fileUrl: string, fileName: string): string => {
+  if (!fileUrl) return ''
+  if (!fileName) return fileUrl
+
+  const isOssUrl = /\.aliyuncs\.com/.test(fileUrl)
+  if (!isOssUrl) return fileUrl
+
+  const disposition = `attachment;filename="${encodeURIComponent(fileName)}"`
+  const separator = fileUrl.includes('?') ? '&' : '?'
+  return fileUrl + separator + 'response-content-disposition=' + encodeURIComponent(disposition)
+}
+
 /**
 /**
  * 兼容方案:为老版本上传的文件补齐 fileSize
  * 兼容方案:为老版本上传的文件补齐 fileSize
  * 逻辑:
  * 逻辑:

+ 5 - 9
src/views/elderly/fee/bill-pay/Form.vue

@@ -914,25 +914,21 @@ const formatArr = (dict: string, value: string) => {
 // 下载文件
 // 下载文件
 const handleDownLoad = (item) => {
 const handleDownLoad = (item) => {
   fetch(item.fileUrl)
   fetch(item.fileUrl)
-    .then((response) => response.blob())
+    .then((response) => {
+      if (!response.ok) throw new Error('下载失败')
+      return response.blob()
+    })
     .then((blob) => {
     .then((blob) => {
-      // 创建一个指向Blob的URL
       const url = URL.createObjectURL(blob)
       const url = URL.createObjectURL(blob)
-
-      // 创建一个a标签用于下载
       const a = document.createElement('a')
       const a = document.createElement('a')
       a.href = url
       a.href = url
-      // 尝试设置下载文件名
       a.download = item.fileName
       a.download = item.fileName
-      // 触发下载
       document.body.appendChild(a)
       document.body.appendChild(a)
       a.click()
       a.click()
-
-      // 清理
       document.body.removeChild(a)
       document.body.removeChild(a)
       URL.revokeObjectURL(url)
       URL.revokeObjectURL(url)
     })
     })
-    .catch((error) => console.error('Error downloading the file:', error))
+    .catch((error) => console.error('下载失败:', error))
 }
 }
 
 
 onMounted(()=>{
 onMounted(()=>{

+ 22 - 2
src/views/elderly/fee/out-refund/Form.vue

@@ -32,7 +32,7 @@
             </TgSelect>
             </TgSelect>
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
-        <el-col :span="12" :xs="24">
+        <el-col :span="6" :xs="24">
           <el-form-item label="是否退费" prop="isRefund">
           <el-form-item label="是否退费" prop="isRefund">
             <TgRadio
             <TgRadio
               v-model="dataForm.isRefund"
               v-model="dataForm.isRefund"
@@ -48,7 +48,23 @@
             </TgRadio>
             </TgRadio>
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
-        <el-col :span="12" :xs="24">
+        <el-col :span="6" :xs="24">
+          <el-form-item v-if="dataForm.isRefund" label="是否自动跨月" prop="isAutoCross" label-width="130">
+            <TgRadio
+              v-model="dataForm.isAutoCross"
+              clearable
+              :list="getDictOptions(DICT_TYPE.COMMON_STATUS6)"
+            >
+              <el-radio
+                v-for="(item, index) in getIntDictOptions(DICT_TYPE.COMMON_STATUS6)"
+                :key="index"
+                :value="item.value"
+              >{{ item.label }}</el-radio
+              >
+            </TgRadio>
+          </el-form-item>
+        </el-col>
+        <el-col :span="6" :xs="24">
           <el-form-item label="状态" prop="status">
           <el-form-item label="状态" prop="status">
             <TgRadio
             <TgRadio
               v-model="dataForm.status"
               v-model="dataForm.status"
@@ -397,6 +413,7 @@ const state = reactive<OutRefundFormType>({
     name: '',
     name: '',
     type: '',
     type: '',
     isRefund: '',
     isRefund: '',
+    isAutoCross: 1,
     isSameDayRefund: '',
     isSameDayRefund: '',
     configType: 0,
     configType: 0,
     status: 1,
     status: 1,
@@ -430,6 +447,9 @@ const open = async (tenantId, id, detail) => {
     try {
     try {
       const res = await getOutboundRefundDetail(id)
       const res = await getOutboundRefundDetail(id)
       dataForm.value = res
       dataForm.value = res
+      if(!dataForm.value.isAutoCross){
+        dataForm.value.isAutoCross = 1
+      }
       dataForm.value.items.map(async (item) => {
       dataForm.value.items.map(async (item) => {
         getItemList(item, false, false)
         getItemList(item, false, false)
       })
       })