Skip to content

Commit

Permalink
Merge pull request #234 from xuewenG/fix/image-preview
Browse files Browse the repository at this point in the history
修复上传图片到S3时的预览问题
  • Loading branch information
xuewenG authored Dec 13, 2024
2 parents 2e15e56 + 5de1e87 commit 8955746
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 163 deletions.
22 changes: 10 additions & 12 deletions front/components/UploadImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template #panel="{close}">
<div class="p-4 flex flex-col gap-2">
<div class="text-xs text-gray-400">本地上传</div>
<UInput type="file" size="sm" icon="i-heroicons-folder" @change="upload" multiple/>
<UInput type="file" size="sm" icon="i-heroicons-folder" accept="image/*" @change="upload" multiple/>
<UTextarea :rows="5" placeholder="或者输入在线图片地址,逗号分隔,最多9张" v-model="imgs"/>

<p v-if="filename" class="text-xs text-gray-400">正在上传({{ current }}/{{ total }})</p>
Expand All @@ -30,23 +30,21 @@ const filename = ref('')
const total = ref(0)
const current = ref(0)
const upload = async (files: FileList) => {
for (let i = 0; i < files.length; i++) {
if (files[i].type.indexOf("image") < 0){
toast.error("只能上传图片");
return
}
const containsOtherFile = [...files].some(file => !file.type.startsWith('image/'))
if (containsOtherFile) {
toast.error("只能上传图片");
return
}
const result = await useUpload(files, (totalSize: number, index: number, name: string, p: number) => {
progress.value = Math.round(p * 100)
filename.value = name
total.value = totalSize
current.value = index
}) as string[]
toast.success("上传成功")
if (result) {
setTimeout(()=>{
imgs.value = (imgs.value ? imgs.value + ',' : '') + result.join(",")
},200)
})
if (result && result.length) {
toast.success("上传成功")
imgs.value = [imgs.value, ...result].filter(Boolean).join(',')
}
}
Expand Down
6 changes: 3 additions & 3 deletions front/components/UploadVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const handleUploadVideo = async (files: FileList) => {
filename.value = name
total.value = totalSize
current.value = index
}) as string[]
toast.success("上传成功")
if (result) {
})
if (result.length) {
toast.success("上传成功")
onlineUrl.value = result[0]
}
}
Expand Down
4 changes: 2 additions & 2 deletions front/pages/sys/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ const uploadFavicon = async (files: FileList) => {
}
}
const result = await useUpload(files)
toast.success("上传成功")
if (result) {
if (result.length) {
toast.success("上传成功")
state.favicon = result[0]
}
}
Expand Down
8 changes: 4 additions & 4 deletions front/pages/user/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ const uploadAvatarUrl = async (files: FileList) => {
}
}
const result = await useUpload(files)
toast.success("上传成功")
if (result) {
if (result.length) {
toast.success("上传成功")
state.avatarUrl = result[0]
}
}
Expand All @@ -87,8 +87,8 @@ const uploadCoverUrl = async (files: FileList) => {
}
}
const result = await useUpload(files)
toast.success("上传成功")
if (result) {
if (result.length) {
toast.success("上传成功")
state.coverUrl = result[0]
}
}
Expand Down
Loading

0 comments on commit 8955746

Please sign in to comment.