Browse Source

导入

master
zhang_li 1 year ago
parent
commit
ce46a44b8d
  1. 128
      src/components/ImportForm/src/ImportForm.vue

128
src/components/ImportForm/src/ImportForm.vue

@ -1,16 +1,41 @@
<!-- 导入组件 --> <!-- 导入组件 -->
<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 + '&outFile=' + outFile" <el-upload
:auto-upload="false" :disabled="formLoading" :headers="uploadHeaders" :limit="1" :on-error="submitFormError" ref="uploadRef"
:on-exceed="handleExceed" :on-success="submitFormSuccess" :accept="accept" drag v-model:file-list="fileList"
style="width:300px;margin:0 auto"> :action="
importUrl +
'?mode=' +
mode +
'&file=' +
file +
'&updatePart=' +
updatePart +
'&outFile=' +
outFile
"
: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"
>
<Icon icon="ep:upload-filled" color="#c0c4cc" size="60" /> <Icon icon="ep:upload-filled" color="#c0c4cc" size="60" />
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div> <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<template #tip> <template #tip>
<div class="el-upload__tip ml--126px mr--80px"> <div class="el-upload__tip ml--126px mr--80px">
<div class="flex"> <div class="flex">
<div class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right" style="line-height:32px">导入模式</div> <div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>导入模式</div
>
<div class=""> <div class="">
<div class="radio"> <div class="radio">
<el-radio-group v-model="mode"> <el-radio-group v-model="mode">
@ -28,7 +53,11 @@
</div> </div>
</div> </div>
<div class="flex mt-16px"> <div class="flex mt-16px">
<div class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right" style="line-height:32px">部分保存</div> <div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>部分保存</div
>
<div class=""> <div class="">
<div class="switch"> <div class="switch">
<el-switch v-model="updatePart" /> <el-switch v-model="updatePart" />
@ -40,7 +69,11 @@
</div> </div>
</div> </div>
<div class="flex mt-16px" v-if="isShowOut"> <div class="flex mt-16px" v-if="isShowOut">
<div class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right" style="line-height:32px">是否外部资源</div> <div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>是否外部资源</div
>
<div class=""> <div class="">
<div class="switch"> <div class="switch">
<el-switch v-model="outFile" /> <el-switch v-model="outFile" />
@ -54,9 +87,9 @@
<div class="flex items-center"> <div class="flex items-center">
<div class="flex-1 text-left"> <div class="flex-1 text-left">
<el-button type="primary" plain @click="importTemplate"> <el-button type="primary" plain @click="importTemplate">
<Icon icon="ep:download" /> <Icon icon="ep:download" />
下载模板 下载模板
</el-button> </el-button>
</div> </div>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button> <el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button> <el-button @click="dialogVisible = false"> </el-button>
@ -79,9 +112,7 @@ const uploadHeaders = ref() // 上传 Header 头
const fileList = ref([]) // const fileList = ref([]) //
const file = ref('') const file = ref('')
const props = defineProps({
const props = defineProps({
importTemplateData: { importTemplateData: {
type: Object, type: Object,
required: true required: true
@ -90,7 +121,7 @@ const file = ref('')
accept: { accept: {
type: String, type: String,
required: false, required: false,
default:'.xlsx,.xls' default: '.xlsx,.xls'
}, },
// .1 // .1
mode: { mode: {
@ -122,9 +153,9 @@ const file = ref('')
required: false, required: false,
default: false default: false
}, },
url:{ url: {
type: String, type: String,
required: false, required: false
}, },
// //
isShowOut: { isShowOut: {
@ -136,19 +167,18 @@ const file = ref('')
type: Boolean, type: Boolean,
required: false, required: false,
default: false default: false
}, }
}) })
const importTemplateData= ref(props.importTemplateData) const importTemplateData = ref(props.importTemplateData)
const accept= ref(props.accept) const accept = ref(props.accept)
const mode = ref(props.mode)//.1 const mode = ref(props.mode) //.1
const updateIsDisable = ref(props.updateIsDisable)//, const updateIsDisable = ref(props.updateIsDisable) //,
const appendIsDisable = ref(props.appendIsDisable)//, const appendIsDisable = ref(props.appendIsDisable) //,
const coverIsDisable = ref(props.coverIsDisable)//, const coverIsDisable = ref(props.coverIsDisable) //,
const updatePart = ref(props.updatePart)// const updatePart = ref(props.updatePart) //
const outFile = ref(props.outFile)// const outFile = ref(props.outFile) //
const importUrl = const importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + props.url
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + props.url
/** 打开弹窗 */ /** 打开弹窗 */
const open = () => { const open = () => {
@ -159,7 +189,6 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */ /** 提交表单 */
const submitForm = async () => { const submitForm = async () => {
if (fileList.value.length == 0) { if (fileList.value.length == 0) {
message.error('请上传文件') message.error('请上传文件')
return return
@ -168,7 +197,7 @@ 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() uploadRef.value!.submit()
@ -179,27 +208,32 @@ const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => { const submitFormSuccess = (response: any) => {
formLoading.value = true formLoading.value = true
console.log(response) console.log(response)
if(response){ if (response) {
if(response.code == 500){ if (response.code == 500) {
uploadRef.value!.clearFiles() uploadRef.value!.clearFiles()
message.error('导入失败') message.error('导入失败')
formLoading.value = false formLoading.value = false
return; return
} else if (response.data.errorCount > 0) { } else if (response.code == 0) {
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => { if (response.data.errorCount > 0) {
// download.excel(file, 'file_' + new Date().getTime()) message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => {
// url // download.excel(file, 'file_' + new Date().getTime())
// const downloadElement = document.createElement('a') // url
// console.log(172, import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/' + response.data.errorFile) // const downloadElement = document.createElement('a')
// console.log(172, import.meta.env.VITE_BASE_URL + '/admin-api/opt/profile/' + response.data.errorFile) // console.log(172, import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/' + response.data.errorFile)
window.open(import.meta.env.VITE_BASE_URL + '/admin-api/profile/' + response.data.errorFile ,'222') // console.log(172, import.meta.env.VITE_BASE_URL + '/admin-api/opt/profile/' + response.data.errorFile)
// downloadElement.setAttribute('href', import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + response.data.errorFile ) window.open(
// import.meta.env.VITE_BASE_URL + '/admin-api/profile/' + response.data.errorFile,
// downloadElement.click() '222'
}) )
// downloadElement.setAttribute('href', import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + response.data.errorFile )
//
// downloadElement.click()
})
} else {
message.success('导入成功')
}
} }
}else{
message.success('导入成功')
} }
// if (response.code !== 0) { // if (response.code !== 0) {

Loading…
Cancel
Save