Browse Source

导入

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

72
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" />
@ -79,8 +112,6 @@ 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,
@ -124,7 +155,7 @@ const file = ref('')
}, },
url: { url: {
type: String, type: String,
required: false, required: false
}, },
// //
isShowOut: { isShowOut: {
@ -136,7 +167,7 @@ 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)
@ -147,8 +178,7 @@ 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()
@ -184,23 +213,28 @@ const submitFormSuccess = (response: any) => {
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) {
if (response.data.errorCount > 0) {
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => { message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => {
// download.excel(file, 'file_' + new Date().getTime()) // download.excel(file, 'file_' + new Date().getTime())
// url // url
// const downloadElement = document.createElement('a') // 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 + 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) // 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') 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.setAttribute('href', import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + response.data.errorFile )
// //
// downloadElement.click() // downloadElement.click()
}) })
}
} else { } else {
message.success('导入成功') message.success('导入成功')
} }
}
}
// if (response.code !== 0) { // if (response.code !== 0) {
// message.error(response.msg) // message.error(response.msg)

Loading…
Cancel
Save