|
|
@ -1,7 +1,7 @@ |
|
|
|
<!-- 导入组件 --> |
|
|
|
<template> |
|
|
|
<Dialog v-model="dialogVisible" title="导入" width="600"> |
|
|
|
<el-upload ref="uploadRef" v-model:file-list="fileList" :action="importUrl + '?mode=' + mode + '&file=' + file + '&updatePart=' + updatePart" |
|
|
|
<el-upload ref="uploadRef" v-model:file-list="fileList" action="#" |
|
|
|
:auto-upload="false" :disabled="formLoading" :headers="uploadHeaders" :limit="1" :on-error="submitFormError" |
|
|
|
:on-exceed="handleExceed" :on-success="submitFormSuccess" :accept="accept" drag |
|
|
|
style="width:300px;margin:0 auto"> |
|
|
@ -63,6 +63,7 @@ |
|
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
|
import {ElMessageBox } from 'element-plus' |
|
|
|
import download from '@/utils/download' |
|
|
|
import request from '@/config/axios' |
|
|
|
|
|
|
|
defineOptions({ name: 'ImportForm' }) |
|
|
|
|
|
|
@ -151,10 +152,32 @@ const submitForm = async () => { |
|
|
|
// 提交请求 |
|
|
|
uploadHeaders.value = { |
|
|
|
Authorization: 'Bearer ' + getAccessToken(), |
|
|
|
'tenant-id': getTenantId() |
|
|
|
'tenant-id': getTenantId(), |
|
|
|
} |
|
|
|
formLoading.value = true |
|
|
|
uploadRef.value!.submit() |
|
|
|
const formData = new FormData() |
|
|
|
formData.append('888', fileList.value[0].raw) |
|
|
|
request.post({ |
|
|
|
url: importUrl, |
|
|
|
method:'POST', |
|
|
|
params:{mode:mode.value, file: '888', 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() |
|
|
|
} |
|
|
|
|
|
|
|
/** 文件上传成功 */ |
|
|
@ -162,13 +185,24 @@ const emits = defineEmits(['success']) |
|
|
|
const submitFormSuccess = (response: any) => { |
|
|
|
|
|
|
|
formLoading.value = true |
|
|
|
var byteString = atob(response) |
|
|
|
var arrayBuffer = new ArrayBuffer(byteString.length) // 创建缓冲数组 |
|
|
|
var intArray = new Uint8Array(arrayBuffer) // 创建视图 |
|
|
|
for (var i = 0; i < byteString.length; i++) { |
|
|
|
intArray[i] = byteString.charCodeAt(i) |
|
|
|
} |
|
|
|
const file = new Blob([intArray], { type: '' }) |
|
|
|
// 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') |
|
|
|
// // 创建下载的链接 |
|
|
@ -252,6 +286,7 @@ const handleExceed = (): void => { |
|
|
|
/** 下载模板操作 */ |
|
|
|
const importTemplate = () => { |
|
|
|
const res = importTemplateData.value.templateUrl |
|
|
|
console.log(266,importTemplateData.value.templateUrl) |
|
|
|
console.log(1); |
|
|
|
console.log(res); |
|
|
|
console.log(1); |
|
|
|