ludc
2023-09-28 432a477d82c052e99e5a0fb3214ce4d990111592
Source/UBCS-WEB/src/views/integration/systemInfo.vue
@@ -24,7 +24,8 @@
      </template>
    </avue-crud>
    <el-dialog :visible.sync="dialogVisible" append-to-body class="avue-dialog avue-dialog--top" title="分类授权" top="-10">
    <el-dialog :visible.sync="dialogVisible" append-to-body class="avue-dialog avue-dialog--top" title="分类授权"
               top="-50px">
      <el-row>
        <el-col :span="10">
@@ -37,18 +38,28 @@
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer" style="height: 50px;line-height: 50px">
        <el-button type="primary" icon="el-icon-plus" size="small">授 权</el-button>
        <el-button icon="el-icon-close"  size="small" type="danger">重 置</el-button>
    </div>
        <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>
      </div>
    </el-dialog>
  </basic-container>
</template>
<script>
import {getSysInfoList, sysInfoAdd, sysInfoEdit, sysInfoDel, sysInfoTree} from '@/api/integration/sysInfo.js'
import {
  getSysInfoList,
  sysInfoAdd,
  sysInfoEdit,
  sysInfoDel,
  sysInfoTree,
  batchAddSave
} from '@/api/integration/sysInfo.js'
export default {
  data() {
    return {
      checkAll: {},
      ParentList: [],
      ParentRemoveList: [],
      //避免缓存
      reload: Math.random(),
      TreeLoading: false,
@@ -125,18 +136,89 @@
      },
    }
  },
  created() {
  },
  methods: {
    empower() {
      batchAddSave(this.checkAll.oid, this.checkAll.id, this.ParentList).then(res => {
        console.log(res)
      })
    },
    //分类授权多选回调
    checkChange(row,checked) {
      // console.log(row)
      // if(checked){
      //
      // }
    checkChange(row, checked) {
      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);
                }
              }
            }
          }
        }
      } else {
        // 取消勾选的节点是父节点
        if (!row.parentId) {
          // 找到父节点在ParentList中的索引
          const parentIndex = this.ParentList.findIndex(item => item.oid === row.oid);
          if (parentIndex !== -1) {
            const parentOid = this.ParentList[parentIndex].classifyOid;
            // 查找所有需要删除的子节点的索引
            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.log(this.ParentList);
    },
    //分类授权
    classifyHandler(row) {
      this.loading = true;
      this.checkAll = row
      sysInfoTree({systemOid: row.oid, systemId: row.id}).then(res => {
        this.TreeData = res.data;
        this.ModifyProperties(this.TreeData, 'text', 'label');
@@ -266,9 +348,7 @@
    },
    // enter搜索
    handleEnter() {
      if (this.search[this.selectValue] === '') return
      else this.getDataList()
      this.getDataList()
    },
    // 输入框清空
    handleClear() {