1
0
mirror of synced 2025-11-06 04:10:39 +08:00

重构v4版本

This commit is contained in:
xuliangzhan
2021-03-08 19:16:34 +08:00
parent 189363a9f4
commit 9e67c569a4
5 changed files with 28 additions and 28 deletions

View File

@@ -10,7 +10,7 @@
## Installing
```shell
npm install xe-utils vxe-table vxe-table-plugin-export-xlsx exceljs
npm install xe-utils vxe-table@next vxe-table-plugin-export-xlsx@next exceljs
```
```javascript

View File

@@ -29,7 +29,8 @@ gulp.task('build_commonjs', function () {
gulp.task('build_umd', function () {
return gulp.src(['depend.ts', 'index.ts'])
.pipe(ts(tsconfig.compilerOptions))
.pipe(replace(`import XEUtils from 'xe-utils/ctor';`, `import XEUtils from 'xe-utils';`))
.pipe(replace(`from 'xe-utils/ctor';`, `from 'xe-utils';`))
.pipe(replace(`from 'vxe-table/lib/vxe-table';`, `from 'vxe-table';`))
.pipe(babel({
moduleId: pack.name,
presets: [
@@ -39,6 +40,7 @@ gulp.task('build_umd', function () {
['@babel/transform-modules-umd', {
globals: {
[pack.name]: exportModuleName,
'vxe-table': 'VXETable',
'xe-utils': 'XEUtils',
'exceljs': 'ExcelJS'
},
@@ -46,7 +48,6 @@ gulp.task('build_umd', function () {
}]
]
}))
.pipe(replace(`global.${exportModuleName} = mod.exports;`, `global.${exportModuleName} = mod.exports.default;`))
.pipe(rename({
basename: 'index',
suffix: '.umd',

View File

@@ -1,13 +1,14 @@
import XEUtils from 'xe-utils/ctor'
import {
VXETableByVueProperty,
VXETableInstance,
VXETableCore,
VxeTableConstructor,
VxeTablePropTypes,
VxeTableDefines,
VxeGlobalInterceptorHandles
} from 'vxe-table/lib/vxe-table'
import * as ExcelJS from 'exceljs'
import ExcelJS from 'exceljs'
let vxetable:VXETableCore
declare module 'vxe-table/lib/vxe-table' {
namespace VxeTableDefines {
@@ -33,7 +34,7 @@ function getCellLabel (column: VxeTableDefines.ColumnInfo, cellValue: any) {
if (cellValue) {
switch (column.cellType) {
case 'string':
return XEUtils.toString(cellValue)
return XEUtils.toValueString(cellValue)
case 'number':
if (!isNaN(cellValue)) {
return Number(cellValue)
@@ -116,10 +117,9 @@ function getDefaultBorderStyle () {
function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams) {
const msgKey = 'xlsx'
const { $table, options, columns, colgroups, datas } = params
const { props, instance, reactData } = $table
const { props, reactData } = $table
const { headerAlign: allHeaderAlign, align: allAlign, footerAlign: allFooterAlign } = props
const { rowHeight } = reactData
const { modal, t } = instance.appContext.config.globalProperties.$vxe as VXETableByVueProperty
const { message, sheetName, isHeader, isFooter, isMerge, isColgroup, original, useStyle, sheetMethod } = options
const showMsg = message !== false
const mergeCells = $table.getMergeCells()
@@ -297,13 +297,13 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
// 导出 xlsx
downloadFile(params, blob, options)
if (showMsg) {
modal.close(msgKey)
modal.message({ message: t('vxe.table.expSuccess'), status: 'success' })
vxetable.modal.close(msgKey)
vxetable.modal.message({ message: vxetable.t('vxe.table.expSuccess'), status: 'success' })
}
})
}
if (showMsg) {
modal.message({ id: msgKey, message: t('vxe.table.expLoading'), status: 'loading', duration: -1 })
vxetable.modal.message({ id: msgKey, message: vxetable.t('vxe.table.expLoading'), status: 'loading', duration: -1 })
setTimeout(exportMethod, 1500)
} else {
exportMethod()
@@ -311,9 +311,6 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
}
function downloadFile (params: VxeGlobalInterceptorHandles.InterceptorExportParams, blob: Blob, options: VxeTablePropTypes.ExportConfig) {
const { $table } = params
const { instance } = $table
const { modal, t } = instance.appContext.config.globalProperties.$vxe as VXETableByVueProperty
const { message, filename, type } = options
const showMsg = message !== false
if (window.Blob) {
@@ -330,7 +327,7 @@ function downloadFile (params: VxeGlobalInterceptorHandles.InterceptorExportPara
}
} else {
if (showMsg) {
modal.alert({ message: t('vxe.error.notExp'), status: 'error' })
vxetable.modal.alert({ message: vxetable.t('vxe.error.notExp'), status: 'error' })
}
}
}
@@ -341,12 +338,11 @@ function checkImportData (tableFields: string[], fields: string[]) {
function importError (params: VxeGlobalInterceptorHandles.InterceptorImportParams) {
const { $table, options } = params
const { instance, internalData } = $table
const { internalData } = $table
const { _importReject } = internalData
const { modal, t } = instance.appContext.config.globalProperties.$vxe as VXETableByVueProperty
const showMsg = options.message !== false
if (showMsg) {
modal.message({ message: t('vxe.error.impFields'), status: 'error' })
vxetable.modal.message({ message: vxetable.t('vxe.error.impFields'), status: 'error' })
}
if (_importReject) {
_importReject({ status: false })
@@ -355,9 +351,8 @@ function importError (params: VxeGlobalInterceptorHandles.InterceptorImportParam
function importXLSX (params: VxeGlobalInterceptorHandles.InterceptorImportParams) {
const { $table, columns, options, file } = params
const { instance, internalData } = $table
const { internalData } = $table
const { _importResolve } = internalData
const { modal, t } = instance.appContext.config.globalProperties.$vxe as VXETableByVueProperty
const showMsg = options.message !== false
const fileReader = new FileReader()
fileReader.onerror = () => {
@@ -408,7 +403,7 @@ function importXLSX (params: VxeGlobalInterceptorHandles.InterceptorImportParams
})
})
if (showMsg) {
modal.message({ message: t('vxe.table.impSuccess', [records.length]), status: 'success' })
vxetable.modal.message({ message: vxetable.t('vxe.table.impSuccess', [records.length]), status: 'success' })
}
} else {
importError(params)
@@ -442,9 +437,12 @@ function handleExportEvent (params: VxeGlobalInterceptorHandles.InterceptorExpor
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 格式
*/
export const VXETablePluginExportXLSX = {
install (vxetable: VXETableInstance) {
const { interceptor } = vxetable
vxetable.setup({
install (vxetablecore: VXETableCore) {
const { setup, interceptor } = vxetablecore
vxetable = vxetablecore
setup({
export: {
types: {
xlsx: 0

View File

@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-export-xlsx",
"version": "3.0.0-beta.0",
"version": "3.0.0-beta.3",
"description": "基于 vxe-table 的表格插件,支持导出 xlsx 格式",
"scripts": {
"lib": "gulp build"
@@ -49,8 +49,8 @@
"prettier": "^2.1.2",
"typescript": "^4.0.5",
"vue": "^3.0.6",
"vxe-table": "^4.0.0-beta.15",
"xe-utils": "^3.1.8"
"vxe-table": "^4.0.0-beta.18",
"xe-utils": "^3.1.11"
},
"peerDependencies": {
"vxe-table": ">= 4"

View File

@@ -7,6 +7,7 @@
"strict": true,
"moduleResolution": "node",
"noImplicitAny": true,
"allowSyntheticDefaultImports": true,
"target": "esnext",
"lib": [
"esnext",