tableRanking.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!-- 表格 -->
  2. <template>
  3. <view class="container">
  4. <view class="table" :style="{ padding: padding }">
  5. <view class="table-title" v-if="title">{{ title }}</view>
  6. <view class="table-box">
  7. <uni-table emptyText="暂无更多数据" :loading="loading">
  8. <!-- 表头行 -->
  9. <uni-tr>
  10. <uni-th
  11. class="table-box-th"
  12. align="center"
  13. v-for="(item, index) in tableTh"
  14. :key="index"
  15. :width="item.width || ''"
  16. >{{ item.field }}</uni-th>
  17. </uni-tr>
  18. <!-- 表格数据行 -->
  19. <uni-tr v-for="(item, index) in tableData.list" :key="index">
  20. <uni-td
  21. class="table-box-td"
  22. align="center"
  23. v-for="(field, index) in tableTh"
  24. :key="index"
  25. >{{ item[field.key] || item[field.key] === 0 ? item[field.key] : '-' }}</uni-td>
  26. </uni-tr>
  27. </uni-table>
  28. </view>
  29. <view class="table-pagination" v-if="tableData.total > 0">
  30. <uni-pagination
  31. show-icon="true"
  32. :total="tableData.total"
  33. :current="tableData.current"
  34. @change="pageChange"
  35. ></uni-pagination>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. props: {
  43. title: {
  44. type: String,
  45. default: ''
  46. },
  47. loading: {
  48. type: Boolean,
  49. default: () => {
  50. return false;
  51. }
  52. },
  53. padding: {
  54. type: String,
  55. default: '15px'
  56. },
  57. tableTh: {
  58. type: Array,
  59. default: () => {
  60. return [];
  61. }
  62. },
  63. tableData: {
  64. type: Object,
  65. default: () => {
  66. return {
  67. current: 1,
  68. total: 0,
  69. list: []
  70. };
  71. }
  72. }
  73. },
  74. methods: {
  75. pageChange(e) {
  76. this.$emit('pageChange', e.current);
  77. }
  78. }
  79. };
  80. </script>
  81. /**
  82. * tableTh
  83. * [{ width: '', field: '', key: '' }] width表示单列的宽度 field表示单列的表头名称 key表示单列字段名
  84. */
  85. <style lang="scss" scoped>
  86. @import 'static/styles/report.scss';
  87. </style>