Browse Source

文件上传修改

master
陈薪名 1 year ago
parent
commit
c6f18c912a
  1. 55
      src/components/ImportForm/src/ImportForm.vue

55
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="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) //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()
} }
/** 文件上传成功 */ /** 文件上传成功 */
@ -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) //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 // // headsfilename
// 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);

Loading…
Cancel
Save