fit: 文件限制
This commit is contained in:
parent
1a65ce3222
commit
c0d0f53baa
@ -39,10 +39,14 @@ export function fileType(name: string) {
|
|||||||
获得文件对应图片
|
获得文件对应图片
|
||||||
*/
|
*/
|
||||||
export function getImgUrl(name: string) {
|
export function getImgUrl(name: string) {
|
||||||
const typeList = ['txt', 'pdf', 'doc', 'csv', 'md']
|
const type = isRightType(name) ? fileType(name) : 'unknow'
|
||||||
const type = typeList.includes(fileType(name)) ? fileType(name) : 'unknow'
|
|
||||||
return new URL(`../assets/${type}-icon.svg`, import.meta.url).href
|
return new URL(`../assets/${type}-icon.svg`, import.meta.url).href
|
||||||
}
|
}
|
||||||
|
// 是否是白名单后缀
|
||||||
|
export function isRightType(name: string) {
|
||||||
|
const typeList = ['txt', 'pdf', 'doc', 'csv', 'md']
|
||||||
|
return typeList.includes(fileType(name))
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
从指定数组中过滤出对应的对象
|
从指定数组中过滤出对应的对象
|
||||||
|
|||||||
@ -61,7 +61,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
|
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
|
||||||
import type { UploadFile, UploadFiles } from 'element-plus'
|
import type { UploadFile, UploadFiles } from 'element-plus'
|
||||||
import { filesize, getImgUrl } from '@/utils/utils'
|
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
|
||||||
import { MsgError } from '@/utils/message'
|
import { MsgError } from '@/utils/message'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
const { dataset } = useStore()
|
const { dataset } = useStore()
|
||||||
@ -91,6 +91,11 @@ const filehandleChange = (file: any, fileList: UploadFiles) => {
|
|||||||
fileList.splice(-1, 1) //移除当前超出大小的文件
|
fileList.splice(-1, 1) //移除当前超出大小的文件
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (!isRightType(file?.name)) {
|
||||||
|
MsgError('文件格式不支持')
|
||||||
|
fileList.splice(-1, 1)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onExceed = () => {
|
const onExceed = () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user