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

Loading…
Cancel
Save