html+vue编写分页功能

效果:

html关键代码:

<div class="ui-jqgrid-resize-mark" id="rs_mlist_table_C87E35BE">&nbsp;</div>
            <div class="list_component_pager ui-jqgrid-pager undefined" dir="ltr">
                <div id="pg_list_table_C87E35BE_pager" class="ui-pager-control" role="group">
                    <table class="ui-pg-table ui-common-table ui-pager-table table table-sm">
                        <tbody>
                        <tr>
                            <td id="list_table_C87E35BE_pager_left" align="left"></td>
                            <td id="list_table_C87E35BE_pager_center" align="center"
                                style="white-space: pre; width: 370.844px;">
                                <table class="ui-pg-table ui-common-table ui-paging-pager">
                                    <tbody>
                                    <tr>
                                        <td ng-show="pageNum<=1" class="ui-pg-button undefined ui-disabled"
                                            title="第一页">
                                            <span class="bi bi-chevron-bar-left"></span>
                                        </td>
                                        <td ng-show="pageNum>1" class="ui-pg-button undefined" title="第一页"
                                            ng-click='ctrl.firstPage()'>
                                            <span class="bi bi-chevron-bar-left"></span>
                                        </td>
                                        <td ng-show="pageNum<=1" class="ui-pg-button undefined ui-disabled"
                                            title="上一页">
                                            <span class="bi bi-chevron-left"></span>
                                        </td>
                                        <td ng-show="pageNum>1" class="ui-pg-button undefined" title="上一页"
                                            ng-click='ctrl.upperPage()'>
                                            <span class="bi bi-chevron-left"></span>
                                        </td>
                                        <td class="ui-pg-button ui-disabled" style="cursor: default;">
                                            <span class="ui-separator"></span>
                                        </td>
                                        <td id="input_list_table_C87E35BE_pager" dir="ltr">
                                            <input class="ui-pg-input undefined" type="text" size="2" maxlength="7"
                                                   ng-model="pageNum" role="textbox">  共
                                            <span id="sp_1_list_table_C87E35BE_pager">{{totalPages}}</span>页
                                        </td>
                                        <td class="ui-pg-button ui-disabled" style="cursor: default;">
                                            <span class="ui-separator"></span>
                                        </td>
                                        <td ng-show="totalPages==pageNum"
                                            class="ui-pg-button undefined ui-disabled"
                                            title="下一页"
                                            style="cursor: default;">
                                            <span class="bi bi-chevron-right"></span>
                                        </td>
                                        <td ng-show="pageNum>=1&&totalPages>1&&pageNum!=totalPages"
                                            class="ui-pg-button undefined"
                                            title="下一页"
                                            ng-click='ctrl.nextPage()'
                                            style="cursor: default;">
                                            <span class="bi bi-chevron-right"></span>
                                        </td>
                                        <td ng-show="pageNum<totalPages"
                                            class="ui-pg-button undefined" title="最后一页"
                                            ng-click='ctrl.lastPage()'>
                                            <span class="bi bi-chevron-bar-right"></span>
                                        </td>
                                        <td ng-show="pageNum>=totalPages"
                                            class="ui-pg-button undefined ui-disabled"
                                            title="最后一页">
                                            <span class="bi bi-chevron-bar-right"></span>
                                        </td>
                                        <td style="margin-top: 20px;">
                                            <cb-select style="border: 1px solid #f0f0f0;margin-top: 20px;"
                                                       ng-model="statType" options="statTypeOptions"
                                                       ng-change='ctrl.flippingPage()'
                                                       inline="true" title="每页记录数">
                                            </cb-select>
                                            <!--                                            <select class="ui-pg-selbox undefined" size="1" role="listbox"-->
                                            <!--                                                    title="每页记录数">-->
                                            <!--                                                <option role="option" value="15" selected="selected">15</option>-->
                                            <!--                                                <option role="option" value="50">50</option>-->
                                            <!--                                                <option role="option" value="100">100</option>-->
                                            <!--                                            </select>-->
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </td>
                            <td id="list_table_C87E35BE_pager_right" align="right">
                                <div dir="ltr" style="text-align:right" class="ui-paging-info">{{test1}}-{{test2}}  共
                                    {{count}} 条
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

