去掉小三角、添加图片、加上连接虚线

  1. <template>
  2. <view class="jg-box">
  3. <div class="jiegou-box">
  4. <el-tree class="tree-line" :data="data" :props="defaultProps" @node-click="handleNodeClick" :default-expand-all="true">
  5. <span class="custom-tree-node" slot-scope="{ node,data }">
  6. <span :data="data.name" style="display: flex;align-items: center;">
  7. <image :src="data.icon" style="width: 24px; height: 20px;margin-right: 6px;" v-if="data.id == 100"></image>
  8. <image :src="data.icon" style="width: 18px; height: 20px;margin-right: 6px;" v-else></image>
  9. <!-- <i :class="data.icon" style="background-color: #4d4d4d;color: #fff;"></i> -->{{data.name}}
  10. </span>
  11. </span>
  12. </el-tree>
  13. </div>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'tree',
  19. data() {
  20. return {
  21. data: [{
  22. name: '一级 1',
  23. icon: 'el-icon-folder-opened',//这时icon是图标,之后在我获取后台的数据后更改了换成了图片路径
  24. children: [{
  25. name: '二级 1-1',
  26. icon: 'el-icon-document',
  27. },
  28. {
  29. name: '二级 1-2',
  30. icon: 'el-icon-document',
  31. },
  32. {
  33. name: '二级 1-3',
  34. icon: 'el-icon-document',
  35. },
  36. {
  37. name: '二级 1-4',
  38. icon: 'el-icon-document',
  39. },
  40. ]
  41. }],
  42. defaultProps: {
  43. children: 'children',
  44. label: 'name'
  45. }
  46. }
  47. },
  48. methods: {
  49. handleNodeClick(data) {//点击节点获取该节点的数据
  50. let id = data.id
  51. console.log(data)
  52. }
  53. },
  54. mounted() {
  55. let that = this;
  56. uni.request({
  57. url: address.getDeptPicture,
  58. method: "POST",
  59. success(res) {
  60. let data1 = ""
  61. data1 = res.data.data;
  62. data1.forEach((value, index) => {//遍历后台的数据给数据加上'icon'图片路径(因为后台的数据中没有这个字段,所以我需要加上icon)
  63. value['icon'] = '../../static/dk-Folder.png'//将小三角换成图片
  64. //console.log(value.children)
  65. value.children.forEach((value1, index) => {
  66. value1['icon'] = '../../static/dk-File.png'
  67. })
  68. })
  69. that.data = data1
  70. console.log(data1)
  71. },
  72. })
  73. }
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .jiegou-box {
  78. display: flex;
  79. justify-content: space-between;
  80. width: 91.14%;
  81. height: 870px;
  82. background: rgba(255, 255, 255, 0.6);
  83. margin-left: 4.43%;
  84. .tree-left {
  85. margin-top: 30px;
  86. margin-left: 30px;
  87. }
  88. }
  89. .edit-fields:nth-child(2) {
  90. font-size: 18px !important;
  91. color: red;
  92. }
  93. /*去掉elementui tree前面的小三角*/
  94. /deep/.el-tree .el-tree-node__expand-icon.expanded // 取消旋转
  95. {
  96. -webkit-transform: rotate(0deg);
  97. transform: rotate(0deg);
  98. }
  99. /deep/ .el-tree .el-icon-caret-right:before {
  100. content: "";
  101. font-size: 18px;
  102. margin-left: 4px;
  103. }
  104. /deep/ .el-tree .el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
  105. content: "";
  106. font-size: 18px;
  107. margin-right: 4px;
  108. }
  109. /*改变每个节点的行高*/
  110. /deep/.el-tree-node__content {
  111. min-height: 35px;
  112. }
  113. /deep/ .el-tree {
  114. background: none;
  115. }
  116. /*加上虚线链接*/
  117. .tree-line {
  118. font-size: 18px;
  119. /deep/ .el-tree-node {
  120. position: relative;
  121. color: #4D4D4D;
  122. }
  123. /deep/ .el-tree-node__children {
  124. padding-left: 16px; // 缩进量
  125. font-size: 16px !important;
  126. }
  127. // 竖线
  128. /deep/ .el-tree-node::before {
  129. content: "";
  130. height: 100%;
  131. width: 1px;
  132. position: absolute;
  133. left: -3px;
  134. top: -26px;
  135. border-width: 1px;
  136. border-left: 1px dashed #52627C;
  137. }
  138. // 当前层最后一个节点的竖线高度固定
  139. /deep/ .el-tree-node:last-child::before {
  140. height: 38px; // 可以自己调节到合适数值
  141. }
  142. // 横线
  143. /deep/ .el-tree-node::after {
  144. content: "";
  145. width: 30px;
  146. height: 20px;
  147. position: absolute;
  148. left: -3px;
  149. top: 18px;
  150. border-width: 1px;
  151. border-top: 1px dashed #52627C;
  152. }
  153. // 去掉最顶层的虚线,放最下面样式才不会被上面的覆盖了
  154. /deep/ &>.el-tree-node::after {
  155. border-top: none;
  156. }
  157. /deep/ &>.el-tree-node::before {
  158. border-left: none;
  159. }
  160. // 展开关闭的icon
  161. /deep/ .el-tree-node__expand-icon {
  162. font-size: 16px;
  163. // 叶子节点(无子节点)
  164. /deep/ &.is-leaf {
  165. color: transparent;
  166. // display: none; // 也可以去掉
  167. }
  168. }
  169. }
  170. </style>