uni-thead.vue 2.7 KB

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