Source/UBCS-WEB/src/components/Theme/ClassifyAuthDialog.vue
@@ -99,6 +99,7 @@
export default {
  name: "classifyAuthDialog.vue",
  props: {
    // 当前点击节点的顶层节点
    classifyData: {
      type: "Object",
      default: "",
@@ -108,12 +109,16 @@
      type: "Boolean",
      default: false,
    },
    // 当前点击的节点
    TreeNode:{
      type:Object
    }
  },
  data() {
    return {
      // 对话框显示控制
      isShowDialog: this.visible,
      isLoading: false,
      isLoading: true,
      tableHeight: "calc(100vh - 550px)",
      classifyAuthData: [],
      //列头
@@ -131,82 +136,15 @@
  },
  computed: {},
  mounted() {},
  created() {},
  created() {
    this.addIndex = this.classifyAuthData.length <= 0 ? 0 :this.classifyAuthData.length -1;
  },
  watch: {
    // 监听父组件传的窗口显示隐藏的值
    visible() {
      if (this.visible) {
        this.isShowDialog = this.visible;
        return new Promise((resolve, reject) => {
          getButtonByParentCode({ code: "classifyTree" })
            .then((res) => {
              // 记录按钮数据
              this.classifyAuthButton = res.data.data;
              const list = res.data.data;
              let tempData = [];
              // 角色列
              tempData.push({
                label: "角色",
                prop: "roleData",
                type: "select",
                width: 150,
              });
              // 编码项分类授权
              tempData.push({
                label: "编码项分类授权",
                prop: "classifyItem",
                type: "text",
                width: 180,
              });
              list.forEach((item) => {
                let columnItem = {
                  label: item.name,
                  prop: item.id,
                  code: item.code,
                  type: "checkbox",
                  width: 180,
                };
                tempData.push(columnItem);
              });
              this.classifyAuthHeader = tempData;
              resolve();
            })
            .catch((err) => {
              reject(err);
            });
          // 获取角色列表
          getPage(1, -1, null).then((res) => {
            this.roleList = res.data.data.records;
          });
          // 获取该分类下已授权的分类授权信息
          getClassifyAuthList({
            classifyId: this.classifyData.oid,
            authType: "classify_auth",
          }).then((res) => {
            //console.log(res.data.data);
            let authDatas = res.data.data;
            if (authDatas.length > 0) {
              authDatas.forEach((authData, index) => {
                let item = {
                  oid: authData.oid,
                  roleData: authData.roleId,
                  classifyItem: this.classifyData.label,
                  authButton:{},
                  index: index,
                  uuid: uuidv4(), //生成唯一的id
                };
                //将按钮设置进去
                authData.buttonIdList.forEach((data) => {
                  Vue.set(item, data, true);
                });
                this.classifyAuthData.push(item);
                this.addIndex = this.classifyAuthData.length - 1; //添加行下标等于classifyAuthData的长度-1
                this.roleHandlerMethods(authData.roleId, "create", index);
                // console.log('index', index)
              });
            }
          });
        });
        this.loadAuthPage();
      }
    },
  },
@@ -215,7 +153,6 @@
      if (this.classifyAuthData.length < 0) {
        return;
      }
      getButtonsByRoleId({ roleId: id, code: "classifyTree" }).then((res) => {
        // 找到this.classifyAuthButton中没有对应的属性
        const filteredItems = this.classifyAuthButton.filter((item) => {
@@ -230,25 +167,25 @@
                Object.keys(this.classifyAuthData[index]).forEach((key) => {
                  this.$set(this.classifyAuthData[index].authButton,item.code,true);
                });
                //添加 “查看全部禁用条件”
                if (item.code === "classify_view") {
                  this.$set(this.classifyAuthData[index].authButton, "allDisabled", true);
                  console.log(this.classifyAuthData[index].authButton.allDisabled)
                }
              } else {
                Object.keys(this.classifyAuthData[index]).forEach((key) => {
                  this.$set(this.classifyAuthData[index].authButton,item.code,false);
                });
                if(item.code === "classify_view"){
                  this.classifyAuthData[index].authButton.allDisabled = false;
                }
              }
            }
          });
        });
        //添加 “查看全部禁用条件”
        if (this.classifyAuthData.authButton) {
          this.classifyAuthData.forEach((classkey, classIndex) => {
            if (classkey.authButton.classify_view) {
              this.$set(this.classifyAuthData[classIndex].authButton,"allDisabled",true);
            } else {
              this.classifyAuthData[classIndex].authButton.allDisabled = false;
            }
          });
        }
        //强制刷新表格
        this.itemKey = uuidv4();
@@ -286,7 +223,7 @@
                });
              }
            }
            this.itemKey = uuidv4(); // 强制刷新表格
          });
        });
