CzrTableCard.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="czr-table-card-main">
  3. <div class="czr-table-card-content">
  4. <template v-if="data?.length > 0">
  5. <div
  6. class="czr-table-card-content-list"
  7. :style="`gap: ${rowMargin} ${colMargin};grid-template-columns: repeat(${col}, calc((100% - ${colMargin} * ${col - 1}) / ${col}));`"
  8. >
  9. <template v-for="(item, index) in data">
  10. <div class="czr-table-card-content-list-model">
  11. <slot name="model" :row="item" :index="index" />
  12. </div>
  13. </template>
  14. </div>
  15. </template>
  16. <template v-else>
  17. <div class="czr-table-card-content-no-data el-table__empty-text">
  18. 暂无数据
  19. </div>
  20. </template>
  21. </div>
  22. <div class="ctc-page">
  23. <div class="total">
  24. <template v-if="isValue(selectLength)">
  25. 已选中 {{ selectLength }} 条 /
  26. </template>
  27. 共 {{ total }} 条
  28. </div>
  29. <el-pagination
  30. v-if="noPage === false"
  31. class="__cus-pagination"
  32. :currentPage="page"
  33. :page-size="pageSize"
  34. background
  35. :page-sizes="pageSizes"
  36. :layout="pageLayoutCpt"
  37. :total="Number(total)"
  38. @size-change="handleSizeChange"
  39. @current-change="handleCurrentChange"
  40. :pager-count="5"
  41. />
  42. </div>
  43. </div>
  44. </template>
  45. <script setup lang="ts">
  46. defineOptions({
  47. name: 'CzrTableCard',
  48. })
  49. import { computed, ref, reactive } from 'vue'
  50. import { isValue } from '@/utils/czr-util'
  51. const emit = defineEmits(['handlePage'])
  52. const props = defineProps({
  53. total: {
  54. required: true,
  55. },
  56. page: {},
  57. pageSize: {},
  58. pageSizes: {
  59. default: () => [20, 40, 60, 80, 100],
  60. },
  61. noPage: {
  62. default: false,
  63. },
  64. col: {
  65. default: 2,
  66. },
  67. colMargin: {
  68. default: '1rem',
  69. },
  70. rowMargin: {
  71. default: '1rem',
  72. },
  73. data: {
  74. required: true,
  75. default: () => [],
  76. },
  77. noLayout: {
  78. default: () => [],
  79. },
  80. selectLength: {
  81. default: null,
  82. },
  83. })
  84. const state = reactive({
  85. pageLayout: ['sizes', 'prev', 'pager', 'next', 'jumper'],
  86. })
  87. const pageLayoutCpt = computed(() => {
  88. return state.pageLayout
  89. .filter((v: string) => props.noLayout.every((s: string) => v !== s))
  90. .join(',')
  91. })
  92. const handleSizeChange = (val: Number) => {
  93. emit('handlePage', 1, val)
  94. }
  95. const handleCurrentChange = (val: Number) => {
  96. emit('handlePage', val, props.pageSize)
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .czr-table-card-main {
  101. width: 100%;
  102. height: 100%;
  103. display: flex;
  104. flex-direction: column;
  105. $cus-page-height: 32px;
  106. .czr-table-card-content {
  107. overflow-y: auto;
  108. overflow-x: hidden;
  109. flex: 1;
  110. .czr-table-card-content-list {
  111. display: grid;
  112. .czr-table-card-content-list-model {
  113. overflow: hidden;
  114. }
  115. }
  116. .czr-table-card-content-no-data {
  117. width: 100%;
  118. height: 100%;
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. font-size: 14px;
  123. }
  124. }
  125. :deep(.ctc-page) {
  126. height: $cus-page-height;
  127. margin-top: 25px;
  128. font-size: 14px;
  129. font-family: Microsoft YaHei;
  130. font-weight: 400;
  131. color: #999999;
  132. display: flex;
  133. justify-content: space-between;
  134. .total {
  135. display: flex;
  136. align-items: center;
  137. }
  138. }
  139. }
  140. </style>