田源
2023-10-08 6c1d86f4e4c43024a9214752cfeb5f315744f4b2
分类授权-构建已选择数据多选回填
已修改1个文件
88 ■■■■■ 文件已修改
Source/UBCS-WEB/src/views/integration/systemInfo.vue 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS-WEB/src/views/integration/systemInfo.vue
@@ -33,8 +33,6 @@
                     v-model="TreeForm"
                     :data="TreeData"
                     :option="TreeOption"
                     node-key="id"
                     :default-checked-keys="[5]"
                     @check-change="checkChange">
          </avue-tree>
        </el-col>
@@ -153,6 +151,7 @@
    },
    //分类授权多选回调
    checkChange(row, checked) {
      console.log('row',row)
      if (checked) {
        if (!row.parentId) {
          const parentRecord = {
@@ -227,43 +226,68 @@
      this.loading = true;
      this.checkAll = row
      sysInfoTree({systemOid: row.oid, systemId: row.id}).then(res => {
        this.TreeData = res.data;
        var List=[]
        this.TreeData.forEach((item,index)=>{
          const parentRecord = {
            label: item.text,
            children:  [], // 初始化children为空数组
        let List = [];
        let value = 0;
        let NumberList= [];
        function traverse(obj, parent) {
          //重新构建一次选中当前row的数据
          const record = {
            label: obj.text,
            oid: obj.oid,
            attributes:{
              classifyId: obj.attributes.classifyId,
              classifyOid: obj.attributes.classifyOid,
              selected:obj.attributes.selected
            },
            classParentOid: obj.parentId,
            value: value,
            children: []
          };
          List.push(parentRecord);
          // 如果item的children不为空 继续循环children中的每个对象
          if (item.children && item.children.length > 0) {
            for (let child of item.children) {
              const childRecord = {
                label: child.text, // 使用child的text属性作为label
                children:  [], // 初始化children为空数组
              };
              parentRecord.children.push(childRecord); // 将childRecord添加到parentRecord的children数组中
              // 如果子对象的children不为空 继续循环获取数据
              if (child.children && child.children.length > 0) {
                for (let subChild of child.children) {
                  const subRecord = {
                    label: subChild.text, // 使用subChild的text属性作为label
                    children:  [], // 初始化children为空数组
                  };
                  childRecord.children.push(subRecord); // 将subRecord添加到childRecord的children数组中
                }
              }
          //当前已选择数据回填
          if (!record.attributes.selected) {
            NumberList.push(record.value);
          }
          if (parent) {
            const existingChild = parent.children.find(child => child.label === record.label);
            if (existingChild) {
              record.value = existingChild.value; // 使用已存在的子节点的value值
            } else {
              parent.children.push(record);
              value++;
            }
          } else {
            const existingRecord = List.find(item => item.label === record.label);
            if (existingRecord) {
              record.value = existingRecord.value; // 使用已存在的顶层节点的value值
            } else {
              List.push(record);
              value++;
            }
          }
        })
        console.log('list',List)
        this.ModifyProperties(this.TreeData, 'text', 'label');
        // 根据 this.TreeData 的长度计算延迟时间
          if (obj.children && obj.children.length > 0) {
            for (let child of obj.children) {
              traverse(child, record);
            }
          }
        }
        for (let item of res.data) {
          traverse(item, null);
        }
        // console.log('list', List);
        this.TreeData = List;
        // this.ModifyProperties(this.TreeData, 'text', 'label');
        // 根据this.TreeData的长度计算延迟时间
        const delayTime = this.TreeData.length * 1;
        setTimeout(() => {
          this.loading = false;
          this.reload = Math.random()
          this.reload = Math.random();
          this.dialogVisible = true;
          this.$nextTick(() => {
            if (this.$refs.tree) {
              this.$refs.tree.setCheckedKeys(NumberList);
            }
          });
        }, delayTime);
      });
    },