antd vue tree节点显示徽标数

本例用于角色赋值权限,由于权限粒度到按钮,所以菜单没有设置父子关联,有些设置了子权限的,父级看不出来,需要在节点后边显示出来各级子菜单已设置的数量

  getSelCount(data, node, parent) {
        if (!node.count) {
          node.count = 0
          node.tmp = node.title
          node.scopedSlots = {title: 'custom'}
        }
        if (data.indexOf(node.id) >= 0) {
          if (parent) {
            parent.count++
          } else {
            node.count++
          }
        }
        let count = 0
        if (node.children && node.children.length > 0) {
          node.children.forEach(item => {
            count = this.getSelCount(data, item, node)
          })
        }
        if (parent) {
          parent.count += count
          if (parent.count > 0) {
            // parent.title = parent.tmp + '' + parent.count
          }
          return parent.count
        } else {
          if (node.count > 0) {
            // node.title = node.tmp + '' + node.count
          }
          return node.count
        }

      },

这是一个递归方法,来计算数量,使用node.scopedSlots = {title: ‘custom’} 设置节点内容自定义

    <a-row style="height:100%;">
        <a-col :span="24/appList.length" v-for="app in appList" :key="app.id" :value="app.id">
          <h4>{{app.name}}</h4>
          <a-tree
            v-model="app.checkedKeys"
            multiple
            checkable
            checkStrictly
            :auto-expand-parent="autoExpandParent"
            :expanded-keys="app.expandedKeys"
            :tree-data="app.menus"
            :selected-keys="app.selectedKeys"
            :replaceFields="replaceFields"
            @expand="(expandedKeys)=>{ app.expandedKeys = expandedKeys}"
          >
            <template slot="custom" slot-scope="{ title,count }">
              {{title}}
              <a-badge :count="count" v-if="count>0" :number-style="{
                    backgroundColor: '#fff',
                    color: '#999',
                    boxShadow: '0 0 0 1px #d9d9d9 inset',
                  }"/>
            </template>
          </a-tree>
        </a-col>
      </a-row>

用 template 设置徽标显示数量

获取到数据后计算数量

 sysRoleOwnMenu({id: record.id}).then((res) => {
          if (res.success) {
            this.appList.forEach(app => {
              app.menus.forEach(item => {
                this.getSelCount(res.data, item)
              })
            })
          }
          this.formLoading = false
        })
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值