fit: 文件限制

This commit is contained in:
wangdan-fit2cloud 2024-04-10 15:50:57 +08:00
parent 1a65ce3222
commit c0d0f53baa
2 changed files with 12 additions and 3 deletions

View File

@ -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))
}
/*

View File

@ -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 = () => {