Skip to content

Commit d314bfb

Browse files
committed
增强文件校验的兼容性
1 parent 35fd5c8 commit d314bfb

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

web/src/components/office/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ watch(
4343
fileUrl.value = val
4444
const fileExt = val.split('.')[1] || ''
4545
const image = ['png', 'jpg', 'jpeg', 'gif']
46-
ext.value = image.includes(fileExt) ? 'image' : fileExt
46+
ext.value = image.includes(fileExt.toLowerCase()) ? 'image' : fileExt
4747
},
4848
{ immediate: true }
4949
)

web/src/components/selectImage/selectImage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const listObj = {
212212
const chooseImg = (url) => {
213213
if (props.fileType) {
214214
const typeSuccess = listObj[props.fileType].some(item => {
215-
if (url.includes(item)) {
215+
if (url.includes(item.toLowerCase())) {
216216
return true
217217
}
218218
})

web/src/components/upload/image.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const props = defineProps({
3939
})
4040
4141
const beforeImageUpload = (file) => {
42-
const isJPG = file.type === 'image/jpeg'
43-
const isPng = file.type === 'image/png'
42+
const isJPG = file.type?.toLowerCase() === 'image/jpeg'
43+
const isPng = file.type?.toLowerCase() === 'image/png'
4444
if (!isJPG && !isPng) {
4545
ElMessage.error('上传头像图片只能是 jpg或png 格式!')
4646
return false

web/src/utils/image.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,21 @@ export const getUrl = (url) => {
106106
}
107107
}
108108

109-
export const isVideoExt = (url) => url.endsWith('.mp4') || url.endsWith('.mov') || url.endsWith('.webm') || url.endsWith('.ogg');
109+
const VIDEO_EXTENSIONS = ['.mp4', '.mov', '.webm', '.ogg']
110+
const VIDEO_MIME_TYPES = ['video/mp4', 'video/webm', 'video/ogg']
111+
const IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/webp', 'image/svg+xml']
110112

111-
export const isVideoMime = (type) => type == 'video/mp4' || type == 'video/webm' || type == 'video/ogg';
113+
export const isVideoExt = (url) => {
114+
const urlLower = url?.toLowerCase() || ''
115+
return urlLower !== '' && VIDEO_EXTENSIONS.some(ext => urlLower.endsWith(ext))
116+
}
117+
118+
export const isVideoMime = (type) => {
119+
const typeLower = type?.toLowerCase() || ''
120+
return typeLower !== '' && VIDEO_MIME_TYPES.includes(typeLower)
121+
}
112122

113-
export const isImageMime = (type) => type == 'image/jpeg' || type == 'image/png' || type == 'image/webp' || type == 'image/svg+xml';
123+
export const isImageMime = (type) => {
124+
const typeLower = type?.toLowerCase() || ''
125+
return typeLower !== '' && IMAGE_MIME_TYPES.includes(typeLower)
126+
}

web/src/view/example/upload/upload.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
>
8686
<template #default="scope">
8787
<el-tag
88-
:type="scope.row.tag === 'jpg' ? 'info' : 'success'"
88+
:type="scope.row.tag?.toLowerCase() === 'jpg' ? 'info' : 'success'"
8989
disable-transitions
9090
>{{ scope.row.tag }}
9191
</el-tag>

0 commit comments

Comments
 (0)