Jelajahi Sumber

修改档案上传时出现超时

unknown 2 minggu lalu
induk
melakukan
2cbd880b1d

+ 2 - 2
src/api/infra/file/index.ts

@@ -40,6 +40,6 @@ export const createFile = (data: any) => {
 }
 
 // 上传文件
-export const updateFile = (data: any) => {
-  return request.upload({ url: '/infra/file/upload', data })
+export const updateFile = (data: any, timeout?: number) => {
+  return request.upload({ url: '/infra/file/upload', data, timeout })
 }

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

@@ -46,9 +46,10 @@
         :before-upload="beforeUpload"
         :show-file-list="false"
         :accept="accept"
+        :disabled="uploading"
         multiple
       >
-        <el-button type="primary">
+        <el-button type="primary" :loading="uploading">
           <Icon icon="ep:upload" />点击选择文件
         </el-button>
       </el-upload>
@@ -101,6 +102,8 @@ const props = defineProps({
 const emit = defineEmits(['update:modelValue', 'success'])
 
 const uploadRef = ref()
+const uploadingCount = ref(0)
+const uploading = computed(() => uploadingCount.value > 0)
 
 const fileList: any = computed({
   get: () => props.modelValue || [],
@@ -113,6 +116,7 @@ const { httpRequest: uploadFn } = useUpload(
 )
 
 const httpRequest = (options: any) => {
+  uploadingCount.value++
   const rawFile = options.file
   uploadFn(options)
     .then((res: any) => {
@@ -131,6 +135,9 @@ const httpRequest = (options: any) => {
     .catch(() => {
       message.error('上传失败')
     })
+    .finally(() => {
+      uploadingCount.value--
+    })
 }
 
 const beforeUpload = (rawFile: any) => {

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

@@ -107,6 +107,8 @@ export const useUpload = (menu: string = '', elder: any = { elderId: '', elderNa
   const uploadUrl = getUploadUrl()
   // 是否使用前端直连上传
   const isClientUpload = UPLOAD_TYPE.CLIENT === import.meta.env.VITE_UPLOAD_TYPE
+  // 上传超时时间(5分钟),文件上传通常比普通接口耗时更长
+  const uploadTimeout = 5 * 60 * 1000
   // 重写ElUpload上传方法
   const httpRequest = async (options: UploadRequestOptions) => {
     // 模式一:前端上传
@@ -120,7 +122,8 @@ export const useUpload = (menu: string = '', elder: any = { elderId: '', elderNa
         .put(presignedInfo.uploadUrl, options.file, {
           headers: {
             'Content-Type': options.file.type
-          }
+          },
+          timeout: uploadTimeout
         })
         .then(() => {
           // 1.4. 记录文件信息到后端(异步)
@@ -137,7 +140,7 @@ export const useUpload = (menu: string = '', elder: any = { elderId: '', elderNa
           operation: menu,
           elderName: elder.elderName,
           elderId: elder.elderId
-        })
+        }, uploadTimeout)
           .then((res) => {
             if (res.code === 0) {
               resolve({

+ 0 - 6
src/views/elderly/fee/daily-fee/medicine-form.vue

@@ -178,16 +178,10 @@ import {
   getMedicineListByTenant,
   useMedicine
 } from '@/api/elderly/fee/daily-fee'
-import { getOverheadPage } from '@/api/elderly/fee/overheadCharge'
-import { getChargeCategoryTree } from '@/api/elderly/fee/chargeCategory'
-import { findTreeNode } from '@/utils/tree'
 import { formatDate } from '@/utils/formatTime'
 import { getNursingLevelPage } from '@/api/elderly/nursing'
-import dayjs from 'dayjs'
 import { useSettingStore } from '@/store/modules/setting'
 import { formatNum } from '@/utils/formatter'
-import { getTenantId } from '@/utils/auth'
-
 const message = useMessage() // 消息弹窗
 const { t } = useI18n() // 国际化
 const dialogVisible = ref(false)