|
|
@ -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) { |
|
|
@ -225,9 +259,9 @@ const submitFormSuccess = (response: any) => { |
|
|
|
// text += '< ' + name + ': ' + data[failure][name] + ' >' |
|
|
|
// } |
|
|
|
// message.alert(text) |
|
|
|
|
|
|
|
|
|
|
|
// 发送操作成功的事件 |
|
|
|
|
|
|
|
|
|
|
|
formLoading.value = false |
|
|
|
emits('success') |
|
|
|
dialogVisible.value = false |
|
|
|