Skip to content

Commit

Permalink
update ts
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Sep 1, 2020
1 parent 0f73721 commit 432b89c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 53 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pack = require('./package.json')
const exportModuleName = 'VXETablePluginExportPDF'

gulp.task('build_commonjs', function () {
return gulp.src(['index.d.ts', 'depend.ts', 'index.ts'])
return gulp.src(['depend.ts', 'index.ts'])
.pipe(sourcemaps.init())
.pipe(ts({
strict: true,
Expand All @@ -32,7 +32,7 @@ gulp.task('build_commonjs', function () {
})

gulp.task('build_umd', function () {
return gulp.src(['index.d.ts', 'depend.ts', 'index.ts'])
return gulp.src(['depend.ts', 'index.ts'])
.pipe(ts({
strict: true,
moduleResolution: 'node',
Expand Down
23 changes: 0 additions & 23 deletions index.d.ts

This file was deleted.

53 changes: 31 additions & 22 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import jsPDF from 'jspdf'
const isWin = typeof window !== 'undefined'
const globalOptions: VXETablePluginExportPDFOptions = {}
const globalFonts: { [key: string]: any } = {}
let _vxetable: typeof VXETable

function getCellText (cellValue: any) {
return cellValue || ' '
Expand All @@ -24,21 +23,26 @@ function getFooterCellValue ($table: Table, opts: ExportOptons, rows: any[], col
return getCellText(cellValue)
}

function getFooterData (opts: ExportOptons, footerData: any[][]) {
const { footerFilterMethod } = opts
return footerFilterMethod ? footerData.filter((items, index) => footerFilterMethod({ items, $rowIndex: index })) : footerData
}

function exportPDF (params: InterceptorExportParams) {
const { fonts, beforeMethod } = globalOptions
const { $table, options, columns, datas } = params
const { $vxe, treeConfig, treeOpts } = $table
const { modal, t } = $vxe
const dX = 7
const dY = 15.8
const ratio = 3.78
const pdfWidth = 210
let colWidth = 0
const msgKey = 'pdf'
const { fonts, beforeMethod } = globalOptions
const { options, columns, datas } = params
const showMsg = options.message !== false
const $table: any = params.$table
const { treeConfig, treeOpts } = $table
const { type, filename, isHeader, isFooter, original, footerFilterMethod } = options
const { type, filename, isHeader, isFooter, original } = options
const footList: { [key: string]: any }[] = []
const headers: { [key: string]: any }[] = columns.map((column) => {
const headers: any[] = columns.map((column) => {
const title = XEUtils.toString(original ? column.property : column.getTitle())
const width = column.renderWidth / ratio
colWidth += width
Expand All @@ -61,8 +65,8 @@ function exportPDF (params: InterceptorExportParams) {
})
if (isFooter) {
const { footerData } = $table.getTableData()
const footers = footerFilterMethod ? footerData.filter(footerFilterMethod) : footerData
footers.forEach((rows: any[]) => {
const footers = getFooterData(options, footerData)
footers.forEach(rows => {
const item: { [key: string]: any } = {}
columns.forEach((column) => {
item[column.id] = getFooterCellValue($table, options, rows, column)
Expand All @@ -77,10 +81,10 @@ function exportPDF (params: InterceptorExportParams) {
}
const exportMethod = () => {
/* eslint-disable new-cap */
const doc = new jsPDF({ putOnlyUsedFonts: true, orientation: 'landscape' })
const doc = new jsPDF({ orientation: 'landscape' })
// 设置字体
doc.setFontSize(10)
doc.internal.pageSize.setWidth(pdfWidth)
doc.internal.pageSize.width = pdfWidth
if (fontConf) {
const { fontName, fontStyle = 'normal' } = fontConf
if (globalFonts[fontName]) {
Expand All @@ -105,12 +109,12 @@ function exportPDF (params: InterceptorExportParams) {
// 导出 pdf
doc.save(`${filename}.${type}`)
if (showMsg) {
_vxetable.modal.close(msgKey)
_vxetable.modal.message({ message: _vxetable.t('vxe.table.expSuccess'), status: 'success' })
modal.close(msgKey)
modal.message({ message: t('vxe.table.expSuccess'), status: 'success' })
}
}
if (showMsg) {
_vxetable.modal.message({ id: msgKey, message: _vxetable.t('vxe.table.expLoading'), status: 'loading', duration: -1 })
modal.message({ id: msgKey, message: t('vxe.table.expLoading'), status: 'loading', duration: -1 })
}
checkFont(fontConf).then(() => {
if (showMsg) {
Expand Down Expand Up @@ -158,6 +162,13 @@ interface VXETablePluginExportPDFOptions {
beforeMethod?: Function;
}

declare global {
interface Window {
jspdf: any;
jsPDF: any;
}
}

function setup (options: VXETablePluginExportPDFOptions) {
const { fonts } = Object.assign(globalOptions, options)
if (fonts) {
Expand All @@ -169,10 +180,9 @@ function setup (options: VXETablePluginExportPDFOptions) {
}
}

declare global {
interface Window {
jspdf: any;
jsPDF: any;
declare module 'vxe-table/lib/vxe-table' {
interface VXETableTypes {
pdf: number;
}
}

Expand All @@ -181,10 +191,9 @@ declare global {
*/
export const VXETablePluginExportPDF = {
setup,
install (xtable: typeof VXETable, options?: VXETablePluginExportPDFOptions) {
const { interceptor } = xtable
_vxetable = xtable
Object.assign(xtable.types, { pdf: 0 })
install (vxetable: typeof VXETable, options?: VXETablePluginExportPDFOptions) {
const { interceptor } = vxetable
vxetable.types.pdf = 0
interceptor.mixin({
'event.export': handleExportEvent
})
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-export-pdf",
"version": "1.8.5",
"version": "1.8.6",
"description": "基于 vxe-table 表格的增强插件,支持导出 pdf 格式",
"scripts": {
"lib": "gulp build"
Expand Down Expand Up @@ -46,17 +46,17 @@
"gulp-sourcemaps": "^2.6.5",
"gulp-typescript": "^5.0.1",
"gulp-uglify": "^3.0.2",
"jspdf": "^2.1.0",
"markdown-doctest": "^0.9.1",
"prettier": "^1.18.2",
"typescript": "^3.9.3",
"vue": "^2.6.11",
"vxe-table": "^2.9.18",
"xe-utils": "^2.7.8",
"jspdf": "^1.5.3"
"vxe-table": "^2.9.19",
"xe-utils": "^2.7.8"
},
"peerDependencies": {
"vxe-table": ">= 2.9.0",
"jspdf": ">= 1.5.0"
"jspdf": ">= 2.1.0"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"files": [
"index.d.ts",
"index.ts",
"depend.ts"
],
Expand Down

0 comments on commit 432b89c

Please sign in to comment.