chenjun 2 yıl önce
ebeveyn
işleme
9b22f7a1ed
1 değiştirilmiş dosya ile 56 ekleme ve 82 silme
  1. 56 82
      src/components/permissiontree/index.vue

+ 56 - 82
src/components/permissiontree/index.vue

@@ -40,9 +40,9 @@
       </div> -->
       <div class="paren_cont">
         <el-scrollbar style="height: 100%">
-          <el-tree :data="data" show-checkbox @check-change="currentChange" @node-click="handleNodeClick" :defaultProps="defaultProps" node-key="AuthId" default-expand-all ref="tree" highlight-current>
+          <el-tree :data="data" show-checkbox @check-change="currentChange" @node-click="handleNodeClick" :defaultProps="defaultProps" node-key="auth_id" default-expand-all ref="tree" highlight-current>
             <span class="custom-tree-node" slot-scope="{ data }">
-              {{ data.AuthName }}
+              {{ data.auth_name }}
               <div class="logup">
                 <div class="one" v-if="data.AuthList && data.AuthList.ValidBegin"></div>
                 <div class="two" v-if="data.AuthList && data.AuthList.Action == '1'"></div>
@@ -69,6 +69,7 @@
 import { translateDataToTreeAll, deteleObject } from "@/utils/validate";
 import { GetAuthTree } from "@/api/apiAuthority";
 import { GetAuthTreeByGroup } from "@/api/AccountGroup";
