Skip to content

Commit

Permalink
perf(projects): 增强文件校验的兼容性
Browse files Browse the repository at this point in the history
  • Loading branch information
Azir-11 committed Nov 9, 2024
1 parent 7d9af64 commit 67677b2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion web/src/components/office/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
fileUrl.value = val
const fileExt = val.split('.')[1] || ''
const image = ['png', 'jpg', 'jpeg', 'gif']
ext.value = image.includes(fileExt) ? 'image' : fileExt
ext.value = image.includes(fileExt?.toLowerCase()) ? 'image' : fileExt
},
{ immediate: true }
)
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/selectImage/selectImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
const chooseImg = (url) => {
if (props.fileType) {
const typeSuccess = listObj[props.fileType].some((item) => {
if (url.includes(item)) {
if (url?.toLowerCase().includes(item)) {
return true
}
})
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/upload/image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
})
const beforeImageUpload = (file) => {
const isJPG = file.type === 'image/jpeg'
const isPng = file.type === 'image/png'
const isJPG = file.type?.toLowerCase() === 'image/jpeg'
const isPng = file.type?.toLowerCase() === 'image/png'
if (!isJPG && !isPng) {
ElMessage.error('上传头像图片只能是 jpg或png 格式!')
return false
Expand Down
28 changes: 16 additions & 12 deletions web/src/utils/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ export const getUrl = (url) => {
}
}

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

export const isVideoMime = (type) =>
type == 'video/mp4' || type == 'video/webm' || type == 'video/ogg'
export const isVideoExt = (url) => {
const urlLower = url?.toLowerCase() || ''
return urlLower !== '' && VIDEO_EXTENSIONS.some(ext => urlLower.endsWith(ext))
}

export const isVideoMime = (type) => {
const typeLower = type?.toLowerCase() || ''
return typeLower !== '' && VIDEO_MIME_TYPES.includes(typeLower)
}

export const isImageMime = (type) =>
type == 'image/jpeg' ||
type == 'image/png' ||
type == 'image/webp' ||
type == 'image/svg+xml'
export const isImageMime = (type) => {
const typeLower = type?.toLowerCase() || ''
return typeLower !== '' && IMAGE_MIME_TYPES.includes(typeLower)
}
2 changes: 1 addition & 1 deletion web/src/view/example/upload/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<el-table-column align="left" label="标签" prop="tag" width="100">
<template #default="scope">
<el-tag
:type="scope.row.tag === 'jpg' ? 'info' : 'success'"
:type="scope.row.tag?.toLowerCase() === 'jpg' ? 'info' : 'success'"
disable-transitions
>{{ scope.row.tag }}
</el-tag>
Expand Down

0 comments on commit 67677b2

Please sign in to comment.