mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fit: 文件限制
This commit is contained in:
parent
1a65ce3222
commit
c0d0f53baa
|
|
@ -39,10 +39,14 @@ export function fileType(name: string) {
|
|||
获得文件对应图片
|
||||
*/
|
||||
export function getImgUrl(name: string) {
|
||||
const typeList = ['txt', 'pdf', 'doc', 'csv', 'md']
|
||||
const type = typeList.includes(fileType(name)) ? fileType(name) : 'unknow'
|
||||
const type = isRightType(name) ? fileType(name) : 'unknow'
|
||||
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">
|
||||
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
|
||||
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 useStore from '@/stores'
|
||||
const { dataset } = useStore()
|
||||
|
|
@ -91,6 +91,11 @@ const filehandleChange = (file: any, fileList: UploadFiles) => {
|
|||
fileList.splice(-1, 1) //移除当前超出大小的文件
|
||||
return false
|
||||
}
|
||||
if (!isRightType(file?.name)) {
|
||||
MsgError('文件格式不支持')
|
||||
fileList.splice(-1, 1)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const onExceed = () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue