图片上传

This commit is contained in:
陈红丽 2024-10-12 17:16:19 +08:00
parent 8553381768
commit 26b37e23d7
3 changed files with 6 additions and 1 deletions

View File

@ -41,6 +41,7 @@
:title="title" :title="title"
confirmButText="确认上传" confirmButText="确认上传"
:uploadApi="uploadApi" :uploadApi="uploadApi"
:name="name"
:circled="circled" :circled="circled"
@uploadSuccess="handleSuccess" @uploadSuccess="handleSuccess"
/> />
@ -62,6 +63,7 @@
uploadApi: { uploadApi: {
type: Function as PropType<(params) => Promise<any>>, type: Function as PropType<(params) => Promise<any>>,
}, },
name: { type: String, default: 'name' },
}); });
const getWidth = cssUnit(props.width); const getWidth = cssUnit(props.width);

View File

@ -179,6 +179,7 @@
uploadApi: { uploadApi: {
type: Function as PropType<(params) => Promise<any>>, type: Function as PropType<(params) => Promise<any>>,
}, },
name: { type: String, default: 'name' },
}; };
export default defineComponent({ export default defineComponent({
@ -251,13 +252,14 @@
return ElMessage.error('请先上传图片'); return ElMessage.error('请先上传图片');
} }
const uploadApi = props.uploadApi; const uploadApi = props.uploadApi;
const name = props.name
if (uploadApi && isFunction(uploadApi)) { if (uploadApi && isFunction(uploadApi)) {
const file = base64ToFile(previewSource.value,filename); const file = base64ToFile(previewSource.value,filename);
try { try {
setSubLoading(true); setSubLoading(true);
const formData = new FormData() const formData = new FormData()
formData.append('file',file) formData.append('file',file)
formData.append('name',filename) formData.append('name',name)
const result = await uploadApi(formData); const result = await uploadApi(formData);
emit('uploadSuccess', result); emit('uploadSuccess', result);
closeModal(); closeModal();

View File

@ -24,6 +24,7 @@
ref="cropperCircled" ref="cropperCircled"
:src="formData.avatar" :src="formData.avatar"
:uploadApi="upload" :uploadApi="upload"
name="user"
title="头像上传" title="头像上传"
@uploadSuccess="uploadSuccess" @uploadSuccess="uploadSuccess"
> >