uni-thead.vue 2.7 KB

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