优化:限制和验证用户导入上传的文件类型和扩展名为xls、xlsx

Signed-off-by: D哥 <12271764+darrenteng@user.noreply.gitee.com>
pull/90/head
D哥 2023-03-11 10:09:46 +00:00 committed by 小诺
parent d13dfb0043
commit e34944a950
1 changed files with 23 additions and 1 deletions

View File

@ -14,7 +14,7 @@
<a-divider dashed />
<div>
<a-spin :spinning="impUploadLoading">
<a-upload-dragger :show-upload-list="false" :custom-request="customRequestLocal">
<a-upload-dragger :show-upload-list="false" :custom-request="customRequestLocal" :accept="impAccept.map((item) => item.mimeType)">
<p class="ant-upload-drag-icon">
<inbox-outlined></inbox-outlined>
</p>
@ -44,10 +44,32 @@
const impAlertStatus = ref(false)
const impResultData = ref({})
const impResultErrorDataSource = ref([])
const impAccept = [
{
extension: '.xls',
mimeType: 'application/vnd.ms-excel'
},
{
extension: '.xlsx',
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
}
]
//
const customRequestLocal = (data) => {
impUploadLoading.value = true
const fileData = new FormData()
// .xls.xlsx
const extension = '.'.concat(data.file.name.split(".").slice(-1).toString().toLowerCase())
const mimeType = data.file.type
//
const extensionArr = impAccept.map((item) => item.extension)
// MIMEType
const mimeTypeArr = impAccept.map((item) => item.mimeType)
if (!extensionArr.includes(extension) || !mimeTypeArr.includes(mimeType)) {
message.warning('上传文件类型仅支持xls、xlsx格式文件')
impUploadLoading.value = false
return false
}
fileData.append('file', data.file)
return userApi
.userImport(fileData)