|
@ -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) //创建新的URL表示指定的blob对象 |
|
|
|
|
|
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) //创建新的URL表示指定的blob对象 |
|
|
|
|
|
const a = document.createElement('a') //创建a标签 |
|
|
|
|
|
a.style.display = 'none' |
|
|
|
|
|
a.href = href // 指定下载链接 |
|
|
|
|
|
a.download = '11111111' //指定下载文件名 |
|
|
|
|
|
a.click() //触发下载 |
|
|
|
|
|
URL.revokeObjectURL(a.href) //释放URL对象 |
|
|
|
|
|
// // 获取heads中的filename文件名 |
|
|
|
|
|
// 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{ |
|
|