|
|
@ -61,8 +61,8 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
// import * as UserApi from '@/api/system/user' |
|
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
|
import {ElMessageBox } from 'element-plus' |
|
|
|
import download from '@/utils/download' |
|
|
|
import { log } from 'console' |
|
|
|
|
|
|
|
defineOptions({ name: 'ImportForm' }) |
|
|
|
|
|
|
@ -160,35 +160,77 @@ const submitForm = async () => { |
|
|
|
/** 文件上传成功 */ |
|
|
|
const emits = defineEmits(['success']) |
|
|
|
const submitFormSuccess = (response: any) => { |
|
|
|
if (response.code !== 0) { |
|
|
|
message.error(response.msg) |
|
|
|
formLoading.value = false |
|
|
|
return |
|
|
|
} |
|
|
|
// 拼接提示语 |
|
|
|
const data = response.data |
|
|
|
const create = response.data.importResult[0] |
|
|
|
const update = response.data.importResult[1] |
|
|
|
const failure = response.data.importResult[2] |
|
|
|
let text = '上传成功数量:' + data[create].length + ';' |
|
|
|
for (let name of data[create]) { |
|
|
|
text += '< ' + name + ' >' |
|
|
|
|
|
|
|
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) |
|
|
|
} |
|
|
|
text += '更新成功数量:' + data[update].length + ';' |
|
|
|
for (const name of data[update]) { |
|
|
|
text += '< ' + name + ' >' |
|
|
|
const file = new Blob([intArray], { type: '' }) |
|
|
|
// // 获取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.code == 500){ |
|
|
|
message.error('导入失败') |
|
|
|
return; |
|
|
|
}else{ |
|
|
|
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => { |
|
|
|
download.excel(file, 'file_' + new Date().getTime()) |
|
|
|
}) |
|
|
|
} |
|
|
|
text += '更新失败数量:' + Object.keys(data[failure]).length + ';' |
|
|
|
for (const name in data[failure]) { |
|
|
|
text += '< ' + name + ': ' + data[failure][name] + ' >' |
|
|
|
}else{ |
|
|
|
message.success('导入成功') |
|
|
|
} |
|
|
|
message.alert(text) |
|
|
|
|
|
|
|
// if (response.code !== 0) { |
|
|
|
// message.error(response.msg) |
|
|
|
// formLoading.value = false |
|
|
|
// return |
|
|
|
// } |
|
|
|
// // 拼接提示语 |
|
|
|
// const data = response.data |
|
|
|
// const create = response.data.importResult[0] |
|
|
|
// const update = response.data.importResult[1] |
|
|
|
// const failure = response.data.importResult[2] |
|
|
|
// let text = '上传成功数量:' + data[create].length + ';' |
|
|
|
// for (let name of data[create]) { |
|
|
|
// text += '< ' + name + ' >' |
|
|
|
// } |
|
|
|
// text += '更新成功数量:' + data[update].length + ';' |
|
|
|
// for (const name of data[update]) { |
|
|
|
// text += '< ' + name + ' >' |
|
|
|
// } |
|
|
|
// text += '更新失败数量:' + Object.keys(data[failure]).length + ';' |
|
|
|
// for (const name in data[failure]) { |
|
|
|
// text += '< ' + name + ': ' + data[failure][name] + ' >' |
|
|
|
// } |
|
|
|
// message.alert(text) |
|
|
|
|
|
|
|
// 发送操作成功的事件 |
|
|
|
|
|
|
|
formLoading.value = false |
|
|
|
emits('success') |
|
|
|
dialogVisible.value = false |
|
|
|
} |
|
|
|
|
|
|
|
/** 上传错误提示 */ |
|
|
|
const submitFormError = (): void => { |
|
|
|
message.error('上传失败,请您重新上传!') |
|
|
@ -210,6 +252,10 @@ const handleExceed = (): void => { |
|
|
|
/** 下载模板操作 */ |
|
|
|
const importTemplate = () => { |
|
|
|
const res = importTemplateData.value.templateUrl |
|
|
|
console.log(1); |
|
|
|
console.log(res); |
|
|
|
console.log(1); |
|
|
|
|
|
|
|
download.excel(res, importTemplateData.value.templateTitle) |
|
|
|
} |
|
|
|
</script> |
|
|
|