vxe-table 3.12.10-beta.21 → 3.12.10-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/style.css +1 -1
- package/es/table/module/export/mixin.js +50 -37
- package/es/ui/index.js +1 -1
- package/es/ui/src/log.js +1 -1
- package/lib/index.umd.js +55 -39
- package/lib/index.umd.min.js +1 -1
- package/lib/style.css +1 -1
- package/lib/table/module/export/mixin.js +53 -37
- package/lib/table/module/export/mixin.min.js +1 -1
- package/lib/ui/index.js +1 -1
- package/lib/ui/index.min.js +1 -1
- package/lib/ui/src/log.js +1 -1
- package/lib/ui/src/log.min.js +1 -1
- package/package.json +1 -1
- package/packages/table/module/export/mixin.ts +88 -53
- /package/es/{iconfont.1737182271148.ttf → iconfont.1737185512944.ttf} +0 -0
- /package/es/{iconfont.1737182271148.woff → iconfont.1737185512944.woff} +0 -0
- /package/es/{iconfont.1737182271148.woff2 → iconfont.1737185512944.woff2} +0 -0
- /package/lib/{iconfont.1737182271148.ttf → iconfont.1737185512944.ttf} +0 -0
- /package/lib/{iconfont.1737182271148.woff → iconfont.1737185512944.woff} +0 -0
- /package/lib/{iconfont.1737182271148.woff2 → iconfont.1737185512944.woff2} +0 -0
|
@@ -5,7 +5,7 @@ import { parseFile, formatText, eqEmptyValue } from '../../../ui/src/utils'
|
|
|
5
5
|
import { createHtmlPage, getExportBlobByContent } from './util'
|
|
6
6
|
import { warnLog, errLog } from '../../../ui/src/log'
|
|
7
7
|
|
|
8
|
-
import type { VxeTablePropTypes, VxeGridConstructor, VxeTableDefines, TableReactData, TableInternalData, GridReactData, VxeColumnPropTypes, VxeTableConstructor } from '../../../../types'
|
|
8
|
+
import type { VxeTablePropTypes, VxeGridConstructor, VxeTableDefines, TableReactData, VxeTablePrivateMethods, TableInternalData, GridReactData, VxeColumnPropTypes, VxeTableConstructor } from '../../../../types'
|
|
9
9
|
|
|
10
10
|
const { getI18n, renderer } = VxeUI
|
|
11
11
|
|
|
@@ -643,7 +643,7 @@ function handleExport ($xeTable: any, opts: VxeTablePropTypes.ExportHandleOption
|
|
|
643
643
|
}
|
|
644
644
|
|
|
645
645
|
function getElementsByTagName (elem: any, qualifiedName: any) {
|
|
646
|
-
return elem.getElementsByTagName(qualifiedName)
|
|
646
|
+
return elem.getElementsByTagName(qualifiedName) as HTMLElement[]
|
|
647
647
|
}
|
|
648
648
|
|
|
649
649
|
function getTxtCellKey (now: any) {
|
|
@@ -659,32 +659,50 @@ function getTxtCellValue (val: any, vMaps: any) {
|
|
|
659
659
|
return rest.replace(/^"+$/g, (qVal: any) => '"'.repeat(Math.ceil(qVal.length / 2)))
|
|
660
660
|
}
|
|
661
661
|
|
|
662
|
-
function
|
|
662
|
+
function toExportField (tableConf: {
|
|
663
|
+
fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
664
|
+
titleMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
665
|
+
}, field: string) {
|
|
666
|
+
const { fieldMaps, titleMaps } = tableConf
|
|
667
|
+
// title 转 field
|
|
668
|
+
if (!fieldMaps[field]) {
|
|
669
|
+
const teCol = titleMaps[field]
|
|
670
|
+
if (teCol && teCol.field) {
|
|
671
|
+
field = teCol.field
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return field
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function parseCsvAndTxt (tableConf: {
|
|
678
|
+
fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
679
|
+
titleMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
680
|
+
}, content: string, cellSeparator: string) {
|
|
663
681
|
const list = content.split(enterSymbol)
|
|
664
682
|
const rows: any[] = []
|
|
665
|
-
let fields
|
|
683
|
+
let fields: string[] = []
|
|
666
684
|
if (list.length) {
|
|
667
685
|
const vMaps: any = {}
|
|
668
686
|
const now = Date.now()
|
|
669
|
-
list.forEach((rVal
|
|
687
|
+
list.forEach((rVal) => {
|
|
670
688
|
if (rVal) {
|
|
671
689
|
const item: any = {}
|
|
672
|
-
rVal = rVal.replace(/("")|(\n)/g, (text:
|
|
690
|
+
rVal = rVal.replace(/("")|(\n)/g, (text: string, dVal: string) => {
|
|
673
691
|
const key = getTxtCellKey(now)
|
|
674
692
|
vMaps[key] = dVal ? '"' : '\n'
|
|
675
693
|
return key
|
|
676
|
-
}).replace(/"(.*?)"/g, (text:
|
|
694
|
+
}).replace(/"(.*?)"/g, (text: string, cVal: string) => {
|
|
677
695
|
const key = getTxtCellKey(now)
|
|
678
696
|
vMaps[key] = replaceTxtCell(cVal, vMaps)
|
|
679
697
|
return key
|
|
680
698
|
})
|
|
681
|
-
const cells = rVal.split(cellSeparator)
|
|
699
|
+
const cells: string[] = rVal.split(cellSeparator)
|
|
682
700
|
if (!fields.length) {
|
|
683
|
-
fields = cells.map((val:
|
|
701
|
+
fields = cells.map((val: string) => toExportField(tableConf, getTxtCellValue(val.trim(), vMaps)))
|
|
684
702
|
} else {
|
|
685
|
-
cells.forEach((val
|
|
703
|
+
cells.forEach((val, colIndex) => {
|
|
686
704
|
if (colIndex < fields.length) {
|
|
687
|
-
item[fields[colIndex]] = getTxtCellValue(val, vMaps)
|
|
705
|
+
item[fields[colIndex]] = getTxtCellValue(val.trim(), vMaps)
|
|
688
706
|
}
|
|
689
707
|
})
|
|
690
708
|
rows.push(item)
|
|
@@ -695,35 +713,44 @@ function parseCsvAndTxt (columns: any, content: any, cellSeparator: any) {
|
|
|
695
713
|
return { fields, rows }
|
|
696
714
|
}
|
|
697
715
|
|
|
698
|
-
function parseCsv (
|
|
699
|
-
|
|
716
|
+
function parseCsv (tableConf: {
|
|
717
|
+
fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
718
|
+
titleMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
719
|
+
}, content: string) {
|
|
720
|
+
return parseCsvAndTxt(tableConf, content, ',')
|
|
700
721
|
}
|
|
701
722
|
|
|
702
|
-
function parseTxt (
|
|
703
|
-
|
|
723
|
+
function parseTxt (tableConf: {
|
|
724
|
+
fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
725
|
+
titleMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
726
|
+
}, content: string) {
|
|
727
|
+
return parseCsvAndTxt(tableConf, content, '\t')
|
|
704
728
|
}
|
|
705
729
|
|
|
706
|
-
function parseHTML (
|
|
730
|
+
function parseHTML (tableConf: {
|
|
731
|
+
fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
732
|
+
titleMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
733
|
+
}, content: string) {
|
|
707
734
|
const domParser = new DOMParser()
|
|
708
735
|
const xmlDoc = domParser.parseFromString(content, 'text/html')
|
|
709
736
|
const bodyNodes = getElementsByTagName(xmlDoc, 'body')
|
|
710
|
-
const rows
|
|
711
|
-
const fields:
|
|
737
|
+
const rows: any[] = []
|
|
738
|
+
const fields: string[] = []
|
|
712
739
|
if (bodyNodes.length) {
|
|
713
740
|
const tableNodes = getElementsByTagName(bodyNodes[0], 'table')
|
|
714
741
|
if (tableNodes.length) {
|
|
715
742
|
const theadNodes = getElementsByTagName(tableNodes[0], 'thead')
|
|
716
743
|
if (theadNodes.length) {
|
|
717
|
-
XEUtils.arrayEach(getElementsByTagName(theadNodes[0], 'tr'),
|
|
718
|
-
XEUtils.arrayEach(getElementsByTagName(rowNode, 'th'),
|
|
719
|
-
fields.push(cellNode.textContent)
|
|
744
|
+
XEUtils.arrayEach(getElementsByTagName(theadNodes[0], 'tr'), rowNode => {
|
|
745
|
+
XEUtils.arrayEach(getElementsByTagName(rowNode, 'th'), cellNode => {
|
|
746
|
+
fields.push(toExportField(tableConf, cellNode.textContent || ''))
|
|
720
747
|
})
|
|
721
748
|
})
|
|
722
749
|
const tbodyNodes = getElementsByTagName(tableNodes[0], 'tbody')
|
|
723
750
|
if (tbodyNodes.length) {
|
|
724
751
|
XEUtils.arrayEach(getElementsByTagName(tbodyNodes[0], 'tr'), rowNode => {
|
|
725
|
-
const item
|
|
726
|
-
XEUtils.arrayEach(getElementsByTagName(rowNode, 'td'), (cellNode
|
|
752
|
+
const item: any = {}
|
|
753
|
+
XEUtils.arrayEach(getElementsByTagName(rowNode, 'td'), (cellNode, colIndex) => {
|
|
727
754
|
if (fields[colIndex]) {
|
|
728
755
|
item[fields[colIndex]] = cellNode.textContent || ''
|
|
729
756
|
}
|
|
@@ -737,25 +764,28 @@ function parseHTML (columns: any, content: any) {
|
|
|
737
764
|
return { fields, rows }
|
|
738
765
|
}
|
|
739
766
|
|
|
740
|
-
function parseXML (
|
|
767
|
+
function parseXML (tableConf: {
|
|
768
|
+
fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
769
|
+
titleMaps: Record<string, VxeTableDefines.ColumnInfo>
|
|
770
|
+
}, content: string) {
|
|
741
771
|
const domParser = new DOMParser()
|
|
742
772
|
const xmlDoc = domParser.parseFromString(content, 'application/xml')
|
|
743
773
|
const sheetNodes = getElementsByTagName(xmlDoc, 'Worksheet')
|
|
744
774
|
const rows: any[] = []
|
|
745
|
-
const fields
|
|
775
|
+
const fields: string[] = []
|
|
746
776
|
if (sheetNodes.length) {
|
|
747
777
|
const tableNodes = getElementsByTagName(sheetNodes[0], 'Table')
|
|
748
778
|
if (tableNodes.length) {
|
|
749
779
|
const rowNodes = getElementsByTagName(tableNodes[0], 'Row')
|
|
750
780
|
if (rowNodes.length) {
|
|
751
|
-
XEUtils.arrayEach(getElementsByTagName(rowNodes[0], 'Cell'),
|
|
752
|
-
fields.push(cellNode.textContent)
|
|
781
|
+
XEUtils.arrayEach(getElementsByTagName(rowNodes[0], 'Cell'), cellNode => {
|
|
782
|
+
fields.push(toExportField(tableConf, cellNode.textContent || ''))
|
|
753
783
|
})
|
|
754
784
|
XEUtils.arrayEach(rowNodes, (rowNode, index) => {
|
|
755
785
|
if (index) {
|
|
756
|
-
const item
|
|
786
|
+
const item: any = {}
|
|
757
787
|
const cellNodes = getElementsByTagName(rowNode, 'Cell')
|
|
758
|
-
XEUtils.arrayEach(cellNodes, (cellNode
|
|
788
|
+
XEUtils.arrayEach(cellNodes, (cellNode, colIndex) => {
|
|
759
789
|
if (fields[colIndex]) {
|
|
760
790
|
item[fields[colIndex]] = cellNode.textContent
|
|
761
791
|
}
|
|
@@ -769,51 +799,56 @@ function parseXML (columns: any, content: any) {
|
|
|
769
799
|
return { fields, rows }
|
|
770
800
|
}
|
|
771
801
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
802
|
+
function handleImport ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, content: any, opts: any) {
|
|
803
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
804
|
+
|
|
805
|
+
const { tableFullColumn, _importResolve, _importReject } = internalData
|
|
806
|
+
let rest: {
|
|
807
|
+
fields: string[];
|
|
808
|
+
rows: any[];
|
|
809
|
+
} = { fields: [], rows: [] }
|
|
810
|
+
const tableFieldMaps: Record<string, VxeTableDefines.ColumnInfo> = {}
|
|
811
|
+
const tableTitleMaps: Record<string, VxeTableDefines.ColumnInfo> = {}
|
|
812
|
+
tableFullColumn.forEach((column) => {
|
|
780
813
|
const field = column.field
|
|
814
|
+
const title = column.getTitle()
|
|
781
815
|
if (field) {
|
|
782
|
-
|
|
816
|
+
tableFieldMaps[field] = column
|
|
817
|
+
}
|
|
818
|
+
if (title) {
|
|
819
|
+
tableTitleMaps[column.getTitle()] = column
|
|
783
820
|
}
|
|
784
821
|
})
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
const { tableFullColumn, _importResolve, _importReject } = $xetable
|
|
790
|
-
let rest: any = { fields: [], rows: [] }
|
|
822
|
+
const tableConf = {
|
|
823
|
+
fieldMaps: tableFieldMaps,
|
|
824
|
+
titleMaps: tableTitleMaps
|
|
825
|
+
}
|
|
791
826
|
switch (opts.type) {
|
|
792
827
|
case 'csv':
|
|
793
|
-
rest = parseCsv(
|
|
828
|
+
rest = parseCsv(tableConf, content)
|
|
794
829
|
break
|
|
795
830
|
case 'txt':
|
|
796
|
-
rest = parseTxt(
|
|
831
|
+
rest = parseTxt(tableConf, content)
|
|
797
832
|
break
|
|
798
833
|
case 'html':
|
|
799
|
-
rest = parseHTML(
|
|
834
|
+
rest = parseHTML(tableConf, content)
|
|
800
835
|
break
|
|
801
836
|
case 'xml':
|
|
802
|
-
rest = parseXML(
|
|
837
|
+
rest = parseXML(tableConf, content)
|
|
803
838
|
break
|
|
804
839
|
}
|
|
805
840
|
const { fields, rows } = rest
|
|
806
|
-
const status =
|
|
841
|
+
const status = fields.some(field => tableFieldMaps[field] || tableTitleMaps[field])
|
|
807
842
|
if (status) {
|
|
808
|
-
$
|
|
843
|
+
$xeTable.createData(rows)
|
|
809
844
|
.then((data: any) => {
|
|
810
845
|
let loadRest
|
|
811
846
|
if (opts.mode === 'insert' || opts.mode === 'insertBottom') {
|
|
812
|
-
loadRest = $
|
|
847
|
+
loadRest = $xeTable.insertAt(data, -1)
|
|
813
848
|
} if (opts.mode === 'insertTop') {
|
|
814
|
-
loadRest = $
|
|
849
|
+
loadRest = $xeTable.insert(data)
|
|
815
850
|
} else {
|
|
816
|
-
loadRest = $
|
|
851
|
+
loadRest = $xeTable.reloadData(data)
|
|
817
852
|
}
|
|
818
853
|
if (opts.message !== false) {
|
|
819
854
|
// 检测弹窗模块
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|