vue代码:

$scope.statTypeOptions = [{id: '1', name: '15'}, {id: '2', name: '50'}, {id: '3', name: '100'}];
$scope.statType = $scope.statTypeOptions[0];
$scope.count = '';//总数
$scope.test1 = '';//开始页数
$scope.test2 = '';//结束页数
$scope.totalPages = '';//总页数
$scope.pageNum = '';//页码
$scope.pageSize = '';//每页数
$scope.lastSize = '';//最后一页
                initialize: function () {
                    ctrl.initData();
                },
                initData: function () {
                    ctrl.getList(ctrl.filter.keyword, ctrl.filter.dateRange, ctrl.filter.dateRanges, $scope.pageNum, $scope.pageSize)
                },
                getList: function (keyword, dateRange, dateRanges, pageNum, pageSize) {
                    http.get('maintenanceRecords/total', {
                        keyword: keyword,
                        dateRange: util.encodeJSON(dateRange),
                        dateRanges: util.encodeJSON(dateRanges),
                        pageNum: pageNum, pageSize: pageSize
                    }).then(function (response) {
                        var result = _.get(response, 'data.datas.result', {});
                        $scope.entity = result.list;
                        $scope.count = result.count;
                        $scope.totalPages = result.totalPages;
                        $scope.pageNum = result.pageNum;
                        $scope.pageSize = result.pageSize;

                        if ($scope.pageNum == '1') {
                            $scope.test1 = '1'
                            $scope.test2 = $scope.count
                        } else {
                            $scope.test1 = $scope.pageSize * 1 + 1
                            if ($scope.pageSize * $scope.pageNum <= $scope.count) {
                                $scope.test2 = $scope.pageSize * $scope.pageNum
                            } else {
                                $scope.test2 = $scope.count
                            }
                        }
                        $scope.lastSize = Math.ceil($scope.totalPages / $scope.pageSize);
                        util.apply($scope);
                    });
                },
                firstPage: function () {
                    ctrl.getList(ctrl.filter.keyword, ctrl.filter.dateRange, ctrl.filter.dateRanges, '1', $scope.pageSize)
                },
                upperPage: function () {
                    $scope.pageNum = $scope.pageNum * 1 - 1
                    ctrl.getList(ctrl.filter.keyword, ctrl.filter.dateRange, ctrl.filter.dateRanges, $scope.pageNum, $scope.pageSize)
                },
                nextPage: function () {
                    $scope.pageNum = $scope.pageNum * 1 + 1
                    ctrl.getList(ctrl.filter.keyword, ctrl.filter.dateRange, ctrl.filter.dateRanges, $scope.pageNum, $scope.pageSize)
                },
                lastPage: function () {
                    $scope.pageNum = Math.ceil($scope.count * 1 / $scope.pageSize * 1);
                    ctrl.getList(ctrl.filter.keyword, ctrl.filter.dateRange, ctrl.filter.dateRanges, $scope.pageNum, $scope.pageSize)
                },
                flippingPage: function () {
                    $scope.pageSize = $scope.statType.name
                    ctrl.getList(ctrl.filter.keyword, ctrl.filter.dateRange, ctrl.filter.dateRanges, $scope.pageNum, $scope.pageSize)
                },

Java后端代码:

