treeNodeNoDedup.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="tree-node">
  3. <view v-for="item in treeData" :key="item.id" class="node-item">
  4. <view class="tree_row" :style="getRowStyle()" @click="handleExpand(item)">
  5. <view class="checkbox_wrap" @click.stop="handleSelect(item)">
  6. <view class="checkbox" :class="{ checked: item.checked, 'half-checked': item.halfChecked }">
  7. <view v-if="(item.checked || item.halfChecked) && item.children && item.children.length > 0" class="checkbox_minus"></view>
  8. <image v-else-if="item.checked && (!item.children || item.children.length === 0)" src="/static/image/publish/correct.png" class="checkbox_check_image" mode="aspectFit"></image>
  9. </view>
  10. </view>
  11. <view class="row_text_container">
  12. <text class="row_text" :class="{ 'leaf-node': !item.children || item.children.length === 0 }">{{ item.name }}</text>
  13. <text v-if="item.userAccount" class="row_account">({{ item.userAccount }})</text>
  14. </view>
  15. <view v-if="item.children && item.children.length > 0" class="expand_icon">
  16. <image src="/static/image/icon/xiala.png" class="expand-arrow" :class="{ expanded: expandedIds.includes(item.id) }" mode="aspectFit"></image>
  17. </view>
  18. </view>
  19. <view v-if="expandedIds.includes(item.id) && item.children && item.children.length > 0" class="children-container">
  20. <TreeNodeNoDedup :tree-data="item.children" :expanded-ids="expandedIds" :level="level + 1"
  21. @toggle-expand="(ids) => $emit('toggle-expand', ids)"
  22. @toggle-select="(item) => $emit('toggle-select', item)" />
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'TreeNodeNoDedup',
  30. props: {
  31. treeData: {
  32. type: Array,
  33. default: () => []
  34. },
  35. expandedIds: {
  36. type: Array,
  37. default: () => []
  38. },
  39. level: {
  40. type: Number,
  41. default: 0
  42. }
  43. },
  44. methods: {
  45. handleExpand(item) {
  46. if (item.children && item.children.length > 0) {
  47. const siblingIds = this.treeData.map(n => n.id);
  48. const isExpanded = this.expandedIds.includes(item.id);
  49. this.$emit('toggle-expand', { itemId: item.id, siblingIds, isExpanded });
  50. }
  51. },
  52. handleSelect(item) {
  53. this.$emit('toggle-select', item);
  54. },
  55. getRowStyle() {
  56. return {
  57. paddingLeft: `${24 + this.level * 48}rpx`
  58. };
  59. }
  60. }
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. .tree-node {
  65. .node-item {
  66. background-color: #FFFFFF;
  67. border-bottom: 2rpx solid #F3F3F3;
  68. &:last-child {
  69. border-bottom: none;
  70. }
  71. }
  72. .tree_row {
  73. display: flex;
  74. align-items: center;
  75. padding: 24rpx;
  76. padding-right: 24rpx;
  77. .checkbox_wrap {
  78. margin-right: 16rpx;
  79. flex-shrink: 0;
  80. .checkbox {
  81. width: 32rpx;
  82. height: 32rpx;
  83. border: 2rpx solid #DCDFE6;
  84. border-radius: 6rpx;
  85. display: flex;
  86. align-items: center;
  87. justify-content: center;
  88. &.checked {
  89. background-color: #2E64FA;
  90. border-color: #2E64FA;
  91. .checkbox_minus {
  92. width: 16rpx;
  93. height: 0;
  94. border-top: 2rpx solid #FFFFFF;
  95. border-bottom: 2rpx solid #FFFFFF;
  96. }
  97. .checkbox_check_image {
  98. width: 32rpx;
  99. height: 32rpx;
  100. }
  101. }
  102. &.half-checked {
  103. background-color: #2E64FA;
  104. border-color: #2E64FA;
  105. .checkbox_minus {
  106. width: 16rpx;
  107. height: 0;
  108. border-top: 2rpx solid #FFFFFF;
  109. border-bottom: 2rpx solid #FFFFFF;
  110. }
  111. }
  112. }
  113. }
  114. .row_text_container {
  115. flex: 1;
  116. display: flex;
  117. align-items: center;
  118. overflow: hidden;
  119. }
  120. .row_text {
  121. font-size: 28rpx;
  122. color: #333333;
  123. &.leaf-node {
  124. color: #666666;
  125. }
  126. }
  127. .row_account {
  128. font-size: 28rpx;
  129. color: #666666;
  130. margin-left: 12rpx;
  131. }
  132. .expand_icon {
  133. flex-shrink: 0;
  134. margin-left: 8rpx;
  135. width: 24rpx;
  136. height: 24rpx;
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. .expand-arrow {
  141. width: 32rpx;
  142. height: 32rpx;
  143. display: inline-block;
  144. transform: rotate(-90deg);
  145. transition: transform 0.3s ease;
  146. &.expanded {
  147. transform: rotate(0deg);
  148. }
  149. }
  150. }
  151. .arrow_right {
  152. font-size: 24rpx;
  153. color: #999999;
  154. flex-shrink: 0;
  155. margin-left: 8rpx;
  156. }
  157. }
  158. .children-container {
  159. border-top: 2rpx solid #F3F3F3;
  160. }
  161. }
  162. </style>