修改导入功能
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
<el-icon class="tip-icon"><Info-Filled /></el-icon>
|
||||
<div class="tip-text">
|
||||
仅允许上传 {{ accept }} 格式文件,文件大小不超过 {{ fileSizeMb }} MB。
|
||||
<el-link v-if="templateUrl" type="primary" underline="never" class="template-link" @click="handleDownloadTemplate">下载模板</el-link>
|
||||
<el-link v-if="hasTemplate" type="primary" underline="never" class="template-link" @click="handleDownloadTemplate">下载模板</el-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -97,12 +97,18 @@ const props = defineProps({
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
// 模板下载接口地址,不传则不显示下载模板链接
|
||||
// 模板下载接口地址(后端接口,走 proxy.download),不传则不显示下载模板链接
|
||||
templateAction: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
// 模板文件名前缀
|
||||
// 静态模板文件地址(public 目录下相对路径,如 /templates/product/xxx.xlsx),
|
||||
// 与 templateAction 二选一,静态地址优先
|
||||
templateUrl: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
// 模板下载文件名(不含扩展名;静态下载时为保存文件名,接口下载时为文件名前缀)
|
||||
templateFileName: {
|
||||
type: String,
|
||||
default: 'template'
|
||||
@@ -181,7 +187,7 @@ const uploadUrl = computed(() => {
|
||||
return import.meta.env.VITE_APP_BASE_API + props.action + '?' + query.toString()
|
||||
})
|
||||
|
||||
const templateUrl = computed(() => !!props.templateAction)
|
||||
const hasTemplate = computed(() => !!(props.templateUrl || props.templateAction))
|
||||
|
||||
// 打开对话框(供父组件通过 ref 调用)
|
||||
function open() {
|
||||
@@ -205,8 +211,17 @@ function handleClose() {
|
||||
uploadRef.value?.clearFiles()
|
||||
}
|
||||
|
||||
// 下载模板
|
||||
// 下载模板:静态文件直接 <a download>,接口走 proxy.download
|
||||
function handleDownloadTemplate() {
|
||||
if (props.templateUrl) {
|
||||
const link = document.createElement('a')
|
||||
link.href = props.templateUrl
|
||||
link.download = props.templateFileName + '.xlsx'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
return
|
||||
}
|
||||
proxy.download(props.templateAction, {}, `${props.templateFileName}_${new Date().getTime()}.xlsx`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user