平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uni-thead.vue 2.5 KiB

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