/**
* @description:导出当前页数据
* @param (row)dataxls请求接口携带的数据
*/
// 导出
async exportXls() {
const res = await materialExportAPI({ ...dataxls })
const resdata = res.data.path.slice(1)
const resPath = res.data.host + resdata
const link = document.createElement('a')
link.style.display = 'none'
link.href = resPath
link.download = res.data.fileName //下载的名称
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(resPath) // 释放掉blob对象
},
/**
* @description:预览文件
* @param (row)表格当前行数据 备注:download点击事件名字
*/
async function lookFile(file) {
const res= await attachmentPreviewApi(file.id)
window.open(res.data.url)
}
下载文件(所有的文件都可下载:包含pdf,word zip都可下载)
/**
* @description: 下载附件
* @param file点击项的id和name 备注:dowloadFileCli点击事件名字
*/
async function dowloadFileCli(file) {
const did = file.id; //点击项的id
const res = await dowloadFile(did); //请求接口
const url = window.URL.createObjectURL(new Blob([res]));
const link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', file.entrustName);//文件名称
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href); // 释放 URL对象
document.body.removeChild(link);
}
导出所有的数据
/**
* @description: xls导出所有的数据
* @param 备注:exportCli点击事件名字
*/
exportCli() {
this.$confirm('此操作将导出所有数据, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async() => {
const exportpage = JSON.parse(JSON.stringify(this.formPage)) // 分页
exportpage.size = -1
const res = await monitorDownloadExportApi.api({ ...exportpage, condition: this.condition }) // 调接口传参
console.log(res, '文件流')
const blob = new Blob([res], {
type: 'application/vnd.ms-excel;charset=UTF-8'
})
let link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.setAttribute(
'download',
`接口明细.xls`
)
link.click()
link = null
this.$notify({
title: '成功',
message: '导出成功',
type: 'success'
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消导出'
})
})
},
/** 导出按钮操作(地址直接下载) */
function exportCli(row) {
ElMessageBox.confirm('此操作将导出所有数据, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async() => {
const url = `${import.meta.env.VITE_APP_BASE_API}/activiti/modeler/export/${row.id}`
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(url) // 释放掉blob对象
proxy.$modal.msgSuccess("导出成功");
}).catch(() => {
ElMessage.error('导出失败');
})
}