zhaoke 1 rok pred
rodič
commit
a592afe2be

+ 16 - 0
src/api/webApi.js

@@ -78,4 +78,20 @@ export function stopAll (params) {
     data: params,
   })
 }
+//获取用户组权限授权
+export function getAuthorization (params) {
+  return request({
+    url: '/user/getAuthorization',
+    method: 'post',
+    data: params,
+  })
+}
+//用户组权限授权
+export function authorization (params) {
+  return request({
+    url: '/user/authorization',
+    method: 'post',
+    data: params,
+  })
+}
 

+ 25 - 0
src/utils/validate.js

@@ -291,6 +291,31 @@ export function listToTree (data, parentKey, key) {
   return parentList;
 }
 
+function format2Tree (item, childrenData) {
+  const { id } = item
+  const nchild = childrenData.filter(item => item.supergroupid == id)
+  return nchild
+}
+
+export function list2ToTree (data, childrenData, parentKey, key) {
+  const obj = {};
+  data.forEach((item) => {
+    obj[item[key]] = item;
+    obj[item[key]]['children'] = format2Tree(item, childrenData)
+  });
+  const parentList = [];
+  data.forEach((item) => {
+    const parent = obj[item[parentKey]];
+    if (parent) {
+      parent.children = parent.children || [];
+      parent.children.push(item);
+    } else {
+      parentList.push(item);
+    }
+  });
+  return parentList;
+}
+
 
 export function setTree (arr, parentKey, key) {
   const datas = []

+ 60 - 49
src/views/permissionPage/components/permissionList.vue

@@ -44,7 +44,7 @@ import PublicPageDialog from '@/components/PublicPageDialog'
 import AdvancedQuery from '@/components/AdvancedQuery'
 import { mapGetters } from 'vuex'
 import { listToTree } from '@/utils/validate'
-import { Query, newData, modifyData, moveData, } from "@/api/webApi"
+import { Query, newData, modifyData, moveData, getAuthorization, authorization } from "@/api/webApi"
 import { formatChange } from '@/utils/validate'
 
 export default {
@@ -80,42 +80,29 @@ export default {
       rowData: {},
       selectOptions: [],
       queryId: 6,
-      userList: [
-        {
-          path: '/userpPermission',
-          tid: 7
-        },
-        {
-          path: '/userGroupPermission',
-          tid: 6
-        }
-      ]
     }
   },
   watch: {
     listMap: {
       handler (row) {
         if (Object.keys(row).length) {
-          const queryItem = {}
-          const pname = this.queryId == 7 ? '用户' : '用户组'
-          queryItem[this.nodeKey] = row[this.nodeKey]
+          const queryItem = _.cloneDeep(row)
+          if (queryItem.children) delete queryItem.children
           this.ischeck = true
           this.checkDatas = []
           this.queryItem = queryItem
           this.$refs.tree.setCheckedKeys([])
-          this.queryTreeData(this.queryId, queryItem, pname)
+          this.queryTreeData(queryItem, '权限')
         }
       },
       deep: true,
       immediate: true
     },
     treeMap: {
-      handler (row) {
-        const { nodeKey, nodeValue } = row
-        if (nodeKey) this.nodeKey = nodeKey
-        if (nodeValue) {
-          // this.defaultProps.label = nodeValue
-          this.dataKey = nodeValue
+      handler (obj) {
+        if (Object.keys(obj).length) {
+          const { serviceid, pagename } = obj
+          this.queryAllAuthData(serviceid, pagename)
         }
       },
       deep: true,
@@ -125,15 +112,54 @@ export default {
   computed: {
     ...mapGetters(['authArrs'])
   },
-  created () {
-    const { path } = this.$route
-    const pitem = this.userList.filter(item => item.path == path)
-    this.queryId = pitem[0].tid
-  },
   mounted () {
-    this.setAuthData()
+
+    // this.setAuthData()
   },
   methods: {
+    async queryAllAuthData (serviceid, pagename) {
+      this.loading = true;
+      const datacontent = { filter: { 1: 1 } }
+      try {
+        const { code, returnData } = await Query({
+          serviceid,
+          datacontent,
+          event: '0'
+        });
+        if (code == 0 && returnData?.length) {
+          const name = '全部'
+          const alldata = this.disableTreeData([...returnData])
+          const treeMenu = listToTree([...alldata], 'superiorid', 'pageconfigurationid')
+          // const treeObj = { serviceid: name, superiorid: name, children: treeMenu }
+          // treeObj['pagename'] = name
+          // treeObj['pageconfigurationid'] = '-1'
+          // const treeMenuAll = [treeObj]
+          // this.defaultKeys = ['-1']
+          this.data = treeMenu
+        } else {
+          this.$message.error(`获取${pagename}数据失败`);
+        }
+      } catch (error) {
+        this.$message.error(`获取${pagename}数据失败`);
+      }
+      this.loading = false;
+    },
+    disableTreeData (arr = []) {
+      if (!arr.length) return
+      const alldata = _.cloneDeep(arr)
+      const isdata = _.cloneDeep(this.authArrs)
+      const nodata = this.findRepetData(alldata, isdata)
+      if (nodata?.length) {
+        alldata.map(item => {
+          nodata.map(ci => {
+            if (item.pageconfigurationid == ci.pageconfigurationid) {
+              item.disabled = true
+            }
+          })
+        })
+      }
+      return alldata
+    },
     restDataRow () {
       const pname = this.queryId == 7 ? '用户' : '用户组'
       this.ischeck = true
@@ -242,18 +268,13 @@ export default {
       }
     },
     //获取当前用户组/用户已有权限
-    async queryTreeData (serviceid, defaultfilter, pagename) {
+    async queryTreeData (dataContent, pagename) {
       this.loading = true;
-      const datacontent = { filter: defaultfilter }
       try {
-        const { code, returnData } = await Query({
-          serviceid,
-          datacontent,
-          event: '0'
-        });
+        const { code, returnData } = await getAuthorization({ datacontent: dataContent });
         if (code == 0) {
           const ndata = _.cloneDeep(returnData)
-          this.setAuthData(ndata)
+          // this.setAuthData(ndata)
           this.$nextTick(() => {
             this.checkAuthData(ndata)
           })
@@ -312,27 +333,17 @@ export default {
         if (item.children) delete item.children
         const paramsItem = {
           pageconfigurationid: item.pageconfigurationid,
-          userpermissionsid: item.userpermissionsid,
-          serviceid: item.serviceid,
-          insetcolumnlist: item.insetcolumnlist || '',
-          updatecolumnlist: item.updatecolumnlist || '',
-          selectcolumnlist: item.selectcolumnlist || '',
-          filterset: item.filterset || ''
-        }
-        if (this.queryId == 7) {
-          paramsItem.userid = item.userid
         }
         const params = {
-          serviceid: this.queryId,
-          datacontent: formatChange(Object.assign(paramsItem, this.queryItem), event, key),
+          datacontent: Object.assign(paramsItem, this.queryItem),
           event
         }
-        type == 'add' ? querys.push(newData(params)) : type == 'edit' ? querys.push(modifyData(params)) : querys.push(moveData(params))
+        querys.push(authorization(params))
       })
-      this.getAnscyData(querys, type)
+      this.getAnscyData(querys)
     },
     //获取异步数据
-    async getAnscyData (allResult, type) {
+    async getAnscyData (allResult) {
       if (!allResult.length) return
       this.loading = true
       const results = await Promise.allSettled(allResult)

+ 138 - 0
src/views/permissionPage/components/permissionTree.vue

@@ -0,0 +1,138 @@
+<template>
+  <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" class="publicPageTree">
+    <div class="publicPageTree_search">
+      <el-input size="small" placeholder="输入关键字进行过滤" clearable v-model="filterText"></el-input>
+    </div>
+    <div class="publicPageTree_tree">
+      <el-scrollbar style="height: 100%" :horizontal="false">
+        <el-tree class="filter-tree" :data="data" :props="defaultProps" node-key="uniqueKey" :default-expanded-keys="defaultKeys" :highlight-current="true" :filter-node-method="filterNode" ref="tree" @node-click="treeNodeClick" />
+      </el-scrollbar>
+    </div>
+  </div>
+</template>
+
+<script>
+import { Query } from "@/api/webApi"
+import { list2ToTree } from '@/utils/validate'
+
+export default {
+  name: 'PublicPageTree',
+  props: {
+    treeData: {
+      type: Array,
+      default: () => []
+    },
+    treeMap: {
+      type: Object,
+      default: () => new Object()
+    },
+    depMath: {
+      type: Number | String,
+      default: 0
+    }
+  },
+  data () {
+    return {
+      loading: false,
+      filterText: '',
+      data: [],
+      defaultProps: {
+        children: 'children',
+        label: 'usergroupname'
+      },
+      defaultKeys: [-1],
+      nodeKey: 'pageconfigurationid',
+      msgCaps: [],
+      dataKey: 'usergroupname'
+    }
+  },
+  watch: {
+    filterText (val) {
+      this.$refs.tree.filter(val);
+    },
+    treeData: {
+      handler (arr) {
+        if (arr.length) {
+          this.pageInit(arr)
+        }
+      },
+      deep: true,
+      immediate: true
+    },
+    depMath: {
+      handler (arr) {
+        this.pageInit(arr)
+      },
+      deep: true
+    }
+  },
+  methods: {
+    filterNode (value, data) {
+      if (!value) return true;
+      return data[this.dataKey].indexOf(value) !== -1;
+    },
+    pageInit (arr) {
+      const { serviceid, pagename } = arr[0]
+      const defaultfilterTag = { 1: 1 }
+      this.queryTreeData(defaultfilterTag, serviceid, pagename)
+    },
+    treeNodeClick (data) {
+      this.$emit('treeNodeClick', data)
+    },
+    setUserTree (arr = []) {
+      //1=用户 2=用户组
+      if (!arr.length) return []
+      const ndata = _.cloneDeep(arr)
+      const ngroup = ndata.filter(item => item.type == 2)
+      const nuser = ndata.filter(item => item.type == 1)
+      const ntree = list2ToTree(ngroup, nuser, 'supergroupid', 'id')
+      return ntree
+    },
+    async queryTreeData (defaultfilter, serviceid, pagename) {
+      this.loading = true;
+      const datacontent = { filter: defaultfilter }
+      try {
+        const { code, returnData } = await Query({
+          serviceid,
+          datacontent,
+          event: '0'
+        });
+        if (code == 0 && returnData?.length) {
+          const name = '全部'
+          const treeMenu = this.setUserTree([...returnData])
+          const treeObj = { serviceid: name, superiorid: name, children: treeMenu }
+          treeObj['usergroupname'] = name
+          treeObj['uniqueKey'] = '-1'
+          const treeMenuAll = [treeObj]
+          this.defaultKeys = ['-1']
+          this.data = treeMenuAll
+        } else {
+          this.$message.error(`获取${pagename}数据失败`);
+        }
+      } catch (error) {
+        this.$message.error(`获取${pagename}数据失败`);
+      }
+      this.loading = false;
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.publicPageTree {
+  background-color: #fff;
+  padding: 20px;
+  height: 100%;
+  width: 100%;
+  ::v-deep &_tree {
+    margin-top: 20px;
+    height: calc(100% - 52px);
+    .el-scrollbar__wrap {
+      overflow-x: hidden;
+    }
+    .is-horizontal {
+      display: none;
+    }
+  }
+}
+</style>

+ 8 - 7
src/views/permissionPage/index.vue

@@ -1,9 +1,9 @@
 <template>
   <div class="permissionPage">
-    <PublicPageHeader class="permissionPage_head" page-title="界面配置管理" />
+    <PublicPageHeader class="permissionPage_head" :page-title="pageTitle" />
     <div class="permissionPage_content flex">
       <div class="permissionPage_content_left">
-        <PublicPageTree :tree-data="treeData" :dep-math="depMath" :tree-map="treeNodeMap" @treeNodeClick="treeNodeClick" />
+        <PublicPageTree :tree-data="treeData" :dep-math="depMath" @treeNodeClick="treeNodeClick" />
       </div>
       <div class="permissionPage_content_right">
         <PublicPageTable :list-map="listMap" :tree-map="treeNodeMap" />
@@ -15,7 +15,7 @@
 <script>
 import PublicPageHeader from '@/components/PublicPageHeader'
 import PublicPageTable from './components/permissionList.vue'
-import PublicPageTree from '@/components/publicPageTree'
+import PublicPageTree from './components/permissionTree.vue'
 import { mapGetters } from 'vuex'
 export default {
   name: 'Permissionpage',
@@ -26,7 +26,8 @@ export default {
       treeParameters: {}, //tree传递参数
       treeNodeMap: {}, //tree传递map
       depMath: 0,
-      listMap: {}
+      listMap: {},
+      pageTitle: '权限配置'
     }
   },
   computed: {
@@ -52,12 +53,12 @@ export default {
       //获取tree权限
       const pageAuthtrees = pageAuthArrs.filter(item => item.pagetype == 'tree')
       if (pageAuthtrees?.length) this.getPageTreeSetting(pageAuthtrees)
+      //获取table权限
+      const pageAuthtables = pageAuthArrs.filter(item => item.pagetype == 'table')
+      if (pageAuthtrees?.length) this.treeNodeMap = pageAuthtables[0]
     },
     //根据页面tree设置数据
     getPageTreeSetting (pageAuthtrees) {
-      const { passparameters, dropdownlistid, dropdownlistlabel } = pageAuthtrees[0]
-      this.treeNodeMap = { nodeKey: dropdownlistid, nodeValue: dropdownlistlabel }
-      this.treeParameters = passparameters
       this.treeData = pageAuthtrees
     },
     //获取tree点击