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>
<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) //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) => {
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) //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')
// //
@ -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);

Loading…
Cancel
Save