Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增强文件校验的兼容性 #1929

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/src/components/office/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ watch(
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 @@ -212,7 +212,7 @@ const listObj = {
const chooseImg = (url) => {
if (props.fileType) {
const typeSuccess = listObj[props.fileType].some(item => {
if (url.includes(item)) {
if (url.includes(item.toLowerCase())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里写反了吧,应该是对url进行toLowerCase

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 @@ -39,8 +39,8 @@ const props = defineProps({
})

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
19 changes: 16 additions & 3 deletions web/src/utils/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +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 @@ -85,7 +85,7 @@
>
<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
Loading