table-span.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <table class="com-table">
  3. <thead>
  4. <tr>
  5. <th v-for="(col, index) of data.column" :key="index" :class="{ light: col.is_light }">{{ col.name }}<br v-if="col.unit != ''" />{{ col.unit }}</th>
  6. </tr>
  7. </thead>
  8. <tbody>
  9. <tr v-for="(row, index) of data.data" :key="index">
  10. <td :rowspan="rowspan(row, col)" :colspan="colspan(row, col)" v-for="(col, i) of data.column" :key="i" :class="{ light: col.is_light || row.is_light, num: col.is_num, remove: row[col.field] == '' }">
  11. {{ row[col.field] }}
  12. </td>
  13. </tr>
  14. </tbody>
  15. </table>
  16. </template>
  17. <script>
  18. export default {
  19. // 名称
  20. name: "ComTable",
  21. // 使用组件
  22. components: {},
  23. // 传入参数
  24. props: {
  25. data: Object,
  26. },
  27. // 自定义事件
  28. emits: {},
  29. // 数据
  30. data() {
  31. return {};
  32. },
  33. computed: {},
  34. // 函数
  35. methods: {
  36. rowspan: function(row, col) {
  37. if (row.row_span.length == 0) {
  38. return 1;
  39. } else {
  40. let row_span = row.row_span.find((t) => t[0] == col.field);
  41. if (row_span) {
  42. return row_span[1];
  43. } else {
  44. return 1;
  45. }
  46. }
  47. },
  48. colspan: function(row, col) {
  49. if (row.col_span.length == 0) {
  50. return 1;
  51. } else {
  52. let col_span = row.col_span.find((t) => t[0] == col.field);
  53. if (col_span) {
  54. return col_span[1];
  55. } else {
  56. return 1;
  57. }
  58. }
  59. },
  60. },
  61. // 生命周期钩子
  62. beforeCreate() {
  63. // 创建前
  64. },
  65. created() {
  66. // 创建后
  67. },
  68. beforeMount() {
  69. // 渲染前
  70. },
  71. mounted() {
  72. // 渲染后
  73. },
  74. beforeUpdate() {
  75. // 数据更新前
  76. },
  77. updated() {
  78. // 数据更新后
  79. },
  80. };
  81. </script>
  82. <style lang="less">
  83. @titleGray: #9ca5a8;
  84. @rowGray: #606769;
  85. @darkBack: #536268;
  86. .com-table {
  87. width: 100%;
  88. border-collapse: collapse;
  89. thead {
  90. tr {
  91. th {
  92. background-color: fade(@darkBack, 60%);
  93. padding: 0.741vh 0;
  94. color: @titleGray;
  95. font-weight: 400;
  96. font-size: @fontsize-s;
  97. position: sticky;
  98. top: 0;
  99. &.light {
  100. color: @green;
  101. }
  102. }
  103. }
  104. }
  105. tbody {
  106. tr {
  107. &:nth-child(2n) {
  108. background-color: fade(@rowGray, 20%);
  109. }
  110. td {
  111. padding: 0.556vh 0;
  112. color: @rowGray;
  113. text-align: center;
  114. font-size: @fontsize-s;
  115. &.light {
  116. color: @green;
  117. }
  118. &.num {
  119. font-family: "Bicubik";
  120. font-weight: 400;
  121. }
  122. &.remove {
  123. display: none;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. </style>