fix:paste table data format judgment

pr675
Hufe921 3 years ago
parent 144cb35d37
commit 8ff0d01dde

@ -196,41 +196,37 @@ export function getElementListByHTML(htmlText: string, options: IGetElementListB
colgroup: [], colgroup: [],
trList: [] trList: []
} }
let tdCount = 0
// 基础数据 // 基础数据
tableElement.querySelectorAll('tr').forEach((trElement, trIndex) => { tableElement.querySelectorAll('tr').forEach(trElement => {
const trHeightStr = window.getComputedStyle(trElement).height.replace('px', '') const trHeightStr = window.getComputedStyle(trElement).height.replace('px', '')
const tr: ITr = { const tr: ITr = {
height: Number(trHeightStr), height: Number(trHeightStr),
tdList: [] tdList: []
} }
trElement.querySelectorAll('td').forEach(tdElement => { trElement.querySelectorAll('th,td').forEach(tdElement => {
const colspan = tdElement.colSpan const tableCell = <HTMLTableCellElement>tdElement
const rowspan = tdElement.rowSpan
if (trIndex === 0) {
tdCount += colspan
}
const td: ITd = { const td: ITd = {
colspan, colspan: tableCell.colSpan,
rowspan, rowspan: tableCell.rowSpan,
value: [{ value: [{
value: tdElement.innerText value: tableCell.innerText
}] }]
} }
tr.tdList.push(td) tr.tdList.push(td)
}) })
if (tr.tdList.length) {
element.trList!.push(tr) element.trList!.push(tr)
}
}) })
if (element.trList!.length) {
// 列选项数据 // 列选项数据
if (tdCount) { const tdCount = element.trList![0].tdList.reduce((pre, cur) => pre + cur.colspan, 0)
const width = Math.ceil(options.innerWidth / tdCount) const width = Math.ceil(options.innerWidth / tdCount)
for (let i = 0; i < tdCount; i++) { for (let i = 0; i < tdCount; i++) {
element.colgroup!.push({ element.colgroup!.push({
width width
}) })
} }
}
if (element.colgroup) {
elementList.push(element) elementList.push(element)
} }
} else if (node.nodeName === 'INPUT' && (<HTMLInputElement>node).type === ControlComponent.CHECKBOX) { } else if (node.nodeName === 'INPUT' && (<HTMLInputElement>node).type === ControlComponent.CHECKBOX) {

Loading…
Cancel
Save