blocks.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. {% macro pager(_uri, total, limit, curr_page, left=3, right=7) -%}
  2. {% if '?' in _uri %}
  3. {% set uri = _uri + '&' %}
  4. {% else %}
  5. {% set uri = _uri + '?' %}
  6. {% endif %}
  7. {% if total > limit %}
  8. {% set page_num = total//limit if total%limit==0 else total//limit+1 %}
  9. {% set pre_page = curr_page - 1 %}
  10. {% set pre_page = 1 if pre_page < 1 else pre_page %}
  11. {% set next_page = curr_page + 1 %}
  12. {% set next_page = page_num if next_page > page_num else next_page %}
  13. {% set begin_idx = 1 if curr_page <= 3 else curr_page - left %}
  14. {% set end_idx = begin_idx + right %}
  15. {% set end_idx = page_num if end_idx > page_num else end_idx %}
  16. <ul class="pagination">
  17. {%if curr_page > 1 %}
  18. <li><a href="{{uri}}p=1&limit={{ limit }}">|&lt;</a></li>
  19. <li><a href="{{uri}}p={{pre_page}}&limit={{ limit }}">&lt;</a></li>
  20. {%else%}
  21. <li class="disabled"><a>|&lt;</a></li>
  22. <li class="disabled"><a>&lt;</a></li>
  23. {%endif%}
  24. {% for idx in range(begin_idx, end_idx+1) %}
  25. <li class="{%if curr_page == idx %}active{%endif%}">
  26. <a href="{{uri}}p={{idx}}&limit={{ limit }}">{{idx}}</a>
  27. </li>
  28. {% endfor %}
  29. {%if curr_page < page_num %}
  30. <li><a href="{{uri}}p={{next_page}}&limit={{ limit }}">&gt;</a></li>
  31. <li><a href="{{uri}}p={{page_num}}&limit={{ limit }}">&gt;|</a></li>
  32. {%else%}
  33. <li
  34. class="disabled"><a>&gt;</a></li>
  35. <li
  36. class="disabled"><a>&gt;|</a></li>
  37. {%endif%}
  38. </ul>
  39. {%endif%}
  40. {%- endmacro %}