UP scFileExport 增加异步导出 async

This commit is contained in:
sc 2022-06-13 17:12:11 +08:00
parent 6760f7b4ba
commit b523011860
3 changed files with 38 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -30,7 +30,8 @@
</el-form-item> </el-form-item>
<slot name="form" :formData="formData"></slot> <slot name="form" :formData="formData"></slot>
</el-form> </el-form>
<el-button type="primary" size="large" icon="el-icon-download" style="width: 100%;" @click="download"> </el-button> <el-button v-if="async" type="primary" size="large" icon="el-icon-plus" style="width: 100%;" @click="download" :loading="asyncLoading">发起导出任务</el-button>
<el-button v-else type="primary" size="large" icon="el-icon-download" style="width: 100%;" @click="download"> </el-button>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="列设置" v-if="columnData.length>0" lazy> <el-tab-pane label="列设置" v-if="columnData.length>0" lazy>
<columnSet :column="columnData"></columnSet> <columnSet :column="columnData"></columnSet>
@ -60,6 +61,7 @@
fileTypes: { type: Array, default: () => ['xlsx'] }, fileTypes: { type: Array, default: () => ['xlsx'] },
data: { type: Object, default: () => {} }, data: { type: Object, default: () => {} },
showData: { type: Boolean, default: false }, showData: { type: Boolean, default: false },
async: { type: Boolean, default: false },
column: { type: Array, default: () => [] }, column: { type: Array, default: () => [] },
blob: { type: Boolean, default: false }, blob: { type: Boolean, default: false },
progress: { type: Boolean, default: true } progress: { type: Boolean, default: true }
@ -73,7 +75,8 @@
}, },
columnData: [], columnData: [],
downLoading: false, downLoading: false,
downLoadProgress: 0 downLoadProgress: 0,
asyncLoading: false
} }
}, },
watch:{ watch:{
@ -105,7 +108,9 @@
column: this.columnData.filter(n => !n.hide).map(n => n.prop).join(",") column: this.columnData.filter(n => !n.hide).map(n => n.prop).join(",")
} }
let assignData = {...this.data, ...this.formData, ...columnArr} let assignData = {...this.data, ...this.formData, ...columnArr}
if(this.blob){ if(this.async){
this.asyncDownload(this.apiObj, this.formData.fileName, assignData)
}else if(this.blob){
this.downloadFile(this.apiObj, this.formData.fileName, assignData) this.downloadFile(this.apiObj, this.formData.fileName, assignData)
}else{ }else{
this.linkFile(this.apiObj.url, this.formData.fileName, assignData) this.linkFile(this.apiObj.url, this.formData.fileName, assignData)
@ -153,6 +158,30 @@
}) })
}) })
}, },
asyncDownload(apiObj, fileName, data={}){
this.asyncLoading = true
apiObj.get(data).then(res => {
this.asyncLoading = false
if(res.code == 200){
this.dialog = false
this.$msgbox({
title: "成功发起任务",
message: `<div><img style="height:200px" src="img/tasks-example.png"/></div><p>已成功发起导出任务,您可以操作其他事务</p><p>稍后可在 <b>任务中心</b> 查看执行结果</p>`,
type: "success",
confirmButtonText: "知道了",
dangerouslyUseHTMLString: true,
center: true
}).catch(() => {})
}else{
this.$alert(res.message || "未知错误", "发起任务失败", {
type: "error",
center: true
}).catch(() => {})
}
}).catch(() => {
this.asyncLoading = false
})
},
toQueryString(obj){ toQueryString(obj){
let arr = [] let arr = []
for (var k in obj) { for (var k in obj) {

View File

@ -40,6 +40,11 @@
<el-col :lg="12"> <el-col :lg="12">
<el-card shadow="never" header="导出"> <el-card shadow="never" header="导出">
<sc-file-export :apiObj="$API.common.exportFile"></sc-file-export> <sc-file-export :apiObj="$API.common.exportFile"></sc-file-export>
<sc-file-export :apiObj="$API.common.exportFile" fileName="人员列表(异步)" async>
<template #default="{open}">
<el-button type="primary" icon="sc-icon-download" @click="open">导出(异步)</el-button>
</template>
</sc-file-export>
<sc-file-export :apiObj="$API.common.exportFile" blob fileName="人员列表" :data="{otherData:'demo'}" showData :column="column" :fileTypes="['xlsx','docx','pdf']"> <sc-file-export :apiObj="$API.common.exportFile" blob fileName="人员列表" :data="{otherData:'demo'}" showData :column="column" :fileTypes="['xlsx','docx','pdf']">
<template #default="{open}"> <template #default="{open}">
<el-button type="primary" icon="sc-icon-download" @click="open">导出(blob文件流)</el-button> <el-button type="primary" icon="sc-icon-download" @click="open">导出(blob文件流)</el-button>
@ -60,6 +65,7 @@
<el-descriptions-item label="apiObj" :width="200">Object 文件导出接口对象通过apiObj.url请求文件</el-descriptions-item> <el-descriptions-item label="apiObj" :width="200">Object 文件导出接口对象通过apiObj.url请求文件</el-descriptions-item>
<el-descriptions-item label="data">Object 上传时附带的额外参数(可为数据表格的过滤项)</el-descriptions-item> <el-descriptions-item label="data">Object 上传时附带的额外参数(可为数据表格的过滤项)</el-descriptions-item>
<el-descriptions-item label="showData">Boolean 是否显示附带的额外参数</el-descriptions-item> <el-descriptions-item label="showData">Boolean 是否显示附带的额外参数</el-descriptions-item>
<el-descriptions-item label="async">Boolean 是否异步导出文件</el-descriptions-item>
<el-descriptions-item label="fileName">String 下载文件名称默认为当前时间戳</el-descriptions-item> <el-descriptions-item label="fileName">String 下载文件名称默认为当前时间戳</el-descriptions-item>
<el-descriptions-item label="fileTypes">Array 可选择文件类型默认为['xlsx']组件将数组第一项当做已选项</el-descriptions-item> <el-descriptions-item label="fileTypes">Array 可选择文件类型默认为['xlsx']组件将数组第一项当做已选项</el-descriptions-item>
<el-descriptions-item label="column">Array 列配置请求文件时将添加column为key的参数值为prop逗号","分割的字符串</el-descriptions-item> <el-descriptions-item label="column">Array 列配置请求文件时将添加column为key的参数值为prop逗号","分割的字符串</el-descriptions-item>