基础设施:增加前端直连上传文件到S3服务的功能
							parent
							
								
									c26eb543e0
								
							
						
					
					
						commit
						a7c37bce14
					
				| 
						 | 
				
			
			@ -43,8 +43,7 @@
 | 
			
		|||
  <XModal v-model="uploadDialogVisible" :title="uploadDialogTitle">
 | 
			
		||||
    <el-upload
 | 
			
		||||
      ref="uploadRef"
 | 
			
		||||
      :action="updateUrl + '?updateSupport=' + updateSupport"
 | 
			
		||||
      :headers="uploadHeaders"
 | 
			
		||||
      :action="uploadUrl"
 | 
			
		||||
      :drag="true"
 | 
			
		||||
      :limit="1"
 | 
			
		||||
      :multiple="true"
 | 
			
		||||
| 
						 | 
				
			
			@ -57,6 +56,7 @@
 | 
			
		|||
      :before-remove="beforeRemove"
 | 
			
		||||
      :on-change="handleFileChange"
 | 
			
		||||
      :auto-upload="false"
 | 
			
		||||
      :http-request="httpRequest"
 | 
			
		||||
      accept=".jpg, .png, .gif"
 | 
			
		||||
    >
 | 
			
		||||
      <Icon icon="ep:upload-filled" />
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +83,7 @@ import type { UploadInstance, UploadRawFile, UploadProps, UploadFile } from 'ele
 | 
			
		|||
// 业务相关的 import
 | 
			
		||||
import { allSchemas } from './fileList.data'
 | 
			
		||||
import * as FileApi from '@/api/infra/fileList'
 | 
			
		||||
import { getAccessToken, getTenantId } from '@/utils/auth'
 | 
			
		||||
import { useUpload } from '@/components/UploadFile/src/useUpload'
 | 
			
		||||
// import { useClipboard } from '@vueuse/core'
 | 
			
		||||
 | 
			
		||||
defineOptions({ name: 'InfraFile' })
 | 
			
		||||
| 
						 | 
				
			
			@ -106,8 +106,7 @@ const uploadDialogTitle = ref('上传')
 | 
			
		|||
const updateSupport = ref(0)
 | 
			
		||||
const uploadDisabled = ref(false)
 | 
			
		||||
const uploadRef = ref<UploadInstance>()
 | 
			
		||||
let updateUrl = import.meta.env.VITE_UPLOAD_URL
 | 
			
		||||
const uploadHeaders = ref()
 | 
			
		||||
const { uploadUrl, httpRequest } = useUpload()
 | 
			
		||||
// 文件上传之前判断
 | 
			
		||||
const beforeUpload = (file: UploadRawFile) => {
 | 
			
		||||
  const isImg = file.type === 'image/jpeg' || 'image/gif' || 'image/png'
 | 
			
		||||
| 
						 | 
				
			
			@ -124,10 +123,6 @@ const handleFileChange = (uploadFile: UploadFile): void => {
 | 
			
		|||
}
 | 
			
		||||
// 文件上传
 | 
			
		||||
const submitFileForm = () => {
 | 
			
		||||
  uploadHeaders.value = {
 | 
			
		||||
    Authorization: 'Bearer ' + getAccessToken(),
 | 
			
		||||
    'tenant-id': getTenantId()
 | 
			
		||||
  }
 | 
			
		||||
  uploadDisabled.value = true
 | 
			
		||||
  uploadRef.value!.submit()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue