1
0
mirror of synced 2025-12-08 22:38:06 +08:00
This commit is contained in:
xuliangzhan
2020-10-22 15:34:14 +08:00
parent 9f524d9659
commit d4e88e3dfa
2 changed files with 15 additions and 9 deletions

View File

@@ -206,12 +206,13 @@ function checkImportData (tableFields: string[], fields: string[]) {
declare module 'vxe-table/lib/vxe-table' {
interface Table {
_importResolve?: Function | null;
_importReject?: Function | null;
}
}
function importXLSX (params: InterceptorImportParams) {
const { $table, columns, options, file } = params
const { $vxe, _importResolve } = $table
const { $vxe, _importResolve, _importReject } = $table
const { modal, t } = $vxe
const showMsg = options.message !== false
const fileReader = new FileReader()
@@ -238,11 +239,17 @@ function importXLSX (params: InterceptorImportParams) {
})
$table.createData(records)
.then((data: any[]) => {
if (options.mode === 'append') {
$table.insertAt(data, -1)
let loadRest: Promise<any>
if (options.mode === 'insert') {
loadRest = $table.insertAt(data, -1)
} else {
$table.reloadData(data)
loadRest = $table.reloadData(data)
}
return loadRest.then(() => {
if (_importResolve) {
_importResolve({ status: true })
}
})
})
if (showMsg) {
modal.message({ message: t('vxe.table.impSuccess', [records.length]), status: 'success' })
@@ -251,10 +258,9 @@ function importXLSX (params: InterceptorImportParams) {
if (showMsg) {
modal.message({ message: t('vxe.error.impFields'), status: 'error' })
}
if (_importReject) {
_importReject({ status: false })
}
if (_importResolve) {
_importResolve(status)
$table._importResolve = null
}
}
fileReader.readAsBinaryString(file)

View File

@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-export-xlsx",
"version": "2.0.2",
"version": "2.0.4",
"description": "基于 vxe-table 的表格插件,支持导出 xlsx 格式",
"scripts": {
"lib": "gulp build"