uni-thead.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. root: Object,
  29. border: false,
  30. selection: false,
  31. rowspan: 1,
  32. indeterminate: false,
  33. checked: false
  34. }
  35. },
  36. created() {
  37. this.root = this.getTable() as UniTableComponentPublicInstance
  38. // #ifdef H5
  39. this.root.theadChildren = this
  40. // #endif
  41. this.border = this.root != null ? (this.root as UTSJSONObject)?.['border'] as boolean : false;
  42. this.selection = this.root != null ? (this.root as UTSJSONObject)?.['type'] as boolean : false;
  43. },
  44. methods: {
  45. init(self:UniTheadComponentPublicInstance) {
  46. this.rowspan++
  47. },
  48. checkboxSelected(e:Event) {
  49. this.indeterminate = false
  50. const backIndexData = (this.root as UniTableComponentPublicInstance).backIndexData;
  51. const trChildren = (this.root as UniTableComponentPublicInstance).trChildren;
  52. const data = trChildren.filter(v => (v as UniTrComponentPublicInstance)?.disabled ==null && (v as UTSJSONObject)?.['keyValue']!=null)
  53. if (backIndexData.length === data.length) {
  54. this.checked = false
  55. let root = this.root as UniTableComponentPublicInstance
  56. root.clearSelection()
  57. } else {
  58. this.checked = true
  59. let root = this.root as UniTableComponentPublicInstance
  60. root.selectionAll()
  61. }
  62. },
  63. /**
  64. * 获取父元素实例
  65. */
  66. getTable(name = 'uniTable') {
  67. let parent = this.$parent
  68. let parentName = parent?.$options?.name ?? ''
  69. while (parentName !== name) {
  70. parent = parent?.$parent ?? null
  71. if (parent==null) return false
  72. parentName = parent?.$options?.name as string
  73. }
  74. return parent
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss">
  80. $border-color: #ebeef5;
  81. .uni-table-thead {
  82. /* #ifdef APP-ANDROID */
  83. display: flex;
  84. /* #endif */
  85. /* #ifndef APP-ANDROID */
  86. display: table-header-group;
  87. /* #endif */
  88. }
  89. .uni-table-tr {
  90. /* #ifndef APP-ANDROID */
  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. color: #333;
  103. /* #ifndef APP-ANDROID */
  104. display: table-cell;
  105. font-weight: 500;
  106. vertical-align: middle;
  107. /* #endif */
  108. /* #ifdef APP-ANDROID */
  109. font-weight: bold;
  110. /* #endif */
  111. border-bottom: 1px $border-color solid;
  112. font-size: 14px;
  113. // text-align: center;
  114. }
  115. .tr-table--border {
  116. border-right: 1px $border-color solid;
  117. }
  118. /* #ifndef APP-NVUE */
  119. .uni-table-tr {
  120. ::v-deep .uni-table-th {
  121. &.table--border:last-child {
  122. // border-right: none;
  123. }
  124. }
  125. ::v-deep .uni-table-td {
  126. &.table--border:last-child {
  127. // border-right: none;
  128. }
  129. }
  130. }
  131. /* #endif */
  132. </style>