+import { Query, GeneralDataReception } from "@/api/dataIntegration";
 import { organizationUptree, postUptree } from "@/api/postInterface";
 export default {
   props: {
@@ -76,11 +77,6 @@ export default {
       type: String,
       default: "",
     },
-    checkedKeys: {
-      //已选中
-      type: Array,
-      default: () => [],
-    },
     //查询类型:queryType: all/获取全部权限树;job/根据岗位获取权限树;origin/根据组织获取权限树;group/根据帐号组获取权限树;
     queryType: {
       type: String,
@@ -118,13 +114,14 @@ export default {
       oldType: "",
       queryIdArr: [], //历史查询ID
       MainJobId: "", //主岗ID
+      checkedKeys:[]
     };
   },
   watch: {
     checkedKeys: {
       handler (val) {
         this.checkedList = val;
-        this.$refs.tree.setCheckedKeys(val);
+        this.$refs.tree.setCheckedKeys(this.checkedList);
       },
       deep: true,
     },
@@ -142,31 +139,10 @@ export default {
     },
     queryId: {
       handler (val) {
-        if (this.queryType == "job") {
-          this.setDisabledAll();
-          let ids = val.split(",");
-          this.queryIdArr = [];
-          this.$refs.tree.setCheckedKeys([]);
-          if (this.isMainJob == true) {
-            this.MainJobId = val;
-          }
-          if (this.MainJobId != "") {
-            this.queryIdArr.push(this.MainJobId);
-          }
-          for (let i = 0; i < ids.length; i++) {
-            if (_.indexOf(this.queryIdArr, ids[i]) == -1) {
-              this.queryIdArr.push(ids[i]);
-            }
-          }
-          for (let j = 0; j < this.queryIdArr.length; j++) {
-            this.searchId = this.queryIdArr[j];
-            this.getDefaultDataList();
-          }
-        } else {
-          this.searchId = val;
-          this.getDefaultDataList();
-        }
+        this.searchId = val;
+        this.getDefaultDataList();
       },
+      immediate: true,
       deep: true,
     },
     queryIds: {
@@ -194,54 +170,52 @@ export default {
       }, 100);
     },
     //获取权限列表
-    getDataList () {
-      GetAuthTree({ QueryName: "" }).then((result) => {
-        this.getDefaultDataList();
-        this.setData(result);
-      });
+    async getDataList () {
+      const res = await Query({
+          id:40,
+          dataContent:[""]
+        });
+        if (res.code === "0") {
+          this.setData(res.returnData.listValues);
+        } else {
+          this.$message.error(res.message);
+          this.loading = false;
+        }
+        this.setData(res);
     },
     async getDefaultDataList () {
-      if (this.queryType == "all" && this.searchId != "") {
-        //获取全部权限树
-        GetAuthTree({ QueryName: "" }).then((result) => {
-          this.setUnDisabledData(result.returnData);
+      try {
+        const res = await Query({
+          id:42,
+          dataContent:[this.searchId]
         });
-      } else if (this.queryType == "job") {
-        //根据岗位获取权限树
-        postUptree({ JobId: this.searchId }).then((result) => {
-          this.setUnDisabledData(result.returnData);
-        });
-      } else if (this.queryType == "origin") {
-        //根据组织获取权限树
-        this.AuthList = [];
-        this.$refs.tree.setCheckedKeys([]);
-        organizationUptree({ OrganId: this.searchId }).then((result) => {
-          this.setUnDisabledData(result.returnData);
-        });
-      } else if (this.queryType == "group") {
-        //根据帐号组获取权限树
-        if (this.searchId) {
-          GetAuthTreeByGroup({ GroupIds: [this.searchId] }).then((result) => {
-            this.setUnDisabledData(result.returnData);
-          });
-        } else if (this.queryIds.length) {
-          GetAuthTreeByGroup({ GroupIds: this.queryIds }).then((result) => {
-            this.setUnDisabledData(result.returnData);
-          });
+        if (res.code === "0") {
+          this.checkedKeys = [];
+          res.returnData.listValues.forEach(item=>{
+            this.checkedKeys.push(item.AuthId)
+            this.AuthArrList.forEach(item2=>{
+              if(item.AuthId == item2.auth_id){
+                item2.AuthList = item
+              }
+            })
+          })
+          this.toTree()
+        } else {
+          this.$message.error(res.message);
+          this.loading = false;
         }
+      } catch (error) {
+        console.log("出错了", error);
       }
     },
     setData (result) {
-      if (result.code === 0 && result.returnData.length) {
+      if (result.code === "0" && result.returnData.listValues.length) {
         this.AuthArrList = [];
-        result.returnData.forEach((item) => {
-          item.flag = item.Status === 1 ? true : false;
+        result.returnData.listValues.forEach((item) => {
+          item.flag = item.auth_status === true ? true : false;
           item["AuthList"] = null;
-          if (this.queryType != "all") {
-            item["disabled"] = true;
-          }
         });
-        this.AuthArrList = _.cloneDeep(result.returnData);
+        this.AuthArrList = _.cloneDeep(result.returnData.listValues);
         this.toTree();
       } else {
         this.$message.error(result.message);
@@ -253,16 +227,14 @@ export default {
       this.dataObj = {};
       this.treeTitles = [];
       let arr = null;
-      arr = translateDataToTreeAll(this.AuthArrList, "UpAuthId", "AuthId");
+      arr = translateDataToTreeAll(this.AuthArrList, "up_auth_id", "auth_id");
       let items = null;
       items = {
-        AuthId: 0,
-        AuthName: "所有权限",
-        QueryTarget: 0,
-        Status: 0,
-        UpAuthId: 0,
-        Type: 0,
-        disabled: true,
+        auth_id: 0,
+        auth_name: "所有权限",
+        auth_status: 0,
+        up_auth_id: 0,
+        auth_type: 0,
         children: arr,
       };
       this.dataObj = _.cloneDeep(items);
@@ -277,6 +249,7 @@ export default {
       delete obj.children;
       datas.unshift(obj);
       this.treeTitles = datas;
+      console.log(datas)
       if (this.$refs.tree) {
         this.$refs.tree.setCheckedKeys(this.checkedList);
       }
@@ -321,7 +294,7 @@ export default {
     //获取指定数据
     decompose (data, id) {
       for (let i = 0; i < data.length; i++) {
-        if (data[i].AuthId == id) {
+        if (data[i].auth_id == id) {
           this.data = [data[i]];
         } else if (data[i].children && data[i].children.length > 0) {
           this.decompose(data[i].children, id);
@@ -334,7 +307,7 @@ export default {
         this.AuthArrList.forEach((item1) => {
           item1["AuthList"] = null;
           this.AuthList.forEach((item2) => {
-            if (item1.AuthId == item2.AuthId) {
+            if (item1.auth_id == item2.auth_id) {
               item1.AuthList = item2;
             }
           });
@@ -360,12 +333,13 @@ export default {
     handleNodeClick (data) {
       // this.toTree();
       const arr = this.$store.getters.authArrs;
+      console.log(arr)
       arr.push(data);
-      const datas = _.unionBy(arr, "AuthId");
+      const datas = _.unionBy(arr, "auth_id");
       const newDatas = _.cloneDeep(datas);
       this.$store.dispatch("auth/changeAuthMsg", newDatas);
       this.$store.dispatch("auth/changeAuthArrs", datas);
-      this.$store.dispatch("auth/changeAuthId", data.AuthId);
+      this.$store.dispatch("auth/changeAuthId", data.auth_id);
     },
     async setDisabledAll () {
       this.AuthArrList.forEach((item) => {