Browse Source

导入组件修改下载错误报告为url

master
陈薪名 1 year ago
parent
commit
b32e595d0c
  1. 74
      src/components/ImportForm/src/ImportForm.vue

74
src/components/ImportForm/src/ImportForm.vue

@ -1,7 +1,7 @@
<!-- 导入组件 --> <!-- 导入组件 -->
<template> <template>
<Dialog v-model="dialogVisible" title="导入" width="600"> <Dialog v-model="dialogVisible" title="导入" width="600">
<el-upload ref="uploadRef" v-model:file-list="fileList" action="#" <el-upload ref="uploadRef" v-model:file-list="fileList" :action="importUrl + '?mode=' + mode + '&file=' + file + '&updatePart=' + updatePart"
:auto-upload="false" :disabled="formLoading" :headers="uploadHeaders" :limit="1" :on-error="submitFormError" :auto-upload="false" :disabled="formLoading" :headers="uploadHeaders" :limit="1" :on-error="submitFormError"
:on-exceed="handleExceed" :on-success="submitFormSuccess" :accept="accept" drag :on-exceed="handleExceed" :on-success="submitFormSuccess" :accept="accept" drag
style="width:300px;margin:0 auto"> style="width:300px;margin:0 auto">
@ -59,11 +59,8 @@
</Dialog> </Dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// import * as UserApi from '@/api/system/user'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
import {ElMessageBox } from 'element-plus'
import download from '@/utils/download' import download from '@/utils/download'
import request from '@/config/axios'
defineOptions({ name: 'ImportForm' }) defineOptions({ name: 'ImportForm' })
@ -155,80 +152,25 @@ const submitForm = async () => {
'tenant-id': getTenantId(), 'tenant-id': getTenantId(),
} }
formLoading.value = true formLoading.value = true
const formData = new FormData() uploadRef.value!.submit()
formData.append(file.value, fileList.value[0].raw)
request.post({
url: importUrl,
method:'POST',
params:{mode:mode.value, file: file.value, updatePart: updatePart.value},
data:formData, responseType:'blob',
headersType:'multipart/form-data' })
.then((response: any) => {
formLoading.value = true
const file = new Blob([response], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
const href = URL.createObjectURL(file) //URLblob
const a = document.createElement('a') //a
a.style.display = 'none'
a.href = href //
a.download = '11111111' //
a.click() //
URL.revokeObjectURL(a.href) //URL
})
.catch(err => {
console.log(err)
})
// uploadRef.value!.submit()
} }
/** 文件上传成功 */ /** 文件上传成功 */
const emits = defineEmits(['success']) const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => { const submitFormSuccess = (response: any) => {
formLoading.value = true formLoading.value = true
// let arr = response.split(',')
// let mime = arr[0].match(/:(.*?);/)
// var byteString = atob(mime)
// var arrayBuffer = new ArrayBuffer(byteString.length) //
// var intArray = new Uint8Array(arrayBuffer) //
// for (var i = 0; i < byteString.length; i++) {
// intArray[i] = byteString.charCodeAt(i)
// }
// 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
const file = new Blob([response], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
const href = URL.createObjectURL(file) //URLblob
const a = document.createElement('a') //a
a.style.display = 'none'
a.href = href //
a.download = '11111111' //
a.click() //
URL.revokeObjectURL(a.href) //URL
// // headsfilename
// const downloadElement = document.createElement('a')
// //
// const href = window.URL.createObjectURL(blob)
// downloadElement.href = href
// //
// downloadElement.download = '11'
// document.body.appendChild(downloadElement)
// //
// downloadElement.click()
// //
// document.body.removeChild(downloadElement)
// // blob
// window.URL.revokeObjectURL(href)
// console.log(2);
// console.log(response);
// const file = new Blob([response])
// console.log(file);
// console.log(2);
if(response){ if(response){
if(response.code == 500){ if(response.code == 500){
message.error('导入失败') message.error('导入失败')
return; return;
}else{ }else{
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => { message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => {
download.excel(file, 'file_' + new Date().getTime()) // download.excel(file, 'file_' + new Date().getTime())
// url
const downloadElement = document.createElement('a')
downloadElement.setAttribute('href','https://sf3-cn.feishucdn.com/obj/ee-appcenter/99cc1467/Feishu-win32_ia32-6.11.16-signed.exe' )
//
downloadElement.click()
}) })
} }
}else{ }else{

Loading…
Cancel
Save