|
@ -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="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" |
|
|
: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"> |
|
@ -63,6 +63,7 @@ |
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
import {ElMessageBox } from 'element-plus' |
|
|
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' }) |
|
|
|
|
|
|
|
@ -151,10 +152,32 @@ const submitForm = async () => { |
|
|
// 提交请求 |
|
|
// 提交请求 |
|
|
uploadHeaders.value = { |
|
|
uploadHeaders.value = { |
|
|
Authorization: 'Bearer ' + getAccessToken(), |
|
|
Authorization: 'Bearer ' + getAccessToken(), |
|
|
'tenant-id': getTenantId() |
|
|
'tenant-id': getTenantId(), |
|
|
} |
|
|
} |
|
|
formLoading.value = true |
|
|
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) => { |
|
|
const submitFormSuccess = (response: any) => { |
|
|
|
|
|
|
|
|
formLoading.value = true |
|
|
formLoading.value = true |
|
|
var byteString = atob(response) |
|
|
// let arr = response.split(',') |
|
|
var arrayBuffer = new ArrayBuffer(byteString.length) // 创建缓冲数组 |
|
|
// let mime = arr[0].match(/:(.*?);/) |
|
|
var intArray = new Uint8Array(arrayBuffer) // 创建视图 |
|
|
// var byteString = atob(mime) |
|
|
for (var i = 0; i < byteString.length; i++) { |
|
|
// var arrayBuffer = new ArrayBuffer(byteString.length) // 创建缓冲数组 |
|
|
intArray[i] = byteString.charCodeAt(i) |
|
|
// var intArray = new Uint8Array(arrayBuffer) // 创建视图 |
|
|
} |
|
|
// for (var i = 0; i < byteString.length; i++) { |
|
|
const file = new Blob([intArray], { type: '' }) |
|
|
// 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文件名 |
|
|
// // 获取heads中的filename文件名 |
|
|
// const downloadElement = document.createElement('a') |
|
|
// const downloadElement = document.createElement('a') |
|
|
// // 创建下载的链接 |
|
|
// // 创建下载的链接 |
|
@ -252,6 +286,7 @@ const handleExceed = (): void => { |
|
|
/** 下载模板操作 */ |
|
|
/** 下载模板操作 */ |
|
|
const importTemplate = () => { |
|
|
const importTemplate = () => { |
|
|
const res = importTemplateData.value.templateUrl |
|
|
const res = importTemplateData.value.templateUrl |
|
|
|
|
|
console.log(266,importTemplateData.value.templateUrl) |
|
|
console.log(1); |
|
|
console.log(1); |
|
|
console.log(res); |
|
|
console.log(res); |
|
|
console.log(1); |
|
|
console.log(1); |
|
|