Skip to content

Commit

Permalink
修复了合并单元格的表格部分情况下显示不正确的问题 #561
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-yufeng committed Nov 17, 2023
1 parent a08941d commit e89cad8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/miniprogram/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ Parser.prototype.popNode = function () {
node.flag = undefined
// 有 colspan 或 rowspan 且含有链接的表格通过 grid 布局实现
styleObj.display = 'grid'
if (styleObj['border-collapse'] === 'collapse') {
styleObj['border-collapse'] = undefined
spacing = 0
}
if (spacing) {
styleObj['grid-gap'] = spacing + 'px'
styleObj.padding = spacing + 'px'
Expand All @@ -778,6 +782,23 @@ Parser.prototype.popNode = function () {
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].name === 'tr') {
trList.push(nodes[i])
} else if (nodes[i].name === 'colgroup') {
let colI = 1
for (const col of (nodes[i].children || [])) {
if (col.name === 'col') {
const style = col.attrs.style || ''
const start = style.indexOf('width') ? style.indexOf(';width') : 0
// 提取出宽度
if (start !== -1) {
let end = style.indexOf(';', start + 6)
if (end === -1) {
end = style.length
}
width[colI] = style.substring(start ? start + 7 : 6, end)
}
colI += 1
}
}
} else {
traversal(nodes[i].children || [])
}
Expand Down Expand Up @@ -808,17 +829,17 @@ Parser.prototype.popNode = function () {
style = style.substr(0, start) + style.substr(end)
}
// 设置竖直对齐
style += ';display:flex'
style += ';display:flex;flex-direction:column'
start = style.indexOf('vertical-align')
if (start !== -1) {
const val = style.substr(start + 15, 10)
if (val.includes('middle')) {
style += ';align-items:center'
style += ';justify-content:center'
} else if (val.includes('bottom')) {
style += ';align-items:flex-end'
style += ';justify-content:flex-end'
}
} else {
style += ';align-items:center'
style += ';justify-content:center'
}
// 设置水平对齐
start = style.indexOf('text-align')
Expand Down
21 changes: 21 additions & 0 deletions src/uni-app/components/mp-html/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ Parser.prototype.popNode = function () {
if (node.flag && node.c) {
// 有 colspan 或 rowspan 且含有链接的表格通过 grid 布局实现
styleObj.display = 'grid'
if (styleObj['border-collapse'] === 'collapse') {
styleObj['border-collapse'] = undefined
spacing = 0
}
if (spacing) {
styleObj['grid-gap'] = spacing + 'px'
styleObj.padding = spacing + 'px'
Expand All @@ -867,6 +871,23 @@ Parser.prototype.popNode = function () {
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].name === 'tr') {
trList.push(nodes[i])
} else if (nodes[i].name === 'colgroup') {
let colI = 1
for (const col of (nodes[i].children || [])) {
if (col.name === 'col') {
const style = col.attrs.style || ''
const start = style.indexOf('width') ? style.indexOf(';width') : 0
// 提取出宽度
if (start !== -1) {
let end = style.indexOf(';', start + 6)
if (end === -1) {
end = style.length
}
width[colI] = style.substring(start ? start + 7 : 6, end)
}
colI += 1
}
}
} else {
traversal(nodes[i].children || [])
}
Expand Down

0 comments on commit e89cad8

Please sign in to comment.