@@ -305,8 +242,7 @@
        this.$message.warning("当前租户不存在角色信息!");
        return;
      }
      // console.log('this.roleList', this.roleList)
      this.addIndex++; //自定义生成添加行下标
      let item = {
        roleData: this.roleList[0].id,
        classifyItem: this.classifyData.label,
@@ -320,6 +256,7 @@
      });
      this.classifyAuthData.push(item);
      this.roleHandlerMethods(this.roleList[0].id, "add", this.addIndex);
      this.addIndex++; //自定义生成添加行下标
    },
    // 删除行
    subClassifyAuth() {
@@ -346,61 +283,68 @@
      this.selectList = list;
    },
    // 保存分类授权信息
    submit() {
      if (this.classifyAuthData.length <= 0) {
        this.$message.warning("授权列表为空!");
        return;
      }
    async submit() {
      let form = {
        classifyAuthList: [],
        isCLear: false, //默认是清空
        classifyId: this.TreeNode.oid,
      };
      let isRepeat = false;
      // 遍历数组,比较后面的对象的roleData是否与前面的对象相等
      for (let i = 0; i < this.classifyAuthData.length - 1; i++) {
        let currentRoleId = this.classifyAuthData[i].roleData;
        for (let j = i + 1; j < this.classifyAuthData.length; j++) {
          if (currentRoleId === this.classifyAuthData[j].roleData) {
            isRepeat = true;
      if(this.classifyAuthData.length > 0){
        // 遍历数组,比较后面的对象的roleData是否与前面的对象相等
        for (let i = 0; i < this.classifyAuthData.length - 1; i++) {
          let currentRoleId = this.classifyAuthData[i].roleData;
          for (let j = i + 1; j < this.classifyAuthData.length; j++) {
            if (currentRoleId === this.classifyAuthData[j].roleData) {
              isRepeat = true;
              break;
            }
          }
          if (isRepeat) {
            break;
          }
        }
        if (isRepeat) {
          break;
        }
      }
      if (isRepeat) {
        this.$message.warning("角色和分类已经存在,请重新配置!");
        return;
      }
      let form = [];
      let flag = false;
      this.classifyAuthData.forEach((item) => {
        let itemButtonList = [];
        //筛选出按钮勾选为true的列
        for (let key in item) {
          if (item[key] === true) {
            itemButtonList.push(key);
          }
        }
        /**如果itemButtonList为空证明是,
         添加了角色但是没勾选任何的按钮*/
        if (itemButtonList.length <= 0) {
          flag = true;
          this.$message.warning("角色和分类已经存在,请重新配置!");
          return;
        }
        let data = {
          oid: item.oid,
          roleId: item.roleData,
          classifyId: this.classifyData.oid,
          buttonIds: itemButtonList.join(","),
          authType: "classify_auth",
        };
        form.push(data);
      });
      if (flag) {
        this.$message.warning("有未勾选操作的权限,不允许授权");
        return;
        let flag = false;
        this.classifyAuthData.forEach((item) => {
          let itemButtonList = [];
          //筛选出按钮勾选为true的列
          for (let key in item) {
            if (item[key] === true) {
              itemButtonList.push(key);
            }
          }
          /**如果itemButtonList为空证明是,
           添加了角色但是没勾选任何的按钮*/
          if (itemButtonList.length <= 0) {
            flag = true;
            return;
          }
          let data = {
            oid: item.oid,
            roleId: item.roleData,
            classifyId: this.TreeNode.oid,
            buttonIds: itemButtonList.join(","),
            authType: "classify_auth",
          };
          form.classifyAuthList.push(data);
        });
        if (flag) {
          this.$message.warning("有未勾选操作的权限,不允许授权");
          return;
        }
      }else {
        // 为空证明是清空授权列表
        form.isCLear = true;
      }
      // console.log(form)
      // console.log(JSON.stringify(form))
      // 调用保存分类授权的接口
      saveOrUpdate(form).then(
      await saveOrUpdate(form).then(
        (res) => {
          this.$message({
            type: "success",
@@ -412,6 +356,8 @@
          window.console.log(error);
        }
      );
      this.classifyAuthData = [];
      this.loadAuthPage();
    },
    // 全选按钮
    selectAllButton() {
@@ -425,6 +371,80 @@
      });
      //console.log("this.selectList",this.selectList);
    },
    // 加载授权列表
    loadAuthPage() {
      return new Promise((resolve, reject) => {
        this.isLoading = true;
        getButtonByParentCode({ code: "classifyTree" })
          .then((res) => {
            // 记录按钮数据
            this.classifyAuthButton = res.data.data;
            const list = res.data.data;
            let tempData = [];
            // 角色列
            tempData.push({
              label: "角色",
              prop: "roleData",
              type: "select",
              width: 150,
            });
            // 编码项分类授权
            tempData.push({
              label: "编码项分类授权",
              prop: "classifyItem",
              type: "text",
              width: 180,
            });
            list.forEach((item) => {
              let columnItem = {
                label: item.name,
                prop: item.id,
                code: item.code,
                type: "checkbox",
                width: 180,
              };
              tempData.push(columnItem);
            });
            this.classifyAuthHeader = tempData;
            resolve();
          })
          .catch((err) => {
            reject(err);
          });
        // 获取角色列表
        getPage(1, -1, null).then((res) => {
          this.roleList = res.data.data.records;
        });
        // 获取该分类下已授权的分类授权信息
        getClassifyAuthList({
          classifyId: this.TreeNode.oid,
          authType: "classify_auth",
        }).then((res) => {
          //console.log(res.data.data);
          let authDatas = res.data.data;
          if (authDatas.length > 0) {
            authDatas.forEach((authData, index) => {
              let item = {
                oid: authData.oid,
                roleData: authData.roleId,
                classifyItem: this.classifyData.label,
                authButton:{},
                index: index,
                uuid: uuidv4(), //生成唯一的id
              };
              //将按钮设置进去
              authData.buttonIdList.forEach((data) => {
                Vue.set(item, data, true);
              });
              this.classifyAuthData.push(item);
              this.roleHandlerMethods(authData.roleId, "create", index);
              // console.log('index', index)
            });
          }
        });
        this.isLoading = false;
      });
    },
  },
};
</script>