update 混入-导出、下载模板可以自定义后缀

This commit is contained in:
赵霄
2023-10-19 09:32:44 +08:00
parent dae16c9d93
commit 6a0fcc09f7
2 changed files with 11 additions and 10 deletions
+6 -5
View File
@@ -297,8 +297,9 @@ export const ConfigurableTableMixin = {
/** /**
* 导出 * 导出
* @param fileName * @param fileName
* @param fileSuffix
*/ */
handleExportXls (fileName) { handleExportXls (fileName, fileSuffix = '.xls') {
if (!fileName || typeof fileName !== 'string') { if (!fileName || typeof fileName !== 'string') {
fileName = '导出文件' fileName = '导出文件'
} }
@@ -323,13 +324,13 @@ export const ConfigurableTableMixin = {
return return
} }
if (typeof window.navigator.msSaveBlob !== 'undefined') { if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls') window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + fileSuffix)
} else { } else {
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' })) const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
const link = document.createElement('a') const link = document.createElement('a')
link.style.display = 'none' link.style.display = 'none'
link.href = url link.href = url
link.setAttribute('download', fileName + '.xls') link.setAttribute('download', fileName + fileSuffix)
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
document.body.removeChild(link) // 下载完成移除元素 document.body.removeChild(link) // 下载完成移除元素
@@ -373,11 +374,11 @@ export const ConfigurableTableMixin = {
}) })
}, },
// 下载导入模板 // 下载导入模板
downTemplate (fileName) { downTemplate (fileName, fileSuffix = '.xlsx') {
if (!fileName || typeof fileName !== 'string') { if (!fileName || typeof fileName !== 'string') {
fileName = '模板文件' fileName = '模板文件'
} }
downloadFile(this.url.downTemplateUrl, fileName + '.xlsx') downloadFile(this.url.downTemplateUrl, fileName + fileSuffix)
}, },
/** /**
* 批量删除 * 批量删除
+5 -5
View File
@@ -288,7 +288,7 @@ export const JeroListMixin = {
const paramsStr = encodeURI(JSON.stringify(this.getQueryParams())) const paramsStr = encodeURI(JSON.stringify(this.getQueryParams()))
window.location.href = `${window._CONFIG.domianURL}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}` window.location.href = `${window._CONFIG.domianURL}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}`
}, },
handleExportXls (fileName) { handleExportXls (fileName, fileSuffix = '.xlsx') {
if (!fileName || typeof fileName !== 'string') { if (!fileName || typeof fileName !== 'string') {
fileName = '导出文件' fileName = '导出文件'
} }
@@ -313,13 +313,13 @@ export const JeroListMixin = {
return return
} }
if (typeof window.navigator.msSaveBlob !== 'undefined') { if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx') window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + fileSuffix)
} else { } else {
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' })) const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
const link = document.createElement('a') const link = document.createElement('a')
link.style.display = 'none' link.style.display = 'none'
link.href = url link.href = url
link.setAttribute('download', fileName + '.xlsx') link.setAttribute('download', fileName + fileSuffix)
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
document.body.removeChild(link) // 下载完成移除元素 document.body.removeChild(link) // 下载完成移除元素
@@ -462,11 +462,11 @@ export const JeroListMixin = {
window.open(url) window.open(url)
}, },
// 下载导入模板 // 下载导入模板
downTemplate (fileName) { downTemplate (fileName, fileSuffix = '.xlsx') {
if (!fileName || typeof fileName !== 'string') { if (!fileName || typeof fileName !== 'string') {
fileName = '模板文件' fileName = '模板文件'
} }
downloadFile(this.url.downTemplateUrl, fileName + '.xlsx') downloadFile(this.url.downTemplateUrl, fileName + fileSuffix)
}, },
handleImportByFileId (fileId) { handleImportByFileId (fileId) {
// TODO 完善通过文件id上传文件的方法 // TODO 完善通过文件id上传文件的方法