ludc
2024-01-24 c327574106f470c72638e9f34c7f8cd26d78a2bf
Source/UBCS-WEB/src/components/Theme/ClassifyAuthDialog.vue
@@ -137,76 +137,7 @@
    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 +146,6 @@
      if (this.classifyAuthData.length < 0) {
        return;
      }
      getButtonsByRoleId({ roleId: id, code: "classifyTree" }).then((res) => {
        // 找到this.classifyAuthButton中没有对应的属性
        const filteredItems = this.classifyAuthButton.filter((item) => {
@@ -344,61 +274,68 @@
      this.selectList = list;
    },
    // 保存分类授权信息
    submit() {
      if (this.classifyAuthData.length <= 0) {
        this.$message.warning("授权列表为空!");
        return;
      }
    async submit() {
      let form = {
        classifyAuthList: [],
        isCLear: false, //默认是清空
        classifyId: this.classifyData.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.classifyData.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",
@@ -410,6 +347,8 @@
          window.console.log(error);
        }
      );
      this.classifyAuthData = [];
      this.loadAuthPage();
    },
    // 全选按钮
    selectAllButton() {
@@ -423,6 +362,79 @@
      });
      //console.log("this.selectList",this.selectList);
    },
    // 加载授权列表
    loadAuthPage() {
      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)
            });
          }
        });
      });
    },
  },
};
</script>