uni-thead.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <thead class="uni-table-thead">
  4. <tr class="uni-table-tr">
  5. <th :rowspan="rowspan" colspan="1" class="checkbox" :class="{ 'tr-table--border': border }">
  6. <table-checkbox :indeterminate="indeterminate" :checked="checked"
  7. @checkboxSelected="checkboxSelected"></table-checkbox>
  8. </th>
  9. </tr>
  10. <slot></slot>
  11. </thead>
  12. <!-- #endif -->
  13. <!-- #ifndef H5 -->
  14. <view class="uni-table-thead">
  15. <slot></slot>
  16. </view>
  17. <!-- #endif -->
  18. </template>
  19. <script>
  20. import tableCheckbox from '../uni-tr/table-checkbox.vue'
  21. export default {
  22. name: 'uniThead',
  23. components: {
  24. tableCheckbox
  25. },
  26. options: {
  27. // #ifdef MP-TOUTIAO
  28. virtualHost: false,
  29. // #endif
  30. // #ifndef MP-TOUTIAO
  31. virtualHost: true
  32. // #endif
  33. },
  34. data() {
  35. return {
  36. border: false,
  37. selection: false,
  38. rowspan: 1,
  39. indeterminate: false,
  40. checked: false
  41. }
  42. },
  43. created() {
  44. this.root = this.getTable()
  45. // #ifdef H5
  46. this.root.theadChildren = this
  47. // #endif
  48. this.border = this.root.border
  49. this.selection = this.root.type
  50. },
  51. methods: {
  52. init(self) {
  53. this.rowspan++
  54. },
  55. checkboxSelected(e) {
  56. this.indeterminate = false
  57. const backIndexData = this.root.backIndexData
  58. const data = this.root.trChildren.filter(v => !v.disabled && v.keyValue)
  59. if (backIndexData.length === data.length) {
  60. this.checked = false
  61. this.root.clearSelection()
  62. } else {
  63. this.checked = true
  64. this.root.selectionAll()
  65. }
  66. },
  67. /**
  68. * 获取父元素实例
  69. */
  70. getTable(name = 'uniTable') {
  71. let parent = this.$parent
  72. let parentName = parent.$options.name
  73. while (parentName !== name) {
  74. parent = parent.$parent
  75. if (!parent) return false
  76. parentName = parent.$options.name
  77. }
  78. return parent
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. $border-color: #ebeef5;
  85. .uni-table-thead {
  86. display: table-header-group;
  87. }
  88. .uni-table-tr {
  89. /* #ifndef APP-NVUE */
  90. display: table-row;
  91. transition: all 0.3s;
  92. box-sizing: border-box;
  93. /* #endif */
  94. border: 1px red solid;
  95. background-color: #fafafa;
  96. }
  97. .checkbox {
  98. padding: 0 8px;
  99. width: 26px;
  100. padding-left: 12px;
  101. /* #ifndef APP-NVUE */
  102. display: table-cell;
  103. vertical-align: middle;
  104. /* #endif */
  105. color: #333;
  106. font-weight: 500;
  107. border-bottom: 1px $border-color solid;
  108. font-size: 14px;
  109. // text-align: center;
  110. }
  111. .tr-table--border {
  112. border-right: 1px $border-color solid;
  113. }
  114. /* #ifndef APP-NVUE */
  115. .uni-table-tr {
  116. ::v-deep .uni-table-th {
  117. &.table--border:last-child {
  118. // border-right: none;
  119. }
  120. }
  121. ::v-deep .uni-table-td {
  122. &.table--border:last-child {
  123. // border-right: none;
  124. }
  125. }
  126. }
  127. /* #endif */
  128. </style>