tableRanking.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!-- 表格 -->
  2. <template>
  3. <view>
  4. <template v-if="isScroll">
  5. <movable-area scale-area>
  6. <movable-view y="10" style="height: 10px" direction="horizontal" scale scale-min="1" scale-max="4">
  7. <view class="container">
  8. <view class="table" :style="{ padding: padding }">
  9. <view class="table-title" v-if="title">{{ title }}</view>
  10. <view class="table-box">
  11. <uni-table emptyText="暂无更多数据" :loading="loading">
  12. <!-- 表头行 -->
  13. <view class="tableHead">
  14. <uni-tr>
  15. <uni-th class="table-box-th" align="center" v-for="(item, index) in tableTh" :key="index" :width="item.width || ''">{{
  16. item.field
  17. }}</uni-th>
  18. </uni-tr>
  19. </view>
  20. <!-- 表格数据行 -->
  21. <view class="tableBody">
  22. <uni-tr v-for="(item, index) in tableData.list" :key="index">
  23. <uni-td class="table-box-td" align="center" v-for="(field, index) in tableTh" :key="index" :width="field.width || ''">{{
  24. item[field.key] || item[field.key] === 0 ? item[field.key] : '-'
  25. }}</uni-td>
  26. </uni-tr>
  27. </view>
  28. </uni-table>
  29. </view>
  30. <view class="table-pagination" v-if="tableData.total > 0">
  31. <uni-pagination show-icon="true" :total="tableData.total" :current="tableData.current" @change="pageChange"></uni-pagination>
  32. </view>
  33. </view>
  34. </view>
  35. </movable-view> </movable-area
  36. ></template>
  37. <template v-else>
  38. <view class="container">
  39. <view class="table" :style="{ padding: padding }">
  40. <view class="table-title" v-if="title">{{ title }}</view>
  41. <view class="table-box">
  42. <uni-table emptyText="暂无更多数据" :loading="loading">
  43. <!-- 表头行 -->
  44. <uni-tr>
  45. <uni-th class="table-box-th" align="center" v-for="(item, index) in tableTh" :key="index" :width="item.width || ''">{{
  46. item.field
  47. }}</uni-th>
  48. </uni-tr>
  49. <!-- 表格数据行 -->
  50. <uni-tr v-for="(item, index) in tableData.list" :key="index">
  51. <uni-td class="table-box-td" align="center" v-for="(field, index) in tableTh" :key="index" :width="field.width || ''">{{
  52. item[field.key] || item[field.key] === 0 ? item[field.key] : '-'
  53. }}</uni-td>
  54. </uni-tr>
  55. </uni-table>
  56. </view>
  57. <view class="table-pagination" v-if="tableData.total > 0">
  58. <uni-pagination show-icon="true" :total="tableData.total" :current="tableData.current" @change="pageChange"></uni-pagination>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. props: {
  68. title: {
  69. type: String,
  70. default: ''
  71. },
  72. loading: {
  73. type: Boolean,
  74. default: () => {
  75. return false;
  76. }
  77. },
  78. padding: {
  79. type: String,
  80. default: '15px'
  81. },
  82. isScroll: {
  83. type: Boolean,
  84. default: false
  85. },
  86. tableTh: {
  87. type: Array,
  88. default: () => {
  89. return [];
  90. }
  91. },
  92. tableData: {
  93. type: Object,
  94. default: () => {
  95. return {
  96. current: 1,
  97. total: 0,
  98. list: []
  99. };
  100. }
  101. }
  102. },
  103. methods: {
  104. pageChange(e) {
  105. this.$emit('pageChange', e.current);
  106. }
  107. }
  108. };
  109. </script>
  110. /** * tableTh * [{ width: '', field: '', key: '' }] width表示单列的宽度 field表示单列的表头名称 key表示单列字段名 */
  111. <style lang="scss" scoped>
  112. movable-view {
  113. display: flex;
  114. width: auto;
  115. height: auto;
  116. min-width: 100%;
  117. }
  118. movable-area {
  119. height: 100%;
  120. width: 100%;
  121. position: fixed;
  122. overflow: scroll;
  123. }
  124. .tableHead {
  125. font-weight: bold;
  126. color: #333333;
  127. background: #f4f6ff;
  128. z-index: 20;
  129. position: fixed;
  130. top: 0;
  131. }
  132. .tableBody {
  133. max-height: calc(100vh - 254px);
  134. overflow: scroll;
  135. margin-top: 60px;
  136. }
  137. @import 'static/styles/report.scss';
  138. </style>