From a930043736d6455b7e615af52172204cf4df9049 Mon Sep 17 00:00:00 2001 From: xuliangzhan Date: Mon, 12 Apr 2021 15:30:36 +0800 Subject: [PATCH] optimize --- index.ts | 26 +++++++++++++++----------- package.json | 8 ++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/index.ts b/index.ts index aea0446..6a692d0 100644 --- a/index.ts +++ b/index.ts @@ -110,6 +110,7 @@ function getDefaultBorderStyle () { function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams) { const msgKey = 'xlsx' + const { modal, t} = vxetable const { $table, options, columns, colgroups, datas } = params const { props, reactData } = $table const { headerAlign: allHeaderAlign, align: allAlign, footerAlign: allFooterAlign } = props @@ -290,14 +291,14 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams var blob = new Blob([buffer], { type: 'application/octet-stream' }) // 导出 xlsx downloadFile(params, blob, options) - if (showMsg) { - vxetable.modal.close(msgKey) - vxetable.modal.message({ message: vxetable.t('vxe.table.expSuccess'), status: 'success' }) + if (showMsg && modal) { + modal.close(msgKey) + modal.message({ content: t('vxe.table.expSuccess'), status: 'success' }) } }) } - if (showMsg) { - vxetable.modal.message({ id: msgKey, message: vxetable.t('vxe.table.expLoading'), status: 'loading', duration: -1 }) + if (showMsg && modal) { + modal.message({ id: msgKey, content: t('vxe.table.expLoading'), status: 'loading', duration: -1 }) setTimeout(exportMethod, 1500) } else { exportMethod() @@ -305,6 +306,7 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams } function downloadFile (params: VxeGlobalInterceptorHandles.InterceptorExportParams, blob: Blob, options: VxeTablePropTypes.ExportConfig) { + const { modal, t } = vxetable const { message, filename, type } = options const showMsg = message !== false if (window.Blob) { @@ -320,8 +322,8 @@ function downloadFile (params: VxeGlobalInterceptorHandles.InterceptorExportPara document.body.removeChild(linkElem) } } else { - if (showMsg) { - vxetable.modal.alert({ message: vxetable.t('vxe.error.notExp'), status: 'error' }) + if (showMsg && modal) { + modal.alert({ content: t('vxe.error.notExp'), status: 'error' }) } } } @@ -331,12 +333,13 @@ function checkImportData (tableFields: string[], fields: string[]) { } function importError (params: VxeGlobalInterceptorHandles.InterceptorImportParams) { + const { modal, t } = vxetable const { $table, options } = params const { internalData } = $table const { _importReject } = internalData const showMsg = options.message !== false - if (showMsg) { - vxetable.modal.message({ message: vxetable.t('vxe.error.impFields'), status: 'error' }) + if (showMsg && modal) { + modal.message({ content: t('vxe.error.impFields'), status: 'error' }) } if (_importReject) { _importReject({ status: false }) @@ -344,6 +347,7 @@ function importError (params: VxeGlobalInterceptorHandles.InterceptorImportParam } function importXLSX (params: VxeGlobalInterceptorHandles.InterceptorImportParams) { + const { modal, t } = vxetable const { $table, columns, options, file } = params const { internalData } = $table const { _importResolve } = internalData @@ -396,8 +400,8 @@ function importXLSX (params: VxeGlobalInterceptorHandles.InterceptorImportParams } }) }) - if (showMsg) { - vxetable.modal.message({ message: vxetable.t('vxe.table.impSuccess', [records.length]), status: 'success' }) + if (showMsg && modal) { + modal.message({ content: t('vxe.table.impSuccess', [records.length]), status: 'success' }) } } else { importError(params) diff --git a/package.json b/package.json index e1a854a..81d5bea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-table-plugin-export-xlsx", - "version": "3.0.1", + "version": "3.0.2", "description": "基于 vxe-table 的表格插件,支持导出 xlsx 格式", "scripts": { "lib": "gulp build" @@ -49,11 +49,11 @@ "prettier": "^2.1.2", "typescript": "^4.0.5", "vue": "^3.0.6", - "vxe-table": "^4.0.5", - "xe-utils": "^3.1.11" + "vxe-table": "^4.0.10", + "xe-utils": "^3.1.13" }, "peerDependencies": { - "vxe-table": "^4.0.0" + "vxe-table": "^4.0.10" }, "repository": { "type": "git",