淘先锋技术网

首页 1 2 3 4 5 6 7

数据内容

{
      "id": "1",
      "parentId": "0",
      "menuName": "xx",
      "menuType": "1",
      "menuLevel": "1",
      "menuUrl": "",
      "iconUrl": "",
      "sortNum": "0",
      "isShow": "1",
      "createUserId": null,
      "modifiedUserId": null,
      "gmtCreate": 1578035996000,
      "gmtModified": 1578036173000,
      "isDeleted": 0,
      "children": [
        {
          "id": "6",
          "parentId": "1",
          "menuName": "xx",
          "menuType": "1",
          "menuLevel": "2",
          "menuUrl": "",
          "iconUrl": "",
          "sortNum": "0",
          "isShow": "1",
          "createUserId": null,
          "modifiedUserId": null,
          "gmtCreate": 1578036266000,
          "gmtModified": 1578036336000,
          "isDeleted": 0,
          "children": null
        }
}

    /**
    * 递归的方式将树形结构处理,如: 
    * this.setDisable(1, this.parentMenuList, 2)// 限制2级以后不可选中
    * count: 当前层级
    * data: 当前层级的数据
    * maxNum: 最多不能超过几级,超过2级,不能选中,
    */
    setDisable(count, data, maxNum) {
      if (count > maxNum) { //最多几级就写几
        data.forEach(v => {
          v.disabled = true // 超过设定的最大级数,给这一集的数据添加disabled属性
        })
      } else {
        data.forEach(v => {
          v.count = count // 设置最外层数据的初始count
          if (v.children && v.children.length) {
            this.setDisable(count + 1, v.children, maxNum) // 子级循环时把这一层数据的count传入
          }
        })
      }
    },
 //级联选择器数据获取,并清空一选择数据
    getParentMenuList() {
      this.selectedParentMenuKeys = [] // 清空级联已经选择数据
      getMenuListTree(this.getListParams).then(res => {
        this.parentMenuList = res.data.data
        // 限制2级以后不可选中
        this.setDisable(1, this.parentMenuList, 2)
        console.log(this.parentMenuList);
      }).catch(err => {
        console.log(err);
      })
    },