mirror of https://gitee.com/xiaonuobase/snowy
【更新】优化代码,业务下人员管理导入功能同步加入导入文件类型限制
parent
e34944a950
commit
47ff13c198
|
@ -37,6 +37,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="bizUserImpExp">
|
<script setup name="bizUserImpExp">
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
import userApi from '@/api/sys/userApi'
|
import userApi from '@/api/sys/userApi'
|
||||||
import bizUserApi from '@/api/biz/bizUserApi'
|
import bizUserApi from '@/api/biz/bizUserApi'
|
||||||
import downloadUtil from '@/utils/downloadUtil'
|
import downloadUtil from '@/utils/downloadUtil'
|
||||||
|
@ -45,10 +46,38 @@
|
||||||
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 uploadAccept = String(
|
||||||
|
impAccept.map((item) => {
|
||||||
|
return item.mimeType
|
||||||
|
})
|
||||||
|
)
|
||||||
// 导入
|
// 导入
|
||||||
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 bizUserApi
|
return bizUserApi
|
||||||
.userImport(fileData)
|
.userImport(fileData)
|
||||||
|
|
|
@ -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" :accept="impAccept.map((item) => item.mimeType)">
|
<a-upload-dragger :show-upload-list="false" :custom-request="customRequestLocal" :accept="uploadAccept">
|
||||||
<p class="ant-upload-drag-icon">
|
<p class="ant-upload-drag-icon">
|
||||||
<inbox-outlined></inbox-outlined>
|
<inbox-outlined></inbox-outlined>
|
||||||
</p>
|
</p>
|
||||||
|
@ -37,8 +37,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="userImpExp">
|
<script setup name="userImpExp">
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
import userApi from '@/api/sys/userApi'
|
import userApi from '@/api/sys/userApi'
|
||||||
import downloadUtil from "@/utils/downloadUtil"
|
import downloadUtil from '@/utils/downloadUtil'
|
||||||
|
|
||||||
const impUploadLoading = ref(false)
|
const impUploadLoading = ref(false)
|
||||||
const impAlertStatus = ref(false)
|
const impAlertStatus = ref(false)
|
||||||
|
@ -54,12 +55,18 @@
|
||||||
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
// 指定能选择的文件类型
|
||||||
|
const uploadAccept = String(
|
||||||
|
impAccept.map((item) => {
|
||||||
|
return item.mimeType
|
||||||
|
})
|
||||||
|
)
|
||||||
// 导入
|
// 导入
|
||||||
const customRequestLocal = (data) => {
|
const customRequestLocal = (data) => {
|
||||||
impUploadLoading.value = true
|
impUploadLoading.value = true
|
||||||
const fileData = new FormData()
|
const fileData = new FormData()
|
||||||
// 校验上传文件扩展名和文件类型是否为.xls、.xlsx
|
// 校验上传文件扩展名和文件类型是否为.xls、.xlsx
|
||||||
const extension = '.'.concat(data.file.name.split(".").slice(-1).toString().toLowerCase())
|
const extension = '.'.concat(data.file.name.split('.').slice(-1).toString().toLowerCase())
|
||||||
const mimeType = data.file.type
|
const mimeType = data.file.type
|
||||||
// 提取允许的扩展名
|
// 提取允许的扩展名
|
||||||
const extensionArr = impAccept.map((item) => item.extension)
|
const extensionArr = impAccept.map((item) => item.extension)
|
||||||
|
|
Loading…
Reference in New Issue