add:新增上传接口,对接表单上传
This commit is contained in:
1 parent
280847acd1
commit
6120d0b8fa
7 files changed
+166
-113
No files matched your search
@@ -1,7 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
import type { UploadProps } from 'tdesign-vue-next'
|
||||
import { MessagePlugin, type UploadProps } from 'tdesign-vue-next'
|
||||
import {ref} from 'vue'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
const imageViewerProps = ref<UploadProps['imageViewerProps']>({
|
||||
closeOnEscKeydown: false,
|
||||
});
|
||||
const sizeLimit = ref<UploadProps['sizeLimit']>({
|
||||
size: 2,
|
||||
unit: 'MB',
|
||||
});
|
||||
const file1 = ref<UploadProps['value']>([]);
|
||||
const disabled = ref(false);
|
||||
const autoUpload = ref(true);
|
||||
const showImageFileName = ref(true);
|
||||
const uploadAllFilesInOneRequest = ref(false);
|
||||
const handleFail: UploadProps['onFail'] = ({ file }) => {
|
||||
MessagePlugin.error(`文件 ${file.name} 上传失败`);
|
||||
};
|
||||
const handleSuccess: UploadProps['onSuccess'] = ({ file }) => {
|
||||
if(file?.url){
|
||||
emits('on-success',file.url)
|
||||
}
|
||||
}
|
||||
const appStore = useAppStore()
|
||||
|
||||
const uploadHeaders = ref<UploadProps['headers']>({
|
||||
Authorization: `Bearer ${appStore.token}`
|
||||
})
|
||||
const emits = defineEmits(['on-success'])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -11,9 +37,10 @@ const file1 = ref<UploadProps['value']>([]);
|
||||
v-model="file1"
|
||||
:image-viewer-props="imageViewerProps"
|
||||
:size-limit="sizeLimit"
|
||||
action="https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com/api/upload-demo"
|
||||
action="/api/files/upload"
|
||||
:headers="uploadHeaders"
|
||||
theme="image"
|
||||
tips="单张图片文件上传(上传成功状态演示)"
|
||||
tips="图片上传限制为2M"
|
||||
accept="image/*"
|
||||
:disabled="disabled"
|
||||
:auto-upload="autoUpload"
|
||||
@@ -25,6 +52,7 @@ const file1 = ref<UploadProps['value']>([]);
|
||||
},
|
||||
}"
|
||||
@fail="handleFail"
|
||||
@success="handleSuccess"
|
||||
>
|
||||
<!-- custom UI -->
|
||||
<!-- <template #fileListDisplay="{ files }">
|
||||
|
||||
Reference in new issue
Block a user