zwx-dropDown.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view style="padding-left: 30rpx;">
  3. <view class="dropDown">
  4. <view class="dropList" v-for="(item,index) in tree" :key="index">
  5. <view class="childrenContent parentnodePadding">
  6. <view :data-index="index" :data-id="item.id" :data-name="item.name" class="parentnode" @click="switchClick">
  7. <i
  8. :class="item.open?'iconfont el-icon-thirdiconfonti-copy iconactive openicon':' iconfont el-icon-thirdiconfonti openicon'"></i>
  9. <text :class="item.open?'iconactive':''">{{item.name}}</text>
  10. </view>
  11. <view v-if="item.file&&item.file.length>0&&item.open">
  12. <view v-for="(fileitem,fileindex) in item.file" :key="fileindex">
  13. <view :data-id="fileitem.fileid" :data-name="fileitem.name" class="fileclass" @click="filechange">
  14. <i class="iconfont el-icon-thirdwenjian"></i>
  15. <text>{{fileitem.name}}</text>
  16. </view>
  17. </view>
  18. </view>
  19. <dropDown v-if="item.children&&item.children.length>0 &&item.open" :node="item.children" @nodechange='switchClick' @filechange="filechange">
  20. </dropDown>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import dropDown from '@/uni_modules/zwx-dropDown/components/zwx-dropDown/zwx-dropDown'
  28. export default {
  29. name: 'dropDown',
  30. components: {
  31. dropDown
  32. },
  33. props: {
  34. node: {
  35. type: Array,
  36. default: () => []
  37. },
  38. isshowAll: {
  39. type: Boolean,
  40. default: true
  41. },
  42. ischeckedAll: {
  43. type: Boolean,
  44. default: true
  45. }
  46. },
  47. data() {
  48. return {
  49. tree: [],
  50. }
  51. },
  52. mounted() {
  53. this.tree = this.node;
  54. },
  55. methods: {
  56. switchClick(e) {
  57. const id = e.currentTarget.dataset.id;
  58. const index = e.currentTarget.dataset.index;
  59. this.$emit('nodechange', e)
  60. this.recursion(id, this.tree,e);
  61. },
  62. filechange(e){
  63. this.$emit("filechange",e)
  64. },
  65. async recursion(id, arr,e) {
  66. let _id = id
  67. await arr.forEach((item) => {
  68. if (item.id === _id) {
  69. let openstatus = item.open
  70. item.open = !openstatus;
  71. };
  72. })
  73. this.$nextTick(function() {
  74. this.tree = arr;
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style>
  81. @import url("./css/iconfont.css");
  82. .childrenContent {
  83. padding: 20rpx 50rpx 0 0;
  84. display: flex;
  85. /* align-items: flex-start; */
  86. flex-direction: column;
  87. }
  88. .childrenContent .parentnode {
  89. display: flex;
  90. align-items: center;
  91. }
  92. .childrenContent .parentnodePadding {
  93. margin-left: 10rpx;
  94. }
  95. .childrenContent .checkedFile {
  96. margin-left: 40rpx;
  97. }
  98. .childrenContent .iconfont {
  99. font-size: 30rpx;
  100. margin-right: 10rpx;
  101. }
  102. .childrenContent .iconactive {
  103. color: #007AFF;
  104. }
  105. .childrenContent .openicon {
  106. font-size: 40rpx;
  107. }
  108. .childrenContent .fileclass {
  109. display: flex;
  110. align-items: center;
  111. font-size: 26rpx;
  112. padding: 10rpx 0;
  113. padding-left: 50rpx;
  114. }
  115. .childrenContent .fileclass .iconfont {
  116. font-size: 24rpx;
  117. }
  118. </style>