pageGroup.js分页器的使用

本文详细介绍了一组CSS样式的设计方案及其在网页布局中的实际应用,包括页面元素的定位、字体大小、颜色设置等,通过具体例子展示了如何使用CSS来美化页面。
css部分:

 <style>
        #pageGro{ width:400px; height:25px; margin:0px auto; padding-top:60px;margin-bottom:74px;}
        #pageGro div,#pageGro div ul li{ font-size:12px;color:#000; line-height:24px; float:left; margin-left:5px;}
        #pageGro div ul li{ width:22px; text-align:center; border:1px solid #959595; cursor:pointer;}
        #pageGro div ul li.on{ color:#fff; background:#3c90d9; border:1px solid #3c90d9;}
        #pageGro .pageUp,#pageGro .pageDown{ width:63px; border:1px solid #999; cursor:pointer;text-align:center}


        .downpage {
            margin: 50px auto;
            margin-bottom: 20px;
            width: 78px;
            height: 34px;
        }
        .downpage li:first-child {
            margin-left: 0px;
        }
        .downpage li {
            float: left;
            margin-left: 10px;
        }
        .downpage li a.blue {
            color: #0195ff;
        }
        .downpage li a {
            float: left;
            display: block;
            color: #7e7b7b;
            width: 32px;
            text-align: center;
            height: 32px;
            line-height: 32px;
            border: 1px solid #eee;
        }
        .clearfix{
            display: block;
            width: 0;
            height: 0;
            overflow: hidden;
            clear: both;
        }
        *{margin: 0; padding: 0;}
        body{
            font-family: Arial,"Microsoft YaHei","微软雅黑",sans-serif;
            background-color: #fff;
            min-width:1080px;
        }
        li{list-style: none;}
        a{text-decoration: none;}
    </style>
</head><body>
<div class="downpage">
    <ol>
        <li>
            <a href="culture.html"  class="blue">1</a>
        </li>
        <li>
            <a href="index.html">2</a>
        </li>
    </ol>
</div>
<div class="clearfix"></div>
</div>
</div>


<script type="text/javascript" src="js/pageGroup.js" ></script>
</body>
</html




要在打印时每一页都显示表头,并且表头中包含你提供的 Vue 模板结构(包含页眉信息、样品名称判断、合并展示提示等),我们需要结合以下两个关键点: --- ## ✅ 1. 使用 CSS `thead` + `display: table-header-group` 实现每页显示表头 ```css @media print { thead { display: table-header-group; } tr { page-break-inside: avoid; } } ``` --- ## ✅ 2. 在 `<thead>` 中嵌套 `<tr>` 和 `<th>`,并插入你提供的页眉结构 你希望在每一页的表头中显示如下结构: ```html <div class="header"> <p>{{ dataForm.checknum }}</p> <p style="display:flex;justify-content: space-between;"> <span v-if="isSameSampleOnPage(pageGroup.rows)"> {{ pageGroup.rows[0].samplename }} </span> <span v-else>合并展示</span> <span>试验地点:实验室</span> </p> </div> ``` 但由于 `<thead>` 中不能直接使用 `<div>`,我们可以将其转换为表格结构,例如: --- ## ✅ 完整实现代码(Vue 模板 + CSS) ### 📁 Vue 模板部分 ```vue <template> <div id="print-area"> <div v-for="(pageGroup, pageIndex) in pagedItems" :key="pageIndex" class="page"> <table class="report-table"> <!-- 表头 --> <thead> <tr> <th colspan="100%"> <div class="header"> <p>报告编号:{{ dataForm.checknum }}</p> <p style="display:flex;justify-content: space-between;"> <span v-if="isSameSampleOnPage(pageGroup.items)"> {{ pageGroup.items[0].samplename }} </span> <span v-else>合并展示</span> <span>试验地点:实验室</span> </p> </div> </th> </tr> <tr> <th>检测项目</th> <th>样品名称</th> <th>其他字段</th> </tr> </thead> <!-- 表体 --> <tbody> <tr v-for="row in pageGroup.items" :key="row.id"> <td>{{ row.testingitems }}</td> <td>{{ row.samplename }}</td> <td>{{ row.result }}</td> </tr> </tbody> </table> </div> </div> </template> ``` --- ### 📁 Vue 脚本部分(methods) ```js <script> export default { data() { return { dataForm: { checknum: '2025-001' }, reportingmanagersonList: [ { id: 1, samplename: '样品1', testingitems: '项目A', result: '合格' }, { id: 2, samplename: '样品1', testingitems: '项目B', result: '合格' }, { id: 3, samplename: '样品1', testingitems: '项目C', result: '合格' }, { id: 4, samplename: '样品2', testingitems: '项目A', result: '合格' }, { id: 5, samplename: '样品2', testingitems: '项目D', result: '合格' }, { id: 6, samplename: '样品3', testingitems: '项目E', result: '合格' }, { id: 7, samplename: '样品3', testingitems: '项目F', result: '合格' }, { id: 8, samplename: '样品4', testingitems: '项目G', result: '合格' }, { id: 9, samplename: '样品4', testingitems: '项目H', result: '合格' }, { id: 10, samplename: '样品5', testingitems: '项目I', result: '合格' }, ], pagedItems: [] }; }, mounted() { this.pagedItems = this.getPagedItems(this.groupedSamples); }, computed: { groupedSamples() { const groups = {}; this.reportingmanagersonList.forEach(item => { const name = item.samplename; if (!groups[name]) groups[name] = []; groups[name].push(item); }); return Object.keys(groups).map(name => ({ samplename: name, items: groups[name] })); } }, methods: { isSameSampleOnPage(items) { const sampleName = items[0].samplename; return items.every(item => item.samplename === sampleName); }, getPagedItems(groupedSamples) { const pages = []; groupedSamples.forEach(group => { const items = group.items; for (let i = 0; i < items.length; i += 5) { const pageItems = items.slice(i, i + 5); pages.push({ samplename: group.samplename, items: pageItems }); } }); return pages; } } }; </script> ``` --- ### 📁 CSS 样式部分(打印样式) ```css <style> @media print { thead { display: table-header-group; } tr { page-break-inside: avoid; } body { -webkit-print-color-adjust: exact; } } .page { height: 920px; width: 100%; page-break-after: always; box-sizing: border-box; } .report-table { width: 100%; border-collapse: collapse; height: 100%; } .header { padding: 10px; font-size: 14px; font-weight: bold; } .header p { margin: 0; } .report-table th, .report-table td { border: 1px solid #000; padding: 8px; vertical-align: middle; } </style> ``` --- ## ✅ 功能说明 | 功能 | 实现方式 | |------|----------| | ✅ 每页显示表头 | 使用 `<thead>` + `display: table-header-group` | | ✅ 表头中显示页眉信息 | 将页眉结构嵌套在 `<thead>` 的 `<th colspan="100%">` 中 | | ✅ 动态判断是否为同一样品 | 使用 `isSameSampleOnPage` 方法 | | ✅ 每页固定高度 920px | 使用 `.page { height: 920px }` | | ✅ 支持打印样式 | 使用 `@media print` 控制样式 | --- ## ✅ 打印建议 你可以使用如下代码触发浏览器打印: ```js window.print(); ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值