app-table.vue 2.5 KB

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