table.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="table-view">
  3. <view
  4. class="table-header"
  5. :style="{ backgroundColor: headerBackgroundColor }"
  6. >
  7. <view
  8. class="table-th"
  9. v-for="(item, index) in columns"
  10. :key="index"
  11. :style="{
  12. flex: item.width ? `0 0 ${item.width}rpx` : '1',
  13. textAlign: item.align || 'left',
  14. fontSzie: `${fontSize}rpx`
  15. }"
  16. >
  17. <!-- <slot :name="item.dataIndex" > -->
  18. {{ item.name || "" }}
  19. <!-- </slot> -->
  20. </view>
  21. </view>
  22. <view class="table-tr" v-for="(item, index) in dataList" :key="index">
  23. <view
  24. class="table-td"
  25. v-for="(column, columnIndex) in columns"
  26. :key="columnIndex"
  27. :style="{
  28. flex: column.width ? `0 0 ${column.width}rpx` : '1',
  29. textAlign: column.align || 'left',
  30. fontSzie: `${fontSize}rpx`
  31. }"
  32. >
  33. <!-- {{ item[column.dataIndex] || "" }} -->
  34. <slot v-if="column.custom" :row="item" :column="column">
  35. {{ item[column.dataIndex] }}
  36. </slot>
  37. <text v-else :class="[column.color || '']">
  38. {{ item[column.dataIndex] }}
  39. </text>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. props: {
  47. columns: {
  48. type: Array,
  49. default: []
  50. },
  51. dataList: {
  52. type: Array,
  53. default: []
  54. },
  55. headerBackgroundColor: {
  56. type: String,
  57. default: "#ffffff"
  58. },
  59. fontSize: {
  60. type: String,
  61. default: 24
  62. }
  63. },
  64. mounted() {
  65. for (let index = 0; index < this.$children.length; index++) {
  66. const element = this.$children[index];
  67. console.log(33333, element, element.$attrs);
  68. }
  69. },
  70. methods: {
  71. childrenItem(name) {
  72. let item = null;
  73. for (let index = 0; index < this.$children.length; index++) {
  74. const element = this.$children[index];
  75. if (element.$options.name == "table-item") {
  76. }
  77. }
  78. return;
  79. }
  80. }
  81. };
  82. </script>
  83. <style lang="scss" scoped>
  84. .table-view {
  85. .table-header {
  86. display: flex;
  87. padding: 20upx 30upx;
  88. box-shadow: 0px 1px 0px 0px #eeeeee;
  89. color: #999999;
  90. .table-th {
  91. }
  92. }
  93. .table-tr {
  94. display: flex;
  95. align-items: center;
  96. padding: 20upx 30upx;
  97. border-bottom: 1px solid #eeeeee;
  98. color: #999999;
  99. .table-td {
  100. .warn {
  101. color: #ffaf1d;
  102. }
  103. .fail {
  104. color: #f51608;
  105. }
  106. .success {
  107. color: #09bb07;
  108. }
  109. .info {
  110. color: #333;
  111. }
  112. }
  113. }
  114. }
  115. </style>