123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <template>
- <div class="app-container page-nesting">
- <!-- 树形组件start -->
- <div class="grid-content treeDom">
- <div style="text-align: center" class="mb-20">
- <el-button type="primary">添加分组</el-button>
- <el-button type="primary">添加站点</el-button>
- </div>
- <el-input
- placeholder="输入关键字进行过滤"
- v-model="filterText"
- class="mb-20 searchInput"
- >
- <i
- class="el-icon-search el-input__icon"
- slot="suffix"
-
- >
- </i>
- </el-input>
- <el-tree
- class="filter-tree"
- :data="data"
- node-key="id"
- :props="defaultProps"
- :expand-on-click-node="false"
- :render-content="renderContent"
- default-expand-all
- :filter-node-method="filterNode"
- ref="tree"
- >
- </el-tree>
- </div>
- <!-- 树形组件end -->
- <!-- 站点主题start -->
- <div class="grid-content nestingDom" style="width: calc(100% -300px)">
- nestingDom
- </div>
- <!-- 站点主题end -->
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- filterText: "",
- data: [
- {
- label: "一级 1",
- children: [
- {
- label: "二级 1-1",
- },
- {
- label: "二级 1-2",
- },
- {
- label: "二级 1-3",
- },
- {
- label: "二级 1-4",
- },
- ],
- },
- {
- label: "一级 2",
- children: [
- {
- label: "二级 2-1",
- },
- {
- label: "二级 2-2",
- },
- {
- label: "二级 2-3",
- },
- {
- label: "二级 2-4",
- },
- ],
- },
- ],
- defaultProps: {
- children: "children",
- label: "label",
- },
- };
- },
- watch: {
- filterText(val) {
- this.$refs.tree.filter(val);
- },
- },
- methods: {
- filterNode(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- handleNodeClick(data) {
- console.log(data);
- },
- append(data) {
- const newChild = { id: id++, label: "testtest", children: [] };
- if (!data.children) {
- this.$set(data, "children", []);
- }
- data.children.push(newChild);
- },
- remove(node, data) {
- const parent = node.parent;
- const children = parent.data.children || parent.data;
- const index = children.findIndex((d) => d.id === data.id);
- children.splice(index, 1);
- },
- renderContent(h, { node, data, store }) {
- return (
- <span class="custom-tree-node">
- <span>{node.label}</span>
- <span>
- <el-button
- size="mini"
- type="text"
- on-click={() => this.remove(node, data)}
- >
- Delete
- </el-button>
- </span>
- </span>
- );
- },
- },
- };
- </script>
- <style scoped lang="scss">
- .app-container.page-nesting {
- padding: 0;
- background: rgba(0, 0, 0, 0);
- }
- .grid-content {
- background: #fff;
- min-height: calc(100vh - 140px);
- }
- .el-input__inner{
- border-radius:20px!important
- }
- .treeDom {
- width: 270px;
- position: absolute;
- left: 0;
- margin-left: 20px;
- padding: 20px;
-
- .el-icon-search{
- color:#409EFF
- }
- .el-button {
- width: 100px;
- }
- }
- .nestingDom {
- margin-left: 290px;
- }
- </style>
|