perf: 上传头像可支持GIF,大小扩大到10M

This commit is contained in:
wangdan-fit2cloud 2024-08-07 11:17:20 +08:00
parent 4b2213a171
commit 2605d50bd0
4 changed files with 28 additions and 20 deletions

View File

@ -48,10 +48,10 @@ export default {
upload: 'Upload', upload: 'Upload',
default: 'Default Logo', default: 'Default Logo',
custom: 'Custom', custom: 'Custom',
sizeTip: 'Suggested size 32*32, supports ico, png, size no more than 200KB', sizeTip: 'Suggested size 32*32, supports jpg, png, gif, size no more than 10 M',
cancel: 'Cancel', cancel: 'Cancel',
save: 'Save', save: 'Save',
fileSizeExceeded: 'File size exceeds 200KB', fileSizeExceeded: 'File size exceeds 10 M',
setSuccess: 'Setting Successful', setSuccess: 'Setting Successful',
uploadImagePrompt: 'Please upload an image' uploadImagePrompt: 'Please upload an image'
}, },

View File

@ -42,15 +42,15 @@ export default {
disabledSuccess: '已禁用' disabledSuccess: '已禁用'
}, },
EditAvatarDialog: { EditAvatarDialog: {
title: '编辑logo', title: '应用头像',
customizeUpload: '自定义上传', customizeUpload: '自定义上传',
upload: '上传', upload: '上传',
default: '默认logo', default: '默认logo',
custom: '自定义', custom: '自定义',
sizeTip: '建议尺寸 32*32支持 ico、png大小不超过200KB', sizeTip: '建议尺寸 32*32支持 JPG、PNG, GIF大小不超过 10 M',
cancel: '取消', cancel: '取消',
save: '保存', save: '保存',
fileSizeExceeded: '文件大小超过 200KB', fileSizeExceeded: '文件大小超过 10 M',
setSuccess: '设置成功', setSuccess: '设置成功',
uploadImagePrompt: '请上传一张图片' uploadImagePrompt: '请上传一张图片'
}, },

View File

@ -47,7 +47,7 @@
}}</el-button> }}</el-button>
<template #tip> <template #tip>
<div class="el-upload__tip info" style="margin-top: 0"> <div class="el-upload__tip info" style="margin-top: 0">
建议尺寸 32*32支持 JPGPNG大小不超过 200 KB 建议尺寸 32*32支持 JPGPNG, GIF大小不超过 10 M
</div> </div>
</template> </template>
</el-upload> </el-upload>
@ -84,7 +84,7 @@
}}</el-button> }}</el-button>
<template #tip> <template #tip>
<div class="el-upload__tip info" style="margin-top: 0"> <div class="el-upload__tip info" style="margin-top: 0">
建议尺寸 32*32支持 JPGPNG大小不超过 200 KB 建议尺寸 32*32支持 JPGPNG, GIF大小不超过 10 M
</div> </div>
</template> </template>
</el-upload> </el-upload>
@ -178,8 +178,8 @@ function resetForm() {
} }
const onChange = (file: any, fileList: UploadFiles, attr: string) => { const onChange = (file: any, fileList: UploadFiles, attr: string) => {
//1 200KB //1 10 M
const isLimit = file?.size / 1024 < 200 const isLimit = file?.size / 1024 / 1024 < 10
if (!isLimit) { if (!isLimit) {
// @ts-ignore // @ts-ignore
MsgError(t('views.applicationOverview.appInfo.EditAvatarDialog.fileSizeExceeded')) MsgError(t('views.applicationOverview.appInfo.EditAvatarDialog.fileSizeExceeded'))

View File

@ -1,9 +1,12 @@
<template> <template>
<el-dialog :title="$t('views.applicationOverview.appInfo.EditAvatarDialog.title')" v-model="dialogVisible"> <el-dialog
:title="$t('views.applicationOverview.appInfo.EditAvatarDialog.title')"
v-model="dialogVisible"
>
<el-radio-group v-model="radioType" class="radio-block mb-16"> <el-radio-group v-model="radioType" class="radio-block mb-16">
<div> <div>
<el-radio value="default"> <el-radio value="default">
<p>{{$t('views.applicationOverview.appInfo.EditAvatarDialog.default')}}</p> <p>{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.default') }}</p>
<AppAvatar <AppAvatar
v-if="detail?.name" v-if="detail?.name"
:name="detail?.name" :name="detail?.name"
@ -16,7 +19,7 @@
</div> </div>
<div class="mt-8"> <div class="mt-8">
<el-radio value="custom"> <el-radio value="custom">
<p>{{$t('views.applicationOverview.appInfo.EditAvatarDialog.customizeUpload')}}</p> <p>{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.customizeUpload') }}</p>
<div class="flex mt-8"> <div class="flex mt-8">
<AppAvatar <AppAvatar
v-if="fileURL" v-if="fileURL"
@ -35,19 +38,25 @@
accept="image/*" accept="image/*"
:on-change="onChange" :on-change="onChange"
> >
<el-button icon="Upload" :disabled="radioType !== 'custom'">{{$t('views.applicationOverview.appInfo.EditAvatarDialog.upload')}}</el-button> <el-button icon="Upload" :disabled="radioType !== 'custom'">{{
$t('views.applicationOverview.appInfo.EditAvatarDialog.upload')
}}</el-button>
</el-upload> </el-upload>
</div> </div>
<div class="el-upload__tip info mt-16"> <div class="el-upload__tip info mt-16">
{{$t('views.applicationOverview.appInfo.EditAvatarDialog.sizeTip')}} {{ $t('views.applicationOverview.appInfo.EditAvatarDialog.sizeTip') }}
</div> </div>
</el-radio> </el-radio>
</div> </div>
</el-radio-group> </el-radio-group>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> {{$t('views.applicationOverview.appInfo.EditAvatarDialog.cancel')}}</el-button> <el-button @click.prevent="dialogVisible = false">
<el-button type="primary" @click="submit" :loading="loading"> {{$t('views.applicationOverview.appInfo.EditAvatarDialog.save')}}</el-button> {{ $t('views.applicationOverview.appInfo.EditAvatarDialog.cancel') }}</el-button
>
<el-button type="primary" @click="submit" :loading="loading">
{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.save') }}</el-button
>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
@ -94,17 +103,16 @@ const open = (data: any) => {
} }
const onChange = (file: any) => { const onChange = (file: any) => {
//1 200KB //1 10M
const isLimit = file?.size / 1024 < 200 const isLimit = file?.size / 1024 / 1024 < 10
if (!isLimit) { if (!isLimit) {
// @ts-ignore // @ts-ignore
MsgError(t('views.applicationOverview.appInfo.EditAvatarDialog.fileSizeExceeded')) MsgError(t('views.applicationOverview.appInfo.EditAvatarDialog.fileSizeExceeded'))
return false return false
} else { } else {
iconFile.value = file iconFile.value = file
fileURL.value = URL.createObjectURL(file.raw) fileURL.value = URL.createObjectURL(file.raw)
} }
} }
function submit() { function submit() {