Browse Source

修改菜单 权限

tangning 3 years ago
parent
commit
d9975c5683
2 changed files with 27 additions and 6 deletions
  1. 2 1
      src/state/user.js
  2. 25 5
      src/view/role/index.vue

+ 2 - 1
src/state/user.js

@@ -87,7 +87,7 @@ export const setPermission = async (val,permissions) => {
     val = []
   }
   console.log('setInfoPermission',val);
-  user.value.permission = val || []
+  // user.value.permission = val || []
   user.value.roleKeyList = power
 }
 
@@ -125,6 +125,7 @@ export const setInfoPermission = val => {
       })
     }
   })
+  console.log('permission',permission);
   user.value.permission = permission || []
 }
 

+ 25 - 5
src/view/role/index.vue

@@ -225,12 +225,24 @@ export default {
     const newAddclick = async (id,type) => {
       let reqApi = getRoleTree;//id?getTreeByRole+id:getRoleTree
       let treeRes = await axios.get(reqApi, {roleId:id});
+      data.selectShow = null;
       data.selectId = id
       if(type != '新增'){
           let res = await axios.get(detailRole+id, {roleId:id});
           let { roleName,perm,deptName} = res.data
-          data.radioData = perm
-          data.checkedList = Object.keys(perm)
+          let radioData = {},checkedList=[],halfCheckedKeys=[]
+          perm.forEach(ele => {
+            if(ele.type == 'button'){
+              checkedList.push(ele.permissionId)
+              radioData[ele.permissionId] = ele.dataScope || '1'
+            }else{
+              halfCheckedKeys.push(ele.permissionId)
+            }
+          })
+          console.log('halfCheckedKeys',halfCheckedKeys,perm);
+          data.radioData = radioData
+          data.checkedList = checkedList
+          data.halfCheckedKeys = halfCheckedKeys
           data.newData = {
             ...data.newData,
             roleName,
@@ -255,6 +267,7 @@ export default {
       selectId:'',
       operateType:'新增',
       deptIdList: [],
+      halfCheckedKeys:[],
       radio: 1,
       roleLevel:sessionStorage.getItem('roleLevel'),
       radioData: {},
@@ -309,6 +322,7 @@ export default {
       console.log(checked);
       console.log(data);
       this.checkedList = checked.checkedKeys
+      this.halfCheckedKeys = checked.halfCheckedKeys
       let CurrentKey = this.$refs.tree.getCurrentKey();
       if (
         checked.checkedKeys.includes(data.id) &&
@@ -359,18 +373,24 @@ export default {
       }
       let perm = {}
       this.checkedList.map(ele =>{ 
-        perm[ele] = 1
+        if(this.radioData[ele]){
+          perm[ele] = this.radioData[ele]
+        }else{
+          perm[ele] = 1
+        }
       })
+      this.halfCheckedKeys.forEach(element => {
+          perm[element] = 1
+      });
+      console.log("newSubmit", this.halfCheckedKeys,perm);
       let id = this.selectId
       let apiinfo = await axios.post(updateRole, { //新增修改角色
         "id": id || '',
         "perm": {
           ...perm,
-          ...this.radioData,
         },
         "roleName": this.newData.roleName
       });
-      console.log("newSubmit", apiinfo);
       this.$message({ message: apiinfo.msg || "成功", type: "success" });
       // await this.$confirm('每个组织只能创建一个总管理员~', '新增用户')
       this.newData = {};