html+vue实现分页功能的示例代码

 更新时间:2024年04月20日 11:16:06   作者:星晨羽  
这篇文章主要为大家详细介绍了如何使用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);
    }

到此这篇关于html+vue实现分页功能的示例代码的文章就介绍到这了,更多相关vue分页内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Vue路由切换和Axios接口取消重复请求详解

    Vue路由切换和Axios接口取消重复请求详解

    在web项目开发的过程中,经常会遇到客服端重复发送请求的场景,下面这篇文章主要给大家介绍了关于Vue路由切换和Axios接口取消重复请求的相关资料,需要的朋友可以参考下
    2022-05-05
  • vue + element-ui 季度选择器组件 el-quarter-picker示例详解

    vue + element-ui 季度选择器组件 el-quarter-picker示例详解

    本文介绍如何在Vue项目中使用基于Element-UI的季度选择器组件ElQuarterPicker,通过引用并调用ElQuarterPicker.vue组件来实现季度选择功能,感兴趣的朋友跟随小编一起看看吧
    2024-09-09
  • vue中el-message的封装使用

    vue中el-message的封装使用

    本文主要介绍了vue中el-message的封装使用,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-02-02
  • vue实现指定日期之间的倒计时

    vue实现指定日期之间的倒计时

    这篇文章主要为大家详细介绍了vue实现指定日期之间的倒计时,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-05-05
  • Vue中EpicEditor和vue-quill-editor的使用详解

    Vue中EpicEditor和vue-quill-editor的使用详解

    EpicEditor和Vue-quill-editor都是基于Quill.js的富文本编辑器,并且都提供了许多强大的功能,下面我们就来介绍一下二者的具体使用,感兴趣的小伙伴可以了解一下
    2023-11-11
  • Vue的百度地图插件尝试使用

    Vue的百度地图插件尝试使用

    本篇文章主要介绍了Vue的百度地图插件尝试使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • 详解Vuex的属性

    详解Vuex的属性

    Vuex是专为Vue.js应用程序开发的状态管理模式,这篇文章主要介绍了Vuex的属性,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-08-08
  • 在vue中实现表单验证码与滑动验证功能的代码详解

    在vue中实现表单验证码与滑动验证功能的代码详解

    在Web应用程序中,表单验证码和滑动验证是常见的安全机制,用于防止恶意攻击和机器人攻击,本文将介绍如何使用Vue和vue-verify-code库来实现表单验证码和滑动验证功能,需要的朋友可以参考下
    2023-06-06
  • 亲自动手实现vue日历控件

    亲自动手实现vue日历控件

    这篇文章主要记录了亲自动手实现vue日历控件的详细过程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-06-06
  • 搭建vue3项目以及按需引入element-ui框架组件全过程

    搭建vue3项目以及按需引入element-ui框架组件全过程

    element是基于vue.js框架开发的快速搭建前端的UI框架,下面这篇文章主要给大家介绍了关于搭建vue3项目以及按需引入element-ui框架组件的相关资料,文中通过图文以及代码介绍的非常详细,需要的朋友可以参考下
    2024-02-02

最新评论