Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jan 21, 2024
1 parent 4dced8f commit 013df11
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
29 changes: 4 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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' {
Expand All @@ -20,7 +20,7 @@ interface VXETablePluginExportPDFFonts {
}

interface VXETablePluginExportPDFOptions {
jspdf?: any
jsPDF?: any
fontName?: string;
fonts?: VXETablePluginExportPDFFonts[];
beforeMethod?: Function;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface VXETablePluginExportPDFFonts {
}

interface VXETablePluginExportPDFOptions {
jspdf?: any
jsPDF?: any
fontName?: string;
fonts?: VXETablePluginExportPDFFonts[];
beforeMethod?: Function;
Expand Down

0 comments on commit 013df11

Please sign in to comment.