index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <el-pagination
  3. class="cip-pagination"
  4. :class="{'cip-pagination__compact':compact}"
  5. :background="background"
  6. @size-change="handleSizeChange"
  7. @current-change="handlePageChange"
  8. :layout="layout"
  9. :total="total"
  10. :current-page="currentPage"
  11. :page-sizes="usingPageSizes"
  12. :page-size="limit"
  13. :hide-on-single-page="hideOnSinglePage"
  14. />
  15. </template>
  16. <script>
  17. import { defineComponent, computed } from 'vue'
  18. import { ElPagination } from 'element-plus'
  19. import { useCipConfig } from '../hooks/use-cip-config'
  20. import { getUsingConfig } from '@cip/utils/util'
  21. import { generateProps, generateEmits } from '../helper/component-util'
  22. import { componentScheme } from './component.scheme'
  23. export default defineComponent({
  24. name: 'CipPagination',
  25. components: { ElPagination },
  26. props: generateProps(componentScheme),
  27. emits: generateEmits(componentScheme),
  28. setup (props, context) {
  29. // 每页条数变化事件
  30. const handleSizeChange = (size) => {
  31. const offset = 0 // (props.currentPage - 1) * size
  32. context.emit('update:limit', size)
  33. context.emit('update:offset', offset)
  34. context.emit('refresh')
  35. }
  36. // 当前页变化事件
  37. const handlePageChange = (page) => {
  38. const offset = (page - 1) * props.limit
  39. context.emit('update:offset', offset)
  40. context.emit('refresh', offset)
  41. }
  42. // 样式模式
  43. const cipConfig = useCipConfig()
  44. const usingPageSizes = computed(() => {
  45. return getUsingConfig(props.pageSizes, cipConfig.pageSizes)
  46. })
  47. const compact = computed(() => {
  48. return cipConfig.paginationCompact ?? ''
  49. })
  50. return {
  51. handleSizeChange,
  52. handlePageChange,
  53. compact,
  54. usingPageSizes
  55. }
  56. }
  57. })
  58. </script>
  59. <style lang="less">
  60. // el-pagination 组件样式与数据中台统一
  61. // el-pagination 紧凑型样式(数据中台)
  62. .cip-pagination{
  63. // element-plus2 将el-pagination设置为flex导致起宽度变为100%无法使用 text-align对其进行位置控制将其设置为inline-flex
  64. display: inline-flex;
  65. .btn-prev,.btn-next{
  66. i{
  67. margin: 0 auto;
  68. }
  69. }
  70. }
  71. .cip-pagination__compact{
  72. &.@{elNamespace}-pagination.is-background{
  73. .btn-prev,.btn-next{
  74. margin: 0;
  75. background: #fff;
  76. }
  77. .btn-prev{
  78. border: 1px solid rgb(217, 217, 217);
  79. border-right:none;
  80. border-radius: 0;
  81. }
  82. .btn-next{
  83. border: 1px solid rgb(217, 217, 217);
  84. border-radius: 0;
  85. }
  86. .@{elNamespace}-pager li:not(.disabled).number.active{
  87. background: #ecf5ff;
  88. color: @primary;
  89. }
  90. .@{elNamespace}-pager li.more{
  91. background: #fff;
  92. border: 1px solid rgb(217, 217, 217);
  93. border-right:none;
  94. border-radius: 0;
  95. margin: 0;
  96. color: #a6a6a6;
  97. }
  98. .@{elNamespace}-pager{
  99. .number{
  100. background: #fff;
  101. border: 1px solid rgb(217, 217, 217);
  102. border-right:none;
  103. border-radius: 0;
  104. margin: 0;
  105. color: #a6a6a6;
  106. }
  107. }
  108. }
  109. }
  110. </style>