最近项目PRD需求如下
有一个树形结构的菜单管理,与官网ant-design-vue
中提供的a-tree
不同
解决方案
这是不修改a-tree
的任何样式文件时出现的icon图标,与项目项目要求不符
若要改成项目PRD要求的那样只需改动一些样式即可
/deep/ .ant-tree li span.ant-tree-switcher{
width:16px;
height:16px;
margin:4px;
// 修改树结构合起的icon
&.ant-tree-switcher_close{
background:url('//assets.2dfire.com/frontend/b415e20fc703838e5a028437366ff22a.png') no-repeat;
background-size:contain;
i{
display: none;
}
}
// 修改树结构展开的icon
&.ant-tree-switcher_open{
background:url('//assets.2dfire.com/frontend/568ca02f82eee05829d276881363c22a.png') no-repeat;
background-size:contain;
i{
display: none;
}
}
}
ant-design-vue
中的a-tree
并未提供操作节点的方法,所以查找了些资料 发现可以用slot重新定义节点的结构,并添加操作方法的按钮
<a-tree
:treeData="allBranchListGetter">
// ....待修改
</a-tree>
...
<script>
const allBranchListGetter = [
{
"key":"99230713",
"title":"万科集团",
// ⚠️重点这这里⚠️每一条数据上都添加scopedSlots属性
"scopedSlots":{
"title":"custom"
},
"children":[
{
"key":"99230992",
"title":"华东区域",
"scopedSlots":{
"title":"custom"
},
"children":[
{
"key":"99230112",
"title":"杭州万科",
"scopedSlots":{
"title":"custom"
},
"children":[],
}
],
},
{
"key":"99230993",
"title":"华南区域",
"scopedSlots":{
"title":"custom"
},
"children":[],
},
{
"key":"99231020",
"title":"华北区域",
"scopedSlots":{
"title":"custom"
},
"children":[],
}
],
}
]
</script>
<a-tree
:treeData="allBranchListGetter">
// ⚠️重点这这里⚠️
<template slot="custom" slot-scope="item">
<div class="tree-view-item">
<span class="tree-view-left">{{ item.title }}</span>
<div class="tree-view-right">
<button class="tree-view-operation" @click.stop="onHandleEditBranchOffice(item)">
<img
src="//assets.2dfire.com/frontend/a7a2aed48cbeac93209d8cf12abb7120.png"
alt="编辑"
/>
</button>
<button
class="tree-view-operation"
@click.stop="onHandleDeleteBranchOffice(item.key)"
>
<img
src="//assets.2dfire.com/frontend/ddb26080b4607970693a064ceef5a672.png"
alt="删除"
/>
</button>
</div>
</div>
</template>
</a-tree>