easyUl tree 做 select 下拉多选

8 篇文章 1 订阅
4 篇文章 0 订阅
elementui的树型在手机端看  复选框点击第一下 只选中了 边框 不触发事件且出现是随机的,没找到解决的办法,只能换一种方式解决现有的问题
找了easyui的 tree 重新来一个

子组件
<style lang="scss">
    .tree {
        text-align: left;
        position: absolute;
        top: 6px;
        left: 0;
        z-index: 1030;
        background: #ffffff;
        max-height: 200px;
        min-height: 30px;
        overflow-y: auto;
        overflow-x: hidden;
        border: 1px solid #dddddd;
        width: calc(100% - 2px);
    }
    .tree-node{
        height: 30px;
    }
    .span-tx {
        line-height: 20px;
    }

    .span-g {
        padding: 2px 5px;
        border-radius: 3px;
        color: #ffffff;
        margin-left: 3px;

        &.span-1 {
            background: #909399;
        }

        &.span0 {
            background: #409eff;
        }

        &.span1 {
            background: #67C23A;
        }

        &.span2 {
            background: #E6A23C;
        }
    }

</style>
<template>
    <Tree :data="treeNodes" :checkbox="true" @checkChange="checkHandle">
        <template slot-scope="scope">
            <span class="span-tx">{{scope.node.name}}</span>
            <span class="span-g" :class="[scope.node.authType === '0' ? 'span0' : '']"
                  v-if="scope.node.authType === '0'">事业部</span>
            <span class="span-g" :class="[scope.node.authType === '-1' ? 'span-1' : '']"
                  v-if="scope.node.authType === '-1'">集团</span>
            <span class="span-g" :class="[scope.node.authType === '1' ? 'span1' : '']"
                  v-if="scope.node.authType === '1'">组织</span>
            <span class="span-g" :class="[scope.node.authType === '2' ? 'span2' : '']"
                  v-if="scope.node.authType === '2'">管理区域</span>
        </template>
    </Tree>
</template>

<script>
  export default {
    name: 'tree-select',
    data() {
      return {
        checkedNodes: null,
        treeNodes: [],
      };
    },
    created() {
      this.$ajax({
        url: '/user/auth-tree',
        method: 'get',
      }).then((d) => {
        //加上根节点
        let rootNode = {
          authType: "-1",
          name: "集团",
          checked: false,
          state: "closed",
          code: "-1"
        };
        let or = this.loop(d);
        rootNode.children = this.loop(d);
        this.treeNodes = [rootNode];
        console.log(this.treeNodes, '<---treeNodes');
      }).catch(() => {
      });
    },
    methods: {
      checkHandle(node) {
        let codeArr = [];
        node.map(item => {
          codeArr.push(item.code);
        });
        this.$emit('select-value', codeArr);
      },
      loop(children) {
        if (children && children.length > 0) {
          children.map(item => {
            if (item.children && item.children.length > 0) {
              item.state = 'closed'
            }
            if (item.children && item.children.length > 0) {
              this.loop(item.children);
            }
          });
        }
        return children
      }
    }
  };
</script>

父组件:

<tree-select @select-value="selectValueHandle"></tree-select>
.tree-ul {
  padding: 0 10px;
  .tree-box {
    position: relative;
    padding: 6px 10px 12px;
    height: 48px;
  }
}

tree-ul 主要是将tree浮起来

仅用于本人项目记录备份

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值