diff --git a/README.md b/README.md index 8902b57..482cecb 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,15 @@ npm install vxe-table@next vxe-table-plugin-export-pdf@next jspdf // ... import VXETable from 'vxe-table' import VXETablePluginExportPDF from 'vxe-table-plugin-export-pdf' -import jspdf from 'jspdf' +import { jsPDF } from 'jspdf' // ... -// 方式1:NPM 安装,注入 jspdf 对象 +// 方式1:NPM 安装,注入 jsPDF 对象 VXETable.use(VXETablePluginExportPDF, { - jspdf + jsPDF }) -// 方式2:CDN 安装,只要确保 window.jspdf 存在即可 +// 方式2:CDN 安装,只要确保 window.jsPDF 存在即可 // VXETable.use(VXETablePluginExportPDF) ``` @@ -55,27 +55,6 @@ VXETable.use(VXETablePluginExportPDF, { | SourceHanSans-Bold | [source-han-sans-bold.js](https://github.com/x-extends/vxe-table-plugin-export-pdf/tree/master/fonts) | | SourceHanSans-Heavy | [source-han-sans-heavy.js](https://github.com/x-extends/vxe-table-plugin-export-pdf/tree/master/fonts) | -```javascript -// ... -import VXETable from 'vxe-table' -import VXETablePluginExportPDF from 'vxe-table-plugin-export-pdf' -// ... - -VXETable.use(VXETablePluginExportPDF, { - // Set default font - fontName: 'SourceHanSans-Normal', - // Font maps - fonts: [ - { - // Font name - fontName: 'SourceHanSans-Normal', - // Font library url - fontUrl: 'https://cdn.jsdelivr.net/npm/vxe-table-plugin-export-pdf/fonts/source-han-sans-normal.js' - } - ] -}) -``` - ## Demo ```html diff --git a/index.ts b/index.ts index 6230d02..4be8793 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,8 @@ import XEUtils from 'xe-utils' -import { VXETableCore, VxeTableConstructor, VxeTablePropTypes, VxeTableDefines, VxeGlobalInterceptorHandles } from 'vxe-table' +import type { VXETableCore, VxeTableConstructor, VxeTablePropTypes, VxeTableDefines, VxeGlobalInterceptorHandles } from 'vxe-table' import type jsPDF from 'jspdf' -let vxetable: VXETableCore +let globalVxetable: VXETableCore let globalJsPDF: any declare module 'vxe-table' { @@ -20,7 +20,7 @@ interface VXETablePluginExportPDFFonts { } interface VXETablePluginExportPDFOptions { - jspdf?: any + jsPDF?: any fontName?: string; fonts?: VXETablePluginExportPDFFonts[]; beforeMethod?: Function; @@ -44,7 +44,7 @@ function getFooterData (opts: VxeTablePropTypes.ExportConfig, footerData: any[][ } function exportPDF (params: VxeGlobalInterceptorHandles.InterceptorExportParams) { - const { modal, t } = vxetable + const { modal, t } = globalVxetable const { fonts, beforeMethod } = globalOptions const { $table, options, columns, datas } = params const { props } = $table @@ -107,7 +107,7 @@ function exportPDF (params: VxeGlobalInterceptorHandles.InterceptorExportParams) } const exportMethod = () => { /* eslint-disable new-cap */ - const doc: jsPDF = new (globalJsPDF || (window as any).jspdf)({ orientation: 'landscape' }) + const doc: jsPDF = new (globalJsPDF || ((window as any).jspdf ? (window as any).jspdf.jsPDF : (window as any).jsPDF))({ orientation: 'landscape' }) // 设置字体 doc.setFontSize(10) doc.internal.pageSize.width = pdfWidth @@ -191,7 +191,8 @@ export const VXETablePluginExportPDF = { console.error('[vxe-table-plugin-export-pdf] Version vxe-table 4.x is required') } - globalJsPDF = options ? options.jspdf : null + globalVxetable = vxetable + globalJsPDF = options ? options.jsPDF : null vxetable.config({ export: { diff --git a/package.json b/package.json index a81b7e2..5a3aa74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-table-plugin-export-pdf", - "version": "4.0.0", + "version": "4.0.1", "description": "基于 vxe-table 表格的扩展插件,支持导出 pdf 格式", "scripts": { "lib": "gulp build" diff --git a/types/index.d.ts b/types/index.d.ts index 4d15928..6896d9d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7,7 +7,7 @@ interface VXETablePluginExportPDFFonts { } interface VXETablePluginExportPDFOptions { - jspdf?: any + jsPDF?: any fontName?: string; fonts?: VXETablePluginExportPDFFonts[]; beforeMethod?: Function;