<!--<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">-->
    <!--<div class="btn-group mr-2" role="group" aria-label="First group">-->
        <!--<button type="button" class="btn btn-light" disabled title="首页"><i class="fa fa-caret-left"></i></button>-->
        <!--<button type="button" class="btn btn-light" disabled title="上一页"><i class="fa fa-angle-left"></i></button>-->
    <!--</div>-->
    <!--<div class="btn-group mr-2" role="group" aria-label="Second group">-->
        <!--<button type="button" class="btn btn-light active">1</button>-->
        <!--<button type="button" class="btn btn-light">2</button>-->
        <!--<button type="button" class="btn btn-light">3</button>-->
        <!--<button type="button" class="btn btn-light">4</button>-->
        <!--<button type="button" class="btn btn-light">5</button>-->
        <!--<button type="button" class="btn btn-light" title="更多">...</button>-->
    <!--</div>-->
    <!--<div class="btn-group" role="group" aria-label="Third group">-->
        <!--<button type="button" class="btn btn-light" title="下一页"><i class="fa fa-angle-right"></i></button>-->
        <!--<button type="button" class="btn btn-light" title="尾页"><i class="fa fa-caret-right"></i></button>-->
    <!--</div>-->
<!--</div>-->

<nav aria-label="Page navigation example">
    <ul class="pagination"></ul>
</nav>
<script type="text/javascript" src="/public/js/bootstrap/bootstrap-paginator.js"></script>
<script type="text/javascript">
    let options = {
        bootstrapMajorVersion: 4,
        currentPage: "<%= pageInfo.page %>",
        totalPages: "<%= pageInfo.total %>",
        numberOfPages: 5,
        size: "normal",
        itemContainerClass: function(type, page, current) {
            let className = 'page-item';
            this.currentPage = parseInt(this.currentPage);
            this.totalPages = parseInt(this.totalPages);

            switch (type) {
                case "first":
                    className = this.currentPage === 1 ? className + ' disabled' : className;
                    break;
                case "prev":
                    className = this.currentPage === 1 ? className + ' disabled' : className;
                    break;
                case "next":
                    className = this.currentPage === this.totalPages ? className + ' disabled' : className;
                    break;
                case "last":
                    className = this.currentPage === this.totalPages ? className + ' disabled' : className;
                    break;
                case "page":
                    className = page === this.currentPage ? className + ' active' : className;
                    break;
            }

            return className;
        },
        itemContentClass: function(type, page, current) {
            return 'page-link';
        },
        itemTexts: function(type, page, current) {
            switch (type) {
                case "first":
                    return '<i class="fa fa-caret-left"></i>';
                case "prev":
                    return '<i class="fa fa-angle-left"></i>';
                case "next":
                    return '<i class="fa fa-angle-right"></i>';
                case "last":
                    return '<i class="fa fa-caret-right"></i>';
                case "page":
                    return page;
                case "more":
                    return '...';
            }
        },
        shouldShowPage: function (type, page, current) {
            let result = true;
            switch (type) {
                case "first":
                    break;
                case "prev":
                    break;
                case "next":
                    break;
                case "last":
                    break;
                case "page":
                    break;
                case "more":
                    result = (page !== this.totalPages);
                    break;
            }
            return result;

        },
        pageUrl: function(type, page, current){
            let queryData = JSON.parse('<%- pageInfo.queryData %>');
            // 如果没有附带查询条件则直接返回
            if (Object.keys(queryData).length <= 0) {
                return "?page=" + page;
            }
            // 有其它数据则重新赋值page，然后组合字符串
            queryData.page = page;
            let queryArray = [];
            for(let tmp in queryData) {
                let tempString = tmp + '=' + queryData[tmp];
                queryArray.push(tempString);
            }

            let firstQuery = queryArray.shift();
            let queryString = queryArray.join('&');
            return  queryString === '' ? '?' + firstQuery : '?' + firstQuery + '&' + queryString;
        }
    };
    if (options.totalPages > 1) {
        $(".pagination").bootstrapPaginator(options);
    } else {
        $(".pagination").hide();
    }
</script>