diff --git a/index.ts b/index.ts index 8363be1..8fc13a4 100644 --- a/index.ts +++ b/index.ts @@ -5,8 +5,8 @@ import jsPDF from 'jspdf' let vxetable: VXETableCore declare module 'vxe-table' { - namespace VxeTablePropTypes { - interface ExportConfig { + export namespace VxeTablePropTypes { + export interface ExportConfig { fontName?: string; } } @@ -174,23 +174,24 @@ function pluginSetup (options: VXETablePluginExportPDFOptions) { } /** - * 基于 vxe-table 表格的增强插件,支持导出 pdf 格式 + * 基于 vxe-table 表格的扩展插件,支持导出 pdf 格式 */ export const VXETablePluginExportPDF = { setup: pluginSetup, - install (vxetablecore: VXETableCore, options?: VXETablePluginExportPDFOptions) { - const { setup, interceptor } = vxetablecore - - vxetable = vxetablecore + install (vxetable: VXETableCore, options?: VXETablePluginExportPDFOptions) { + // 检查版本 + if (!/^(4)\./.test(vxetable.version)) { + console.error('[vxe-table-plugin-export-pdf] Version vxe-table 4.x is required') + } - setup({ + vxetable.setup({ export: { types: { pdf: 1 } } }) - interceptor.mixin({ + vxetable.interceptor.mixin({ 'event.export': handleExportEvent }) if (options) { diff --git a/package.json b/package.json index 7e4ada4..dcde6d9 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "vxe-table-plugin-export-pdf", - "version": "3.0.6", - "description": "基于 vxe-table 的表格插件,支持导出 pdf 格式", + "version": "3.1.0", + "description": "基于 vxe-table 表格的扩展插件,支持导出 pdf 格式", "scripts": { "lib": "gulp build" }, "files": [ + "types", "fonts/source-han-sans-bold.js", "fonts/source-han-sans-normal.js", "dist", @@ -16,7 +17,7 @@ "unpkg": "dist/index.umd.js", "jsdelivr": "dist/index.umd.js", "style": "dist/style.css", - "typings": "index.ts", + "typings": "types/index.d.ts", "devDependencies": { "@babel/core": "^7.12.3", "@babel/plugin-transform-runtime": "^7.12.1", @@ -52,11 +53,11 @@ "sass": "^1.55.0", "typescript": "^4.6.4", "vue": "^3.3.4", - "vxe-table": "^4.4.6", - "xe-utils": "^3.5.11" + "vxe-table": "^4.5.10", + "xe-utils": "^3.5.13" }, "peerDependencies": { - "vxe-table": "^4.0.27" + "vxe-table": "^4.5.0" }, "repository": { "type": "git", diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..276ccf9 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,22 @@ +import { VXETableCore } from 'vxe-table' + +interface VXETablePluginExportPDFFonts { + fontName: string; + fontStyle?: 'normal'; + fontUrl: string; +} + +interface VXETablePluginExportPDFOptions { + fontName?: string; + fonts?: VXETablePluginExportPDFFonts[]; + beforeMethod?: Function; +} + +/** + * 基于 vxe-table 表格的扩展插件,支持导出 pdf 格式 + */ +export declare const VXETablePluginExportPDF: { + install (vxetable: VXETableCore, options?: VXETablePluginExportPDFOptions): void +} + +export default VXETablePluginExportPDF