Skip to content

Commit ed80dff

Browse files
committed
fix: 数据表格宽度问题修复。(表格行高因此暂时失效,以后修复)
1 parent e67badb commit ed80dff

File tree

4 files changed

+68
-16
lines changed

4 files changed

+68
-16
lines changed

src/components/PageComponents/RoyTable/RoyComplexTable.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@
4949
>
5050
<table :style="`width: ${bodyTableWidth}px`">
5151
<thead>
52-
<tr :style="`height: ${tableRowHeight}px`">
52+
<tr>
5353
<th
5454
v-for="(item, index) in tableCols"
5555
:key="index"
5656
:style="{
57-
width: `${item.width}px`
57+
width: `${item.width}px`,
58+
height: `${tableRowHeight}px`
5859
}"
5960
>
60-
{{ item.title }}
61+
<div style="display: inline; width: 100%">
62+
{{ item.title }}
63+
</div>
6164
</th>
6265
</tr>
6366
</thead>

src/components/PageComponents/style.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,26 @@ export const StyledComplexTable = styled('div', complexTableProps)`
360360
th {
361361
text-align: center;
362362
font-weight: bold;
363-
padding: 2px;
363+
padding: 0;
364+
word-break: break-all;
364365
}
365366
366367
td {
367-
padding: 3px;
368+
padding: 0;
369+
word-break: break-all;
370+
position: relative;
371+
}
372+
373+
.roy-complex-table-cell-in {
374+
height: 100%;
375+
width: 100%;
376+
position: absolute;
377+
left: 0;
378+
right: 0;
379+
top: 0;
380+
bottom: 0;
381+
align-items: center;
382+
display: flex;
368383
}
369384
370385
.rendered-roy-complex-table__footer {

src/components/Viewer/auto-render.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ export class AutoRender {
355355
const { tables, overflowPages } = this.getTablesSplit(
356356
element.style,
357357
trElements,
358-
thElement
358+
thElement,
359+
true
359360
)
360361
tables.forEach((table, index) => {
361362
if (index > 0) {
@@ -435,8 +436,18 @@ export class AutoRender {
435436
newElement = null
436437
}
437438

438-
getTablesSplit(style, rows, head = null) {
439-
let headHeight = head == null ? 0 : head.clientHeight
439+
getTablesSplit(style, rows, head = null, isDataTable = false) {
440+
let headHeight = 0
441+
if (isDataTable && head !== null) {
442+
let innerCell = head.getElementsByClassName('roy-complex-table-cell-in')
443+
for (let cell of innerCell) {
444+
headHeight =
445+
headHeight < cell.children[0].clientHeight
446+
? cell.children[0].clientHeight
447+
: headHeight
448+
}
449+
head.children[0].style.height = `${headHeight}px`
450+
}
440451
let headHtml = head == null ? '' : head.outerHTML
441452
let realTop = this.curPageUsedHeight || style.top
442453
let maxHeight = this.maxPageUseHeight - realTop
@@ -448,6 +459,19 @@ export class AutoRender {
448459
let maxTableWidth = 0
449460
for (let i = 0; i < rows.length; i++) {
450461
let curTd = rows[i]
462+
if (isDataTable) {
463+
let maxHeight = 0
464+
let innerCell = curTd.getElementsByClassName(
465+
'roy-complex-table-cell-in'
466+
)
467+
for (let cell of innerCell) {
468+
maxHeight =
469+
maxHeight < cell.children[0].clientHeight
470+
? cell.children[0].clientHeight
471+
: maxHeight
472+
}
473+
curTd.style.height = `${maxHeight}px`
474+
}
451475
let lastHeight = curHeight
452476
curHeight += curTd.clientHeight
453477
maxTableWidth =

src/components/Viewer/auto-table.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,33 @@ export class AutoTable {
106106
}
107107

108108
generateComplexTable() {
109-
const { tableRowHeight, tableDataSource, tableCols, bodyTableWidth } =
110-
this.propValue
109+
const { tableDataSource, tableCols, bodyTableWidth } = this.propValue
111110
const tableData = this.dataSet[tableDataSource] || []
112111
const tableHead = tableCols
113112
.map((item) => {
114-
return `<th style='width: ${item.width}px; height: ${tableRowHeight}px'>${item.title}</th>`
113+
return `<th style='width: ${item.width}px;'>
114+
<div class="roy-complex-table-cell-in" style='justify-content: center;'>
115+
<div style='padding: 3px'>${item.title}</div>
116+
</div>
117+
</th>`
115118
})
116119
.join('')
120+
let widthList = tableCols.map((item) => {
121+
return item.width
122+
})
117123
const tableBody = tableData
118124
.map((row) => {
119125
let tdEle = tableCols
120-
.map((col) => {
126+
.map((col, index) => {
121127
const { field, formatter, align } = col
122-
return `<td height="${tableRowHeight}px" style="text-align: ${align}">${RenderUtil.getDataWithTypeConvertedByDataSource(
123-
row[field],
124-
formatter
125-
)}</td>`
128+
return `<td style="width: ${widthList[index]}px;">
129+
<div class="roy-complex-table-cell-in" style='justify-content: ${align}'>
130+
<div style='padding: 3px'>${RenderUtil.getDataWithTypeConvertedByDataSource(
131+
row[field],
132+
formatter
133+
)}</div>
134+
</div>
135+
</td>`
126136
})
127137
.join('')
128138
return `<tr class="roy-complex-table-row">${tdEle}</tr>`

0 commit comments

Comments
 (0)