Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed May 29, 2020
1 parent e920365 commit 53b6c00
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ import VXETablePluginExportPDF from 'vxe-table-plugin-export-pdf'
VXETable.use(VXETablePluginExportPDF)
```

## Options

| 参数 | 描述 | 默认值 |
|------|------|------|
| fontName | 字体名称 | |
| fontStyle | 字体的样式 | normal |
| fontUrl | 字体库下载路径 | |
| beforeMethod | Function({ $pdf, options, columns, datas }) 导出之前触发回调,可以自行设置字体等相关样式 | |

## Font

| 字体名称 | 描述 |
|------|------|
| SourceHanSans-Bold | 思源雅黑-粗体 |

```javascript
// ...
import VXETablePluginExportPDF from 'vxe-table-plugin-export-pdf'
Expand Down
23 changes: 18 additions & 5 deletions dist/index.common.js

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
var colWidth = 0;
var msgKey = 'pdf';
var fontName = globalOptions.fontName,
fontUrl = globalOptions.fontUrl;
_globalOptions$fontSt = globalOptions.fontStyle,
fontStyle = _globalOptions$fontSt === void 0 ? 'normal' : _globalOptions$fontSt,
beforeMethod = globalOptions.beforeMethod;
var options = params.options,
columns = params.columns,
datas = params.datas;
Expand Down Expand Up @@ -104,9 +106,20 @@
orientation: 'landscape'
}); // 设置字体

if (fontName && fontUrl) {
doc.addFont(fontName + '.ttf', fontName, 'normal');
doc.setFont(fontName, 'normal');
if (fontName && globalFonts[fontName]) {
doc.addFont(fontName + '.ttf', fontName, fontStyle);
doc.setFont(fontName, fontStyle);
} // 导出之前


if (beforeMethod && beforeMethod({
$pdf: doc,
$table: $table,
options: options,
columns: columns,
datas: datas
}) === false) {
return;
} // 转换数据


Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getFooterCellValue ($table: Table, opts: ExportOptons, rows: any[], col
function exportPDF (params: InterceptorExportParams) {
let colWidth = 0
const msgKey = 'pdf'
const { fontName, fontUrl } = globalOptions
const { fontName, fontStyle = 'normal', beforeMethod } = globalOptions
const { options, columns, datas } = params
const showMsg = options.message !== false
const $table: any = params.$table
Expand Down Expand Up @@ -70,9 +70,13 @@ function exportPDF (params: InterceptorExportParams) {
/* eslint-disable new-cap */
const doc = new jsPDF({ putOnlyUsedFonts: true, orientation: 'landscape' })
// 设置字体
if (fontName && fontUrl) {
doc.addFont(fontName + '.ttf', fontName, 'normal')
doc.setFont(fontName, 'normal')
if (fontName && globalFonts[fontName]) {
doc.addFont(fontName + '.ttf', fontName, fontStyle)
doc.setFont(fontName, fontStyle)
}
// 导出之前
if (beforeMethod && beforeMethod({ $pdf: doc, $table, options, columns, datas }) === false) {
return
}
// 转换数据
doc.table(1, 1, rowList.concat(footList), headers, { printHeaders: isHeader, autoSize: false })
Expand Down Expand Up @@ -122,7 +126,9 @@ function handleExportEvent (params: InterceptorExportParams) {

interface VXETablePluginExportPDFOptions {
fontName?: 'SourceHanSans-Bold';
fontStyle?: 'normal';
fontUrl?: string;
beforeMethod?: Function;
}

function setup (options: VXETablePluginExportPDFOptions) {
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": "1.5.0",
"version": "1.5.5",
"description": "基于 vxe-table 表格的增强插件,支持导出 pdf 格式",
"scripts": {
"lib": "gulp build"
Expand Down

0 comments on commit 53b6c00

Please sign in to comment.