后端那些奇特需求1---设备树

需求:在调用远程的开关的

思路启发:

elementUI中Tree树形控件点击叶子节点才触发 - 百度文库

简述:设备是放在子组件的,开关的按钮是在父组件的==>采用了事件总线(不细讲);

子组件

<!-- 输入框 -->
      <el-input placeholder="输入关键字进行过滤"
        size="mini"
        suffix-icon="el-icon-search"
        v-model="filterText">
      </el-input>
      <el-tree class="filter-tree scrollBar"
        :data="deviceData"
        ref="tree"
        :props="defaultProps"
        accordion
        :default-expanded-keys="[1]"
        node-key="name"
        :highlight-current="true"
        :filter-node-method="filterNode"
        style="overflow: auto; font-size: 14px"
        @node-click="handleNodeClick"></el-tree>

---------------------------------
    handleNodeClick (val) {
      let node = this.$refs.tree.getNode(val.name)
      // 如果设备树的节点的长度等于0,说明就是子节点,并且子节点的层级不是1级和2级根节点
      if (node.childNodes.length === 0 && (node.level !== 1 && node.level !== 2)) {
        this.poitDevice = node
        this.$bus.$emit('openClick', node, true)
      } else {
        this.poitDevice = {}
        this.$bus.$emit('openClick', this.poitDevice, false)
        // 
      }
    }

 父组件:

mounted(){
 this.$bus.$on('openClick', this.clickDevice)
}

补充: (暂不细讲--待更新)
beforeDestroy () {
    this.$bus.$off('openClick', this.clickDevice)
  },

--------------------------------------
   clickDevice (msg, open) {
      console.log("我接受到传递来的设备", msg, open);
      this.deviceMsg = msg
      this.clicOrnot = open
    },


---------------------------方法:
  OpenclickDevice () {
      if (!this.clicOrnot) {
        this.$message.info("请先选择设备")
      } else {

        let data = {
          deviceVendor: this.deviceMsg.data.deviceVendor,
          id: this.deviceMsg.data.deviceCode,
          internal: this.formTime.time
        }
        remoteOpen(data).then(res => {
          if (res.code == 200) {
            this.$message.info("远程开门成功")
            this.deviceMsg = {}  //释放内存
            this.clicOrnot = false
          }
        }).catch(error => {
          this.$message.error(JSON.stringify(error))
        })
      }
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值