完成中介库导入改造
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- 导入对话框 -->
|
||||
<el-dialog
|
||||
:title="title"
|
||||
:visible.sync="visible"
|
||||
@@ -13,22 +12,18 @@
|
||||
:close-on-press-escape="false"
|
||||
custom-class="import-dialog-wrapper"
|
||||
>
|
||||
<!-- 全屏Loading遮罩层 -->
|
||||
<div v-show="isUploading" class="import-loading-overlay">
|
||||
<i class="el-icon-loading"></i>
|
||||
<p>正在导入中,请稍候...</p>
|
||||
</div>
|
||||
|
||||
<el-form :model="formData" label-position="top" size="medium">
|
||||
<!-- 导入类型 -->
|
||||
<el-form-item label="导入类型">
|
||||
<el-radio-group v-model="formData.importType" @change="handleImportTypeChange" style="width: 100%">
|
||||
<el-radio label="person" border>个人中介</el-radio>
|
||||
<el-radio label="entity" border>机构中介</el-radio>
|
||||
</el-radio-group>
|
||||
<el-form label-position="top" size="medium">
|
||||
<el-form-item label="导入说明">
|
||||
<div class="scene-tips">
|
||||
<p v-for="item in sceneTips" :key="item">{{ item }}</p>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 文件上传 -->
|
||||
<el-form-item label="选择文件">
|
||||
<el-upload
|
||||
ref="upload"
|
||||
@@ -53,7 +48,6 @@
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 下载模板 -->
|
||||
<el-form-item>
|
||||
<el-link type="primary" :underline="false" @click="handleDownloadTemplate">
|
||||
<i class="el-icon-download"></i>
|
||||
@@ -62,7 +56,6 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button
|
||||
type="primary"
|
||||
@@ -79,7 +72,6 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 导入结果对话框 -->
|
||||
<import-result-dialog
|
||||
:visible.sync="importResultVisible"
|
||||
:content="importResultContent"
|
||||
@@ -90,10 +82,16 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {getToken} from "@/utils/auth";
|
||||
import {getEntityImportStatus, getPersonImportStatus} from "@/api/ccdiIntermediary";
|
||||
import { getToken } from "@/utils/auth";
|
||||
import {
|
||||
getEnterpriseRelationImportStatus,
|
||||
getPersonImportStatus
|
||||
} from "@/api/ccdiIntermediary";
|
||||
import ImportResultDialog from "@/components/ImportResultDialog.vue";
|
||||
|
||||
const PERSON_SCENE = "person";
|
||||
const ENTERPRISE_RELATION_SCENE = "enterpriseRelation";
|
||||
|
||||
export default {
|
||||
name: "ImportDialog",
|
||||
components: { ImportResultDialog },
|
||||
@@ -105,32 +103,55 @@ export default {
|
||||
title: {
|
||||
type: String,
|
||||
default: "数据导入"
|
||||
},
|
||||
scene: {
|
||||
type: String,
|
||||
default: PERSON_SCENE
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
formData: {
|
||||
importType: "person"
|
||||
},
|
||||
headers: { Authorization: "Bearer " + getToken() },
|
||||
isUploading: false,
|
||||
isFileSelected: false,
|
||||
// 导入结果弹窗
|
||||
importResultVisible: false,
|
||||
importResultContent: "",
|
||||
// 轮询状态
|
||||
pollingTimer: null,
|
||||
currentTaskId: null
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
sceneConfig() {
|
||||
if (this.scene === ENTERPRISE_RELATION_SCENE) {
|
||||
return {
|
||||
uploadPath: "/ccdi/intermediary/importEnterpriseRelationData",
|
||||
templatePath: "ccdi/intermediary/importEnterpriseRelationTemplate",
|
||||
templateName: "中介实体关联关系导入模板",
|
||||
statusApi: getEnterpriseRelationImportStatus,
|
||||
tips: [
|
||||
"只导入中介与机构关系;",
|
||||
"统一社会信用代码必须已存在于系统机构表。"
|
||||
]
|
||||
};
|
||||
}
|
||||
return {
|
||||
uploadPath: "/ccdi/intermediary/importPersonData",
|
||||
templatePath: "ccdi/intermediary/importPersonTemplate",
|
||||
templateName: "中介信息导入模板",
|
||||
statusApi: getPersonImportStatus,
|
||||
tips: [
|
||||
"personSubType 为字典下拉;",
|
||||
"本人行 relatedNumId 为空;",
|
||||
"亲属行 relatedNumId 填关联中介本人证件号码。"
|
||||
]
|
||||
};
|
||||
},
|
||||
uploadUrl() {
|
||||
const baseUrl = process.env.VUE_APP_BASE_API;
|
||||
if (this.formData.importType === 'person') {
|
||||
return `${baseUrl}/ccdi/intermediary/importPersonData`;
|
||||
} else {
|
||||
return `${baseUrl}/ccdi/intermediary/importEntityData`;
|
||||
}
|
||||
return `${baseUrl}${this.sceneConfig.uploadPath}`;
|
||||
},
|
||||
sceneTips() {
|
||||
return this.sceneConfig.tips;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -145,21 +166,14 @@ export default {
|
||||
this.$emit("close");
|
||||
},
|
||||
handleCancel() {
|
||||
// 通过 $emit 通知父组件更新 visible 状态,而不是直接修改 prop
|
||||
this.$emit('update:visible', false);
|
||||
},
|
||||
handleImportTypeChange() {
|
||||
if (this.$refs.upload) {
|
||||
this.$refs.upload.clearFiles();
|
||||
}
|
||||
this.isFileSelected = false;
|
||||
this.$emit("update:visible", false);
|
||||
},
|
||||
handleDownloadTemplate() {
|
||||
if (this.formData.importType === 'person') {
|
||||
this.download('ccdi/intermediary/importPersonTemplate', {}, `个人中介黑名单模板_${new Date().getTime()}.xlsx`);
|
||||
} else {
|
||||
this.download('ccdi/intermediary/importEntityTemplate', {}, `机构中介黑名单模板_${new Date().getTime()}.xlsx`);
|
||||
}
|
||||
this.download(
|
||||
this.sceneConfig.templatePath,
|
||||
{},
|
||||
`${this.sceneConfig.templateName}_${new Date().getTime()}.xlsx`
|
||||
);
|
||||
},
|
||||
handleFileUploadProgress() {
|
||||
this.isUploading = true;
|
||||
@@ -177,28 +191,30 @@ export default {
|
||||
const taskId = response.data.taskId;
|
||||
this.currentTaskId = taskId;
|
||||
|
||||
// 显示通知
|
||||
this.$notify({
|
||||
title: '导入任务已提交',
|
||||
message: '正在后台处理中,处理完成后将通知您',
|
||||
type: 'info',
|
||||
title: "导入任务已提交",
|
||||
message: "正在后台处理中,处理完成后将通知您",
|
||||
type: "info",
|
||||
duration: 3000
|
||||
});
|
||||
|
||||
// 关闭对话框 - 使用$emit更新父组件的visible
|
||||
this.$emit('update:visible', false);
|
||||
this.$refs.upload.clearFiles();
|
||||
this.$emit("task-created", {
|
||||
scene: this.scene,
|
||||
taskId,
|
||||
status: "PROCESSING"
|
||||
});
|
||||
this.$emit("update:visible", false);
|
||||
this.$emit("success", { scene: this.scene, taskId });
|
||||
|
||||
// 通知父组件刷新列表
|
||||
this.$emit("success");
|
||||
if (this.$refs.upload) {
|
||||
this.$refs.upload.clearFiles();
|
||||
}
|
||||
|
||||
// 开始轮询
|
||||
this.startImportStatusPolling(taskId);
|
||||
} else {
|
||||
this.$modal.msgError(response.msg || '导入失败');
|
||||
this.$modal.msgError(response.msg || "导入失败");
|
||||
}
|
||||
},
|
||||
// 导入结果弹窗关闭
|
||||
handleImportResultClose() {
|
||||
this.importResultVisible = false;
|
||||
this.importResultContent = "";
|
||||
@@ -206,77 +222,65 @@ export default {
|
||||
handleFileError() {
|
||||
this.isUploading = false;
|
||||
this.$modal.msgError("导入失败,请检查文件格式是否正确");
|
||||
this.$refs.upload.clearFiles();
|
||||
if (this.$refs.upload) {
|
||||
this.$refs.upload.clearFiles();
|
||||
}
|
||||
},
|
||||
handleSubmit() {
|
||||
// 触发清除历史记录事件
|
||||
this.$emit('clear-import-history', this.formData.importType);
|
||||
|
||||
// 提交文件上传
|
||||
this.$emit("clear-import-history", this.scene);
|
||||
this.$refs.upload.submit();
|
||||
},
|
||||
/** 开始轮询导入状态 */
|
||||
startImportStatusPolling(taskId) {
|
||||
let pollCount = 0;
|
||||
const maxPolls = 150; // 最多5分钟
|
||||
const maxPolls = 150;
|
||||
|
||||
this.pollingTimer = setInterval(async () => {
|
||||
try {
|
||||
pollCount++;
|
||||
|
||||
if (pollCount > maxPolls) {
|
||||
clearInterval(this.pollingTimer);
|
||||
this.$modal.msgWarning('导入任务处理超时,请联系管理员');
|
||||
this.$modal.msgWarning("导入任务处理超时,请联系管理员");
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据导入类型调用不同的API
|
||||
const apiMethod = this.formData.importType === 'person'
|
||||
? getPersonImportStatus
|
||||
: getEntityImportStatus;
|
||||
|
||||
const response = await apiMethod(taskId);
|
||||
|
||||
if (response.data && response.data.status !== 'PROCESSING') {
|
||||
const response = await this.sceneConfig.statusApi(taskId);
|
||||
if (response.data && response.data.status !== "PROCESSING") {
|
||||
clearInterval(this.pollingTimer);
|
||||
this.handleImportComplete(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clearInterval(this.pollingTimer);
|
||||
this.$modal.msgError('查询导入状态失败: ' + error.message);
|
||||
this.$modal.msgError("查询导入状态失败: " + error.message);
|
||||
}
|
||||
}, 2000); // 每2秒轮询一次
|
||||
}, 2000);
|
||||
},
|
||||
/** 处理导入完成 */
|
||||
handleImportComplete(statusResult) {
|
||||
if (statusResult.status === 'SUCCESS') {
|
||||
if (statusResult.status === "SUCCESS") {
|
||||
this.$notify({
|
||||
title: '导入完成',
|
||||
title: "导入完成",
|
||||
message: `全部成功!共导入${statusResult.totalCount}条数据`,
|
||||
type: 'success',
|
||||
type: "success",
|
||||
duration: 5000
|
||||
});
|
||||
} else if (statusResult.failureCount > 0) {
|
||||
this.$notify({
|
||||
title: '导入完成',
|
||||
title: "导入完成",
|
||||
message: `成功${statusResult.successCount}条,失败${statusResult.failureCount}条`,
|
||||
type: 'warning',
|
||||
type: "warning",
|
||||
duration: 5000
|
||||
});
|
||||
}
|
||||
|
||||
// 通知父组件更新失败记录状态
|
||||
this.$emit("import-complete", {
|
||||
scene: this.scene,
|
||||
taskId: statusResult.taskId,
|
||||
hasFailures: statusResult.failureCount > 0,
|
||||
importType: this.formData.importType,
|
||||
totalCount: statusResult.totalCount,
|
||||
successCount: statusResult.successCount,
|
||||
failureCount: statusResult.failureCount
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 组件销毁时清除定时器 */
|
||||
beforeDestroy() {
|
||||
if (this.pollingTimer) {
|
||||
clearInterval(this.pollingTimer);
|
||||
@@ -292,35 +296,6 @@ export default {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.el-radio-group {
|
||||
display: flex;
|
||||
|
||||
.el-radio {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
margin-right: 0;
|
||||
|
||||
&:first-child {
|
||||
.el-radio__label {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
.el-radio__label {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.is-bordered {
|
||||
padding: 10px 0;
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.el-upload {
|
||||
width: 100%;
|
||||
|
||||
@@ -355,6 +330,18 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
.scene-tips {
|
||||
padding: 12px 14px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 4px;
|
||||
color: #606266;
|
||||
line-height: 1.7;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
text-align: center;
|
||||
padding: 5px 0 0;
|
||||
|
||||
Reference in New Issue
Block a user