index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div class="app-container page-nesting">
  3. <!-- 树形组件start -->
  4. <div class="grid-content treeDom">
  5. <div style="text-align: center" class="mb-20">
  6. <el-button type="primary">添加分组</el-button>
  7. <el-button type="primary">添加站点</el-button>
  8. </div>
  9. <el-input
  10. placeholder="输入关键字进行过滤"
  11. v-model="filterText"
  12. class="mb-20 searchInput"
  13. >
  14. <i
  15. class="el-icon-search el-input__icon"
  16. slot="suffix"
  17. >
  18. </i>
  19. </el-input>
  20. <el-tree
  21. class="filter-tree"
  22. :data="data"
  23. node-key="id"
  24. :props="defaultProps"
  25. :expand-on-click-node="false"
  26. :render-content="renderContent"
  27. default-expand-all
  28. :filter-node-method="filterNode"
  29. ref="tree"
  30. >
  31. </el-tree>
  32. </div>
  33. <!-- 树形组件end -->
  34. <!-- 站点主题start -->
  35. <div class="grid-content nestingDom" style="width: calc(100% -300px)">
  36. nestingDom
  37. </div>
  38. <!-- 站点主题end -->
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. filterText: "",
  46. data: [
  47. {
  48. label: "一级 1",
  49. children: [
  50. {
  51. label: "二级 1-1",
  52. },
  53. {
  54. label: "二级 1-2",
  55. },
  56. {
  57. label: "二级 1-3",
  58. },
  59. {
  60. label: "二级 1-4",
  61. },
  62. ],
  63. },
  64. {
  65. label: "一级 2",
  66. children: [
  67. {
  68. label: "二级 2-1",
  69. },
  70. {
  71. label: "二级 2-2",
  72. },
  73. {
  74. label: "二级 2-3",
  75. },
  76. {
  77. label: "二级 2-4",
  78. },
  79. ],
  80. },
  81. ],
  82. defaultProps: {
  83. children: "children",
  84. label: "label",
  85. },
  86. };
  87. },
  88. watch: {
  89. filterText(val) {
  90. this.$refs.tree.filter(val);
  91. },
  92. },
  93. methods: {
  94. filterNode(value, data) {
  95. if (!value) return true;
  96. return data.label.indexOf(value) !== -1;
  97. },
  98. handleNodeClick(data) {
  99. console.log(data);
  100. },
  101. append(data) {
  102. const newChild = { id: id++, label: "testtest", children: [] };
  103. if (!data.children) {
  104. this.$set(data, "children", []);
  105. }
  106. data.children.push(newChild);
  107. },
  108. remove(node, data) {
  109. const parent = node.parent;
  110. const children = parent.data.children || parent.data;
  111. const index = children.findIndex((d) => d.id === data.id);
  112. children.splice(index, 1);
  113. },
  114. renderContent(h, { node, data, store }) {
  115. return (
  116. <span class="custom-tree-node">
  117. <span>{node.label}</span>
  118. <span>
  119. <el-button
  120. size="mini"
  121. type="text"
  122. on-click={() => this.remove(node, data)}
  123. >
  124. Delete
  125. </el-button>
  126. </span>
  127. </span>
  128. );
  129. },
  130. },
  131. };
  132. </script>
  133. <style scoped lang="scss">
  134. .app-container.page-nesting {
  135. padding: 0;
  136. background: rgba(0, 0, 0, 0);
  137. }
  138. .grid-content {
  139. background: #fff;
  140. min-height: calc(100vh - 140px);
  141. }
  142. .el-input__inner{
  143. border-radius:20px!important
  144. }
  145. .treeDom {
  146. width: 270px;
  147. position: absolute;
  148. left: 0;
  149. margin-left: 20px;
  150. padding: 20px;
  151. .el-icon-search{
  152. color:#409EFF
  153. }
  154. .el-button {
  155. width: 100px;
  156. }
  157. }
  158. .nestingDom {
  159. margin-left: 290px;
  160. }
  161. </style>