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