重构产品价和红线价功能
This commit is contained in:
@@ -24,7 +24,10 @@
|
||||
<!-- 上传拖拽区 -->
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
:limit="1"
|
||||
:limit="fileLimit"
|
||||
:multiple="fileLimit > 1"
|
||||
:show-file-list="false"
|
||||
:on-exceed="handleExceed"
|
||||
:accept="accept"
|
||||
:headers="headers"
|
||||
:action="uploadUrl"
|
||||
@@ -40,16 +43,16 @@
|
||||
<div class="upload-placeholder">
|
||||
<el-icon class="upload-icon"><upload-filled /></el-icon>
|
||||
<div class="upload-title">点击或拖拽上传文件</div>
|
||||
<div class="upload-hint">支持 {{ accept }} 格式,单次最多导入 1 个文件,文件大小不超过 {{ fileSizeMb }} MB</div>
|
||||
<div class="upload-hint">支持 {{ accept }} 格式,单次最多导入 {{ fileLimit }} 个文件,文件大小不超过 {{ fileSizeMb }} MB</div>
|
||||
</div>
|
||||
</el-upload>
|
||||
|
||||
<!-- 已选文件 + 进度 -->
|
||||
<div v-if="selectedFile || isUploading" class="file-progress">
|
||||
<div v-if="selectedFile" class="selected-file">
|
||||
<div v-if="selectedFiles.length || isUploading" class="file-progress">
|
||||
<div v-for="(item, idx) in selectedFiles" :key="item.uid || item.name" class="selected-file">
|
||||
<el-icon class="file-icon"><Document /></el-icon>
|
||||
<span class="file-name" :title="selectedFile.name">{{ selectedFile.name }}</span>
|
||||
<el-icon v-if="!isUploading" class="file-remove" @click="handleClearFile"><CircleClose /></el-icon>
|
||||
<span class="file-name" :title="item.name">{{ item.name }}</span>
|
||||
<el-icon v-if="!isUploading" class="file-remove" @click="handleRemoveAt(idx)"><CircleClose /></el-icon>
|
||||
</div>
|
||||
<el-progress v-if="isUploading" :percentage="progressPercent" :stroke-width="6" :show-text="true" status="success" class="upload-progress" />
|
||||
</div>
|
||||
@@ -77,7 +80,7 @@
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" :disabled="!selectedFile || isUploading" :loading="isUploading" @click="handleSubmit">{{ submitText }}</el-button>
|
||||
<el-button type="primary" :disabled="!selectedFiles.length || isUploading" :loading="isUploading" @click="handleSubmit">{{ submitText }}</el-button>
|
||||
<el-button @click="visible = false" :disabled="isUploading">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -168,6 +171,10 @@ const props = defineProps({
|
||||
type: Number,
|
||||
default: 50
|
||||
},
|
||||
fileLimit: {
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
// 业务说明(字符串数组),显示在弹窗顶部 importDesc 段
|
||||
importDesc: {
|
||||
type: Array,
|
||||
@@ -202,7 +209,7 @@ const emit = defineEmits(['success'])
|
||||
|
||||
const uploadRef = ref(null)
|
||||
const visible = ref(false)
|
||||
const selectedFile = ref(null)
|
||||
const selectedFiles = ref([])
|
||||
const isUploading = ref(false)
|
||||
const updateSupport = ref(false)
|
||||
const progressPercent = ref(0)
|
||||
@@ -232,7 +239,7 @@ function open() {
|
||||
validateError.value = ''
|
||||
visible.value = true
|
||||
nextTick(() => {
|
||||
selectedFile.value = null
|
||||
selectedFiles.value = []
|
||||
})
|
||||
}
|
||||
|
||||
@@ -244,7 +251,7 @@ function handleClosed() {
|
||||
isUploading.value = false
|
||||
progressPercent.value = 0
|
||||
validateError.value = ''
|
||||
selectedFile.value = null
|
||||
selectedFiles.value = []
|
||||
}
|
||||
|
||||
// 下载模板:自定义 handler > 静态文件 > 接口 proxy.download
|
||||
@@ -295,30 +302,51 @@ function checkFile(file) {
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 文件选择处理 */
|
||||
function handleExceed() {
|
||||
validateError.value = '单次最多导入 ' + props.fileLimit + ' 个文件'
|
||||
}
|
||||
|
||||
function syncSelectedFiles(fileList) {
|
||||
const list = Array.isArray(fileList) ? fileList : []
|
||||
selectedFiles.value = list.slice(0, props.fileLimit)
|
||||
}
|
||||
|
||||
const handleFileChange = (file, fileList) => {
|
||||
progressPercent.value = 0
|
||||
const err = checkFile(file)
|
||||
if (err) {
|
||||
validateError.value = err
|
||||
selectedFile.value = null
|
||||
safeClearFiles()
|
||||
const rest = (fileList || []).filter(f => f && f.uid !== file.uid)
|
||||
syncSelectedFiles(rest)
|
||||
const inst = uploadRef.value
|
||||
if (inst && typeof inst.handleRemove === 'function') {
|
||||
try { inst.handleRemove(file) } catch (e) { /* ignore */ }
|
||||
}
|
||||
return
|
||||
}
|
||||
validateError.value = ''
|
||||
selectedFile.value = file
|
||||
syncSelectedFiles(fileList)
|
||||
}
|
||||
|
||||
/** 文件删除处理 */
|
||||
const handleFileRemove = (file, fileList) => {
|
||||
selectedFile.value = null
|
||||
syncSelectedFiles(fileList)
|
||||
progressPercent.value = 0
|
||||
validateError.value = ''
|
||||
}
|
||||
|
||||
/** 手动清除已选文件 */
|
||||
function handleRemoveAt(idx) {
|
||||
const file = selectedFiles.value[idx]
|
||||
if (!file) return
|
||||
const inst = uploadRef.value
|
||||
if (inst && typeof inst.handleRemove === 'function') {
|
||||
try { inst.handleRemove(file) } catch (e) { /* ignore */ }
|
||||
}
|
||||
selectedFiles.value = selectedFiles.value.filter((_, i) => i !== idx)
|
||||
validateError.value = ''
|
||||
}
|
||||
|
||||
function handleClearFile() {
|
||||
selectedFile.value = null
|
||||
selectedFiles.value = []
|
||||
validateError.value = ''
|
||||
safeClearFiles()
|
||||
}
|
||||
@@ -328,7 +356,7 @@ function handleSuccess(response) {
|
||||
isUploading.value = false
|
||||
progressPercent.value = 0
|
||||
validateError.value = ''
|
||||
selectedFile.value = null
|
||||
selectedFiles.value = []
|
||||
visible.value = false
|
||||
proxy.$modal.msgSuccess(plainText(response && response.msg))
|
||||
emit('success')
|
||||
@@ -343,19 +371,26 @@ async function handleSubmit() {
|
||||
return
|
||||
}
|
||||
}
|
||||
const file = selectedFile.value
|
||||
const err = checkFile(file)
|
||||
if (err) {
|
||||
proxy.$modal.msgError(err)
|
||||
const files = selectedFiles.value.slice()
|
||||
if (!files.length) {
|
||||
proxy.$modal.msgError('请先选择文件')
|
||||
return
|
||||
}
|
||||
for (const item of files) {
|
||||
const err = checkFile(item)
|
||||
if (err) {
|
||||
proxy.$modal.msgError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (typeof props.submitHandler === 'function') {
|
||||
isUploading.value = true
|
||||
progressPercent.value = 0
|
||||
try {
|
||||
const resultMsg = await props.submitHandler(file)
|
||||
const arg = props.fileLimit > 1 ? files : files[0]
|
||||
const resultMsg = await props.submitHandler(arg)
|
||||
validateError.value = ''
|
||||
selectedFile.value = null
|
||||
selectedFiles.value = []
|
||||
visible.value = false
|
||||
proxy.$modal.msgSuccess(plainText(resultMsg))
|
||||
emit('success')
|
||||
@@ -371,7 +406,12 @@ async function handleSubmit() {
|
||||
uploadRef.value?.submit?.()
|
||||
}
|
||||
|
||||
defineExpose({ open, close })
|
||||
function setProgress(percent) {
|
||||
const n = Number(percent)
|
||||
if (!Number.isNaN(n)) progressPercent.value = Math.min(100, Math.max(0, Math.round(n)))
|
||||
}
|
||||
|
||||
defineExpose({ open, close, setProgress })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user