田源
2023-10-10 820dde03b508f1ca6436cacf517ff197e1875f4f
集成系统信息管理-分类授权-重置、展开所有节点多选父节点增删
已修改1个文件
126 ■■■■ 文件已修改
Source/UBCS-WEB/src/views/integration/systemInfo.vue 126 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS-WEB/src/views/integration/systemInfo.vue
@@ -40,7 +40,7 @@
      <div slot="footer" class="dialog-footer" style="height: 50px;line-height: 50px">
        <el-button icon="el-icon-plus" size="small" type="primary" @click="empower">授 权</el-button>
        <el-button icon="el-icon-close" size="small" type="danger">重 置</el-button>
        <el-button icon="el-icon-close" size="small" type="danger" @click="resetting">重 置</el-button>
      </div>
    </el-dialog>
  </basic-container>
@@ -140,6 +140,11 @@
  created() {
  },
  methods: {
    //重置
    resetting(){
      this.$refs.tree.setCheckedKeys([])
      // console.log(this.ParentList)
    },
    empower() {
      batchAddSave(this.checkAll.oid, this.checkAll.id, this.ParentList).then(res => {
        // console.log(res.data)
@@ -151,76 +156,65 @@
    },
    //分类授权多选回调
    checkChange(row, checked) {
      // this.ParentList=[]
      // console.log('row',row)
      if (checked) {
        if (!row.parentId) {
          const parentRecord = {
            oid: row.oid,
            classifyId: row.attributes.classifyId,
            classifyOid: row.attributes.classifyOid,
            classParentOid: row.parentId,
          };
          this.ParentList.push(parentRecord);
          // 如果row的children不为空 继续循环children中的每个对象
          if (row.children && row.children.length > 0) {
            for (let child of row.children) {
              const childRecord = {
                oid: child.oid,
                classifyId: child.attributes.classifyId,
                classifyOid: child.attributes.classifyOid,
                classParentOid: child.parentId,
              };
              this.ParentList.push(childRecord);
              // 如果子对象的children不为空 继续循环获取数据
              if (child.children && child.children.length > 0) {
                for (let subChild of child.children) {
                  const subRecord = {
                    oid: subChild.oid,
                    classifyId: subChild.attributes.classifyId,
                    classifyOid: subChild.attributes.classifyOid,
                    classParentOid: subChild.parentId,
                  };
                  this.ParentList.push(subRecord);
                }
              }
            }
          }
        }
        this.addAllChildren(row.children);
        this.addToParentList(row);
        // 勾选行时,将当前行以及其所有子节点添加到ParentList中
      } else {
        // 取消勾选的节点是父节点
        if (!row.parentId) {
          // 找到父节点在ParentList中的索引
          const parentIndex = this.ParentList.findIndex(item => item.oid === row.oid);
          if (parentIndex !== -1) {
            const parentOid = this.ParentList[parentIndex].classifyOid;
        this.removeAllChildren(row.children);
        this.removeFromParentList(row);
        // 取消勾选行时,将当前行以及其所有子节点从ParentList中移除
      }
            // 查找所有需要删除的子节点的索引
            const childIndexes = this.ParentList.reduce((indexes, item, index) => {
              if (item.classParentOid === parentOid && item.classifyOid !== parentOid) {
                indexes.push(index);
              }
              return indexes;
            }, []);
            // 从后往前删除子节点的数据,保证索引的正确性
            for (let i = childIndexes.length - 1; i >= 0; i--) {
              this.ParentList.splice(childIndexes[i], 1);
            }
            // 删除父节点的数据
            this.ParentList.splice(parentIndex, 1);
          }
        } else {
          // 取消勾选的节点是子节点
          const childIndex = this.ParentList.findIndex(item => item.oid === row.oid);
          if (childIndex !== -1) {
            // 删除子节点的数据
            this.ParentList.splice(childIndex, 1);
          }
      // console.table(this.ParentList);
    },
    addAllChildren(children) {
      for (let child of children) {
        this.addToParentList(child);
        // 将子节点添加到 ParentList 中
        if (child.children && child.children.length > 0) {
          this.addAllChildren(child.children);
          // 递归调用继续添加子节点的子节点
        }
      }
      console.log('this.ParentList',this.ParentList);
    },
    removeAllChildren(children) {
      for (let child of children) {
        this.removeFromParentList(child);
        // 将子节点从 ParentList 中移除
        if (child.children && child.children.length > 0) {
          this.removeAllChildren(child.children);
          // 递归调用继续移除子节点的子节点
        }
      }
    },
    addToParentList(item) {
      const classifyOid = item.attributes.classifyOid;
      if (!this.isClassifyOidExists(classifyOid)) {
        const record = {
          oid: item.oid,
          classifyId: item.attributes.classifyId,
          classifyOid: classifyOid,
        };
        this.ParentList.push(record);
        // 将节点添加到ParentList中
      }
    },
    removeFromParentList(item) {
      const classifyOid = item.attributes.classifyOid;
      if (this.isClassifyOidExists(classifyOid)) {
        const index = this.findIndexByClassifyOid(classifyOid);
        if (index !== -1) {
          this.ParentList.splice(index, 1);
        }
        // 将节点从ParentList中移除
      }
    },
    isClassifyOidExists(classifyOid) {
      return this.ParentList.some(item => item.classifyOid === classifyOid);
    },
    findIndexByClassifyOid(classifyOid) {
      return this.ParentList.findIndex(item => item.classifyOid === classifyOid);
    },
    //分类授权
    classifyHandler(row) {