merge.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <script setup lang="ts">
  2. interface User {
  3. id: string;
  4. name: string;
  5. amount1: string;
  6. amount2: string;
  7. amount3: number;
  8. }
  9. interface SpanMethodProps {
  10. row: User;
  11. column: any;
  12. rowIndex: number;
  13. columnIndex: number;
  14. }
  15. const arraySpanMethod = ({ rowIndex, columnIndex }: SpanMethodProps) => {
  16. if (rowIndex % 2 === 0) {
  17. if (columnIndex === 0) {
  18. return [1, 2];
  19. } else if (columnIndex === 1) {
  20. return [0, 0];
  21. }
  22. }
  23. };
  24. const objectSpanMethod = ({ rowIndex, columnIndex }: SpanMethodProps) => {
  25. if (columnIndex === 0) {
  26. if (rowIndex % 2 === 0) {
  27. return {
  28. rowspan: 2,
  29. colspan: 1
  30. };
  31. } else {
  32. return {
  33. rowspan: 0,
  34. colspan: 0
  35. };
  36. }
  37. }
  38. };
  39. const tableData: User[] = [
  40. {
  41. id: "12987122",
  42. name: "Tom",
  43. amount1: "234",
  44. amount2: "3.2",
  45. amount3: 10
  46. },
  47. {
  48. id: "12987123",
  49. name: "Tom",
  50. amount1: "165",
  51. amount2: "4.43",
  52. amount3: 12
  53. },
  54. {
  55. id: "12987124",
  56. name: "Tom",
  57. amount1: "324",
  58. amount2: "1.9",
  59. amount3: 9
  60. },
  61. {
  62. id: "12987125",
  63. name: "Tom",
  64. amount1: "621",
  65. amount2: "2.2",
  66. amount3: 17
  67. },
  68. {
  69. id: "12987126",
  70. name: "Tom",
  71. amount1: "539",
  72. amount2: "4.1",
  73. amount3: 15
  74. }
  75. ];
  76. const columns: TableColumnList = [
  77. {
  78. label: "ID",
  79. prop: "id"
  80. },
  81. {
  82. label: "Name",
  83. prop: "name"
  84. },
  85. {
  86. label: "Amount 1",
  87. prop: "amount1",
  88. sortable: true
  89. },
  90. {
  91. label: "Amount 2",
  92. prop: "amount2",
  93. sortable: true
  94. },
  95. {
  96. label: "Amount 3",
  97. prop: "amount3",
  98. sortable: true
  99. }
  100. ];
  101. </script>
  102. <template>
  103. <div>
  104. <pure-table
  105. :data="tableData"
  106. :columns="columns"
  107. :span-method="arraySpanMethod"
  108. border
  109. />
  110. <pure-table
  111. :data="tableData"
  112. :columns="columns"
  113. :span-method="objectSpanMethod"
  114. border
  115. />
  116. </div>
  117. </template>