优化:限制和验证用户导入上传的文件类型和扩展名为xls、xlsx
Signed-off-by: D哥 <12271764+darrenteng@user.noreply.gitee.com>
This commit is contained in:
parent
d13dfb0043
commit
e34944a950
@ -14,7 +14,7 @@
|
|||||||
<a-divider dashed />
|
<a-divider dashed />
|
||||||
<div>
|
<div>
|
||||||
<a-spin :spinning="impUploadLoading">
|
<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">
|
<p class="ant-upload-drag-icon">
|
||||||
<inbox-outlined></inbox-outlined>
|
<inbox-outlined></inbox-outlined>
|
||||||
</p>
|
</p>
|
||||||
@ -44,10 +44,32 @@
|
|||||||
const impAlertStatus = ref(false)
|
const impAlertStatus = ref(false)
|
||||||
const impResultData = ref({})
|
const impResultData = ref({})
|
||||||
const impResultErrorDataSource = 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) => {
|
const customRequestLocal = (data) => {
|
||||||
impUploadLoading.value = true
|
impUploadLoading.value = true
|
||||||
const fileData = new FormData()
|
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)
|
fileData.append('file', data.file)
|
||||||
return userApi
|
return userApi
|
||||||
.userImport(fileData)
|
.userImport(fileData)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user