fixd:头像上传新增名称

This commit is contained in:
2024-06-13 14:06:54 +08:00
parent b28c4b4a6c
commit 804fa59f59

View File

@ -56,7 +56,7 @@
</el-col>
<el-col :lg="{ span: 2, offset: 6 }" :md="2">
<el-button type="primary" :loading="loading" @click="confirmUpload">
yyds
</el-button>
</el-col>
</el-row>
@ -74,10 +74,10 @@ const props = withDefaults(defineProps<{
fileId?: number | string
fileUrl?: string
/**
* 图片大小单位MB
*
* @default 2
*/
* 图片大小单位MB
*
* @default 2
*/
fileSize?: number
/** 默认生成截图框宽度 */
autoCropHeight?: number
@ -175,10 +175,13 @@ function realTime(data: PreviewData) {
options.previews = data
}
const file = shallowRef()
const fileName = shallowRef()
const cropperURL = useObjectUrl(file)
onChange((param) => {
file.value = param?.item(0)
const flName = param?.item(0).name
fileName.value = flName.substring(0, flName.lastIndexOf('.'))
})
function selectImage() {
@ -203,6 +206,7 @@ async function uploadImg(blob: Blob) {
loading = true
const formData = new FormData()
formData.append('file', blob)
formData.append('name', fileName.value)
try {
const res = await props.uploadFunction(formData)
@ -241,7 +245,7 @@ tryOnMounted(init)
watch(() => props.fileId, init)
</script>
<style>
@import url('vue-cropper/dist/index.css');
@import url('element-plus/theme-chalk/el-upload.css');
</style>
<style>
@import url('vue-cropper/dist/index.css');
@import url('element-plus/theme-chalk/el-upload.css');
</style>