TreeItem.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!-- TreeItem.vue -->
  2. <template>
  3. <view>
  4. <view class="item_tree frame">
  5. <view class="tree_title" style="width: 100%;" @click="choice(item)">
  6. <view v-if="item.children.length > 0" @click="toggleNode">
  7. <u-icon name="arrow-right" v-if="!expanded"></u-icon>
  8. <u-icon name="arrow-down" v-else></u-icon>
  9. </view>
  10. <view v-else style="width: 32rpx;"></view>
  11. <view class="name_tree_item">{{ item.name }}</view>
  12. </view>
  13. <!-- <view>
  14. <u-button type="primary" size="small" text="确定" @click="choice(item)"></u-button>
  15. </view> -->
  16. </view>
  17. <view v-if="item.children && item.children.length && expanded">
  18. <tree-item style="padding-left: 20rpx;" @confirm="confirm" v-for="child in item.children" :key="child.id"
  19. :item="child"></tree-item>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'TreeItem',
  26. props: ['item'],
  27. data() {
  28. return {
  29. expanded: true // 初始状态为折叠
  30. };
  31. },
  32. methods: {
  33. toggleNode() {
  34. this.expanded = !this.expanded; // 切换展开和折叠状态
  35. },
  36. choice(value) {
  37. this.$emit('confirm', value)
  38. },
  39. confirm(cmpCode) {
  40. this.$emit('confirm', cmpCode)
  41. }
  42. }
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. .item_tree {
  47. display: flex;
  48. align-items: center;
  49. justify-content: space-between;
  50. padding: 30rpx;
  51. // border-bottom: 1rpx solid #dfdfdf;
  52. }
  53. .tree_title {
  54. display: flex;
  55. align-items: center;
  56. padding-left: 20rpx;
  57. }
  58. .name_tree_item {
  59. width: 60%;
  60. margin-left: 10rpx;
  61. font-size: 30rpx;
  62. white-space: nowrap;
  63. text-overflow: ellipsis;
  64. overflow: hidden;
  65. }
  66. </style>