实现翻页加表头
实现效果
![](https://i-blog.csdnimg.cn/blog_migrate/2d2d0d36a2a00220fceea2670b27f83a.png)
要实现翻页加表头,所以用原生table来写,我把我需要打印的table,写在了dialog里面,下面是我的代码
<el-dialog :visible.sync="boxListPage" width="1460px" append-to-body>
<div id="archiveTitleList" style="text-align:center">
<div
v-for="(boxListInfo,index) in archiveTitleList"
:key="boxListInfo.id"
:style="index != archiveTitleList.length-1?'break-after: page;':''"
>
<div style="display: flex;justify-content: space-between;width:54%">
<span style="font-size:30px;">箱号</span>
<span style="font-size:30px">装箱清单</span>
<span style="font-size:30px;position:absolute;right:10.5%">锁扣号</span>
</div>
<div style="display: flex;justify-content: space-between">
<span style="font-size:30px;">{{ boxListInfo.boxNo }}</span>
<span style="font-size:30px;"> </span>
<span style="font-size:30px;">{{ boxListInfo.lockNo }}</span>
</div>
//实现翻页加表头的原生table
<table
cellspacing="0"
cellpadding="0"
border="0"
class="el-table__body"
style="width: 1418px;"
>
<thead>
<tr class="table-header">
<th
colspan="1"
rowspan="1"
class="el-table_1_column_1 is-center is-leaf first-child el-table__cell"
style=" background: rgb(255, 255, 255);"
>
<div class="cell">序号</div>
</th>
<th
colspan="2"
rowspan="1"
class="el-table_1_column_2 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">件袋号</div>
</th>
<th
colspan="4"
rowspan="1"
class="el-table_1_column_3 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">企业名称</div>
</th>
<th
colspan="1"
rowspan="1"
class="el-table_1_column_4 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">年度</div>
</th>
<th
colspan="2"
rowspan="1"
class="el-table_1_column_5 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">借款日期</div>
</th>
<th
colspan="2"
rowspan="1"
class="el-table_1_column_6 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">还款日期</div>
</th>
<th
colspan="2"
rowspan="1"
class="el-table_1_column_7 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">保证合同编号</div>
</th>
<th
colspan="3"
rowspan="1"
class="el-table_1_column_8 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">借款合同编号</div>
</th>
<th
colspan="2"
rowspan="1"
class="el-table_1_column_9 is-center is-leaf el-table__cell"
style="background: rgb(255, 255, 255);"
>
<div class="cell">盒号</div>
</th>
<th class="el-table__cell gutter" style="width: 0px; display: none;"></th>
</tr>
</thead>
<tbody>
<tr
class="el-table__row"
v-for="(item, index) in boxListInfo.archiveList"
:key="index"
>
<td rowspan="1" colspan="1" class="el-table_1_column_1 is-center first-child el-table__cell">
<div class="cell">
<div>{{index + 1}}</div>
</div>
</td>
<td rowspan="1" colspan="2" class="el-table_1_column_2 is-center el-table__cell">
<div class="cell">{{item.archiveNo}}</div>
</td>
<td rowspan="1" colspan="4" class="el-table_1_column_3 is-center el-table__cell">
<div class="cell">{{item.companyName}}</div>
</td>
<td rowspan="1" colspan="1" class="el-table_1_column_4 is-center el-table__cell">
<div class="cell">{{item.year}}</div>
</td>
<td rowspan="1" colspan="2" class="el-table_1_column_5 is-center el-table__cell">
<div class="cell">{{item.loanDate}}</div>
</td>
<td rowspan="1" colspan="2" class="el-table_1_column_6 is-center el-table__cell">
<div class="cell">{{item.repaymentDate}}</div>
</td>
<td rowspan="1" colspan="2" class="el-table_1_column_7 is-center el-table__cell">
<div class="cell">{{item.guaranteeContractNo}}</div>
</td>
<td rowspan="1" colspan="3" class="el-table_1_column_8 is-center el-table__cell">
<div class="cell">{{item.loanContractNo}}</div>
</td>
<td rowspan="1" colspan="2" class="el-table_1_column_9 is-center el-table__cell">
<div class="cell">{{item.caseNo}}</div>
</td>
</tr>
</tbody>
</table>
<!-- <div style="height: 100px"></div> ---->
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button
v-print="'#archiveTitleList'"
@closeCallback="emptyThis()"
type="primary"
@click="printThis()"
>打印箱清单</el-button>
<el-button @click="noPrint()">取 消</el-button>
</div>
</el-dialog>
<style lang="scss">
.titleclass {
font-size: 20px;
color: rgb(235, 75, 75);
margin-top: 20px;
}
#archiveTitleList{
.el-table__body {
table-layout: fixed;
border-collapse: separate;
.table-header {
.el-table__cell {
border-top: 1px solid black !important;
}
}
.first-child {
border-left: 1px solid black !important;
}
.el-table__cell {
text-align: center;
border-right: 1px solid black !important;
border-bottom: 1px solid black !important;
padding: 12px 0;
min-width: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-overflow: ellipsis;
vertical-align: middle;
position: relative;
}
.cell {
overflow: hidden;
text-overflow: ellipsis;
white-space: normal;
word-break: break-all;
line-height: 23px;
padding-left: 10px;
padding-right: 10px;
}
}
}
.demo-form-inline {
margin-top: 30px;
}
#archiveTitleList {
tr {
page-break-inside: avoid;
}
.el-table--border,
.el-table--group {
border: 1px solid black !important;
}
.el-table th.el-table__cell.is-leaf,
.el-table td.el-table__cell {
border-bottom: 1px solid black !important;
}
.el-table--border .el-table__cell {
border-right: 1px solid black !important;
}
}
</style>
解决空白页问题
:style="index != archiveTitleList.length-1?'break-after: page;':''"这个再加上我下面的css代码是我实现空白页主要代码
<style >
@media print{
#archiveTitleList{
margin:0 1em;
height: auto;
}
body{
border: solid 1px #fff;
margin: 0;
height: auto;
}
html {
background-color: #ffffff;
margin: 0;
height: auto;
}
@page {
size: auto;
}
}
</style>
某行被从中间截断问题
解决方案:给需要打印的table加上这个属性
tr {
page-break-inside: avoid;
}