@GetMapping("/total")
    public CheckMessage total(@RequestParam(value = "keyword", required = false) String keyword,
                              @RequestParam(value = "dateRanges", required = false) String dateRanges,
                              @RequestParam(value = "dateRange", required = false) String dateRange,
                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {
        Document userDoc = UserUtils.getUser();
        Document query = new Document();

        //维修单编号、状态、产品类型、产品编码、产品名称、SN码(新旧码一起搜索)、处理方案、创建日期、维修完成日期
        if (StrUtil.isNotEmpty(keyword)) {
            query = new Document()
                    .append("$or", Arrays.asList(
                            new Document("repairOrderNumber", new Document("$regex", keyword)),
                            new Document("orderWorkStatus", new Document("$regex", keyword)),
                            new Document("appraisal.service.name", new Document("$regex", keyword)),
                            new Document("product.type", new Document("$regex", keyword)),
                            new Document("product.code", new Document("$regex", keyword)),
                            new Document("product.name", new Document("$regex", keyword)),
                            new Document("snCode", new Document("$regex", keyword)),
                            new Document("resultsRepair.newSnCode", new Document("$regex", keyword)),
                            new Document("resultsRepair.machine", new Document("$regex", keyword))));
        }

        if (UserUtils.isOEMUser()) {
            Document oemDto = userDoc.get("oem", Document.class);
            query.append("oemCode", oemDto.getString("id"));
        }

        if (StrUtil.isNotEmpty(dateRange)) {
            Document entity = DocuLib.parseDecode(dateRange);
            if (entity.size() > 0) {
                query.append("$and", Arrays.asList(
                        new Document("createTime", new Document("$gte", entity.getString("start"))),
                        new Document("createTime", new Document("$lte", entity.getString("end")))
                ));
            }
        }

        if (StrUtil.isNotEmpty(dateRanges)) {
            Document entity = DocuLib.parseDecode(dateRanges);
            if (entity.size() > 0) {
                query.append("$and", Arrays.asList(
                        new Document("completedRepairData", new Document("$gte", entity.getString("start"))),
                        new Document("completedRepairData", new Document("$lte", entity.getString("end")))
                ));
            }
        }

        // 计算跳过的记录数
        int skipCount = (pageNum - 1) * pageSize;

        List<Document> list = DBUtils.list(MaintenanceRecords.collectionName, query, null, null, pageSize, skipCount);

        //总数
        long count = DBUtils.count(MaintenanceRecords.collectionName, query);

        // 计算总页数
        int totalPages = (int) Math.ceil((double) count / pageSize);
        Document entity = new Document();
        entity.put("list", list);
        entity.put("count", count);
        entity.put("pageNum", pageNum);
        entity.put("pageSize", pageSize);
        entity.put("totalPages", totalPages);

        return ResultData.succ(entity);
    }

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,作为AI语言模型,我无法提供代码编写服务。但是,我可以为您提供一些指导和建议。 首先,您需要安装Vue3、TypeScript和ElementUI。然后,您可以创建一个Vue组件,该组件包含一个分页表格。您可以使用ElementUI的el-table和el-pagination组件来实现这个分页表格。 在组件中,您需要定义一些数据,例如表格数据、当前页码、每页显示的行数等。您还需要定义一些方法来处理分页和表格数据的加载。 以下是一个简单的示例: ```html <template> <div> <el-table :data="tableData" border> <el-table-column prop="name" label="Name"></el-table-column> <el-table-column prop="age" label="Age"></el-table-column> <el-table-column prop="address" label="Address"></el-table-column> </el-table> <el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalRows" ></el-pagination> </div> </template> <script lang="ts"> import { defineComponent } from 'vue'; import { ElTable, ElTableColumn, ElPagination } from 'element-plus'; export default defineComponent({ name: 'PaginationTable', components: { ElTable, ElTableColumn, ElPagination }, data() { return { tableData: [], currentPage: 1, pageSize: 10, totalRows: , }; }, methods: { async loadData() { // load data from server based on currentPage and pageSize // update tableData and totalRows }, handleCurrentChange(page: number) { this.currentPage = page; this.loadData(); }, }, mounted() { this.loadData(); }, }); </script> ``` 在这个示例中,我们使用了ElementUI的el-table和el-pagination组件来实现分页表格。我们定义了一些数据,例如表格数据、当前页码、每页显示的行数和总行数。我们还定义了一个loadData方法来加载表格数据,并在mounted钩子中调用它。我们还定义了一个handleCurrentChange方法来处理页码变化事件,并在el-pagination组件中使用它。 当用户点击页码或更改每页显示的行数时,handleCurrentChange方法将被调用,并更新currentPage和pageSize数据。然后,loadData方法将被调用,从服务器加载新的表格数据,并更新tableData和totalRows数据。最后,el-pagination组件将根据这些数据重新渲染分页器。 当然,这只是一个简单的示例。您可能需要根据您的具体需求进行更改和扩展。但是,这个示例应该可以帮助您入门Vue3、TypeScript和ElementUI分页表格的编写
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值