修改套餐导入功能

This commit is contained in:
wuweihua
2026-10-10 11:16:03 +08:00
parent 9d7218795a
commit fab2ec7d9c
12 changed files with 578 additions and 127 deletions
@@ -1,5 +1,13 @@
<template>
<el-dialog :title="title" v-model="visible" :width="width" append-to-body @close="handleClose" class="excel-import-dialog">
<el-dialog
:title="title"
v-model="visible"
:width="width"
append-to-body
destroy-on-close
@closed="handleClosed"
class="excel-import-dialog"
>
<div class="import-body">
<!-- 业务说明(可选) -->
<div v-if="importDesc.length" class="import-desc">
@@ -81,6 +89,23 @@ import { getToken } from '@/utils/auth'
const { proxy } = getCurrentInstance()
function plainText(msg) {
if (msg == null || msg === '') return '导入完成'
return String(msg).replace(/<br\s*\/?>/gi, '\n').replace(/<[^>]+>/g, '')
}
/** Do not call el-upload.clearFiles while the dialog is hiding: EP sets inputRef.value.value = ''. */
function safeClearFiles() {
if (!visible.value) return
const inst = uploadRef.value
if (!inst || typeof inst.clearFiles !== 'function') return
try {
inst.clearFiles()
} catch (e) {
/* ignore */
}
}
const props = defineProps({
// 对话框标题
title: {
@@ -203,17 +228,14 @@ function open() {
visible.value = true
nextTick(() => {
selectedFile.value = null
uploadRef.value?.clearFiles()
})
}
// 关闭时清理
function handleClose() {
function handleClosed() {
isUploading.value = false
progressPercent.value = 0
validateError.value = ''
selectedFile.value = null
uploadRef.value?.clearFiles()
}
// 下载模板:静态文件直接 <a download>,接口走 proxy.download
@@ -262,7 +284,7 @@ const handleFileChange = (file, fileList) => {
if (err) {
validateError.value = err
selectedFile.value = null
nextTick(() => uploadRef.value?.clearFiles())
safeClearFiles()
return
}
validateError.value = ''
@@ -280,18 +302,17 @@ const handleFileRemove = (file, fileList) => {
function handleClearFile() {
selectedFile.value = null
validateError.value = ''
uploadRef.value?.clearFiles()
safeClearFiles()
}
// 上传成功
function handleSuccess(response) {
visible.value = false
isUploading.value = false
progressPercent.value = 0
validateError.value = ''
selectedFile.value = null
uploadRef.value?.clearFiles()
proxy.$alert("<div style='overflow:auto;overflow-x:hidden;max-height:70vh;padding:10px 20px 0;'>" + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
visible.value = false
proxy.$modal.msgSuccess(plainText(response && response.msg))
emit('success')
}
@@ -315,25 +336,21 @@ async function handleSubmit() {
progressPercent.value = 0
try {
const resultMsg = await props.submitHandler(file)
visible.value = false
validateError.value = ''
selectedFile.value = null
uploadRef.value?.clearFiles()
const html = resultMsg == null || resultMsg === ''
? '导入完成'
: String(resultMsg)
proxy.$alert("<div style='overflow:auto;overflow-x:hidden;max-height:70vh;padding:10px 20px 0;'>" + html + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
visible.value = false
proxy.$modal.msgSuccess(plainText(resultMsg))
emit('success')
} catch (e) {
const tip = (e && e.message) ? e.message : '导入失败'
proxy.$modal.msgError(tip)
proxy.$modal.msgError(plainText(tip) || '导入失败')
} finally {
isUploading.value = false
progressPercent.value = 0
}
return
}
uploadRef.value.submit()
uploadRef.value?.submit?.()
}
defineExpose({ open })