Browse Source

完成顶部和左侧tab栏权限设置

shaogen1995 4 năm trước cách đây
mục cha
commit
97b620473e

+ 18 - 6
src/components/tabLeft.vue

@@ -25,12 +25,12 @@ export default {
   data () {
     return {
       tabList: [
-        { name: '藏品登记', id: 0 },
-        { name: '藏品总账', id: 3 },
-        { name: '入库管理', id: 1 },
-        { name: '出库管理', id: 2 },
-        { name: '藏品修改', id: 4 },
-        { name: '藏品注销', id: 5 }
+        { name: '藏品登记', id: 0, ip: 100 },
+        { name: '藏品总账', id: 3, ip: 200 },
+        { name: '入库管理', id: 1, ip: 300 },
+        { name: '出库管理', id: 2, ip: 400 },
+        { name: '藏品修改', id: 4, ip: 500 },
+        { name: '藏品注销', id: 5, ip: 600 }
       ]
     }
   },
@@ -44,6 +44,18 @@ export default {
         }, 200)
       })
     }
+  },
+  mounted () {
+    // 获取用户权限数据
+    let temp2 = localStorage.getItem('daliCK_limits')
+    temp2 = JSON.parse(temp2)
+    const tempList1 = []
+    temp2.forEach(v => {
+      if (v.authority) {
+        if ((this.tabList.filter(p => p.ip === v.id))[0]) tempList1.push((this.tabList.filter(p => p.ip === v.id))[0])
+      }
+    })
+    this.tabList = tempList1
   }
 }
 </script>

+ 15 - 3
src/components/tabLeft3.vue

@@ -24,9 +24,9 @@ export default {
   data () {
     return {
       tabList: [
-        { name: '库房设置', id: 0 },
-        { name: '统计报表', id: 1 },
-        { name: '藏品移库', id: 2 }
+        { name: '库房设置', id: 0, ip: 700 },
+        { name: '统计报表', id: 1, ip: 999999 },
+        { name: '藏品移库', id: 2, ip: 800 }
       ]
     }
   },
@@ -34,6 +34,18 @@ export default {
     skip (index) {
       this.$router.push(`/layout/statistics${index}`).catch(() => {})
     }
+  },
+  mounted () {
+    // 获取用户权限数据
+    let temp2 = localStorage.getItem('daliCK_limits')
+    temp2 = JSON.parse(temp2)
+    const tempList1 = []
+    temp2.forEach(v => {
+      if (v.authority) {
+        if ((this.tabList.filter(p => p.ip === v.id))[0]) tempList1.push((this.tabList.filter(p => p.ip === v.id))[0])
+      }
+    })
+    this.tabList = tempList1
   }
 }
 </script>

+ 32 - 9
src/views/layout/index.vue

@@ -122,12 +122,12 @@ export default {
           name: '馆藏管理',
           push: '/layout/holding',
           son: [
-            { name: '藏品登记', id: 0 },
-            { name: '藏品总账', id: 3 },
-            { name: '入库管理', id: 1 },
-            { name: '出库管理', id: 2 },
-            { name: '藏品修改', id: 4 },
-            { name: '藏品注销', id: 5 }
+            { name: '藏品登记', id: 0, ip: 100 },
+            { name: '藏品总账', id: 3, ip: 200 },
+            { name: '入库管理', id: 1, ip: 300 },
+            { name: '出库管理', id: 2, ip: 400 },
+            { name: '藏品修改', id: 4, ip: 500 },
+            { name: '藏品注销', id: 5, ip: 600 }
           ]
         },
         // {
@@ -144,9 +144,9 @@ export default {
           name: '库房管理',
           push: '/layout/statistics',
           son: [
-            { name: '库房设置', id: 0 },
-            { name: '统计报表', id: 1 },
-            { name: '藏品移库', id: 2 }
+            { name: '库房设置', id: 0, ip: 700 },
+            { name: '统计报表', id: 1, ip: 99999 },
+            { name: '藏品移库', id: 2, ip: 800 }
           ]
         },
         {
@@ -240,6 +240,29 @@ export default {
     // 进来显示用户信息
     const userData = localStorage.getItem('daliCK')
     this.userData = JSON.parse(userData).user
+    // 只有系统管理员才能看到系统管理
+    // 获取用户角色权限标识
+    let temp = localStorage.getItem('daliCK')
+    temp = JSON.parse(temp)
+    if (temp) {
+      const temp2 = temp.role[0]
+      if (temp2 !== 'sys_admin') this.tabList.pop() // 不是超级管理员
+    }
+    // 获取用户权限数据
+    let temp2 = localStorage.getItem('daliCK_limits')
+    temp2 = JSON.parse(temp2)
+    // console.log(666, this.tabList[1].son, this.tabList[2].son)
+    const tempList1 = []
+    const tempList2 = []
+    temp2.forEach(v => {
+      if (v.authority) {
+        if ((this.tabList[1].son.filter(p => p.ip === v.id))[0]) tempList1.push((this.tabList[1].son.filter(p => p.ip === v.id))[0])
+        if ((this.tabList[2].son.filter(p => p.ip === v.id))[0]) tempList2.push((this.tabList[2].son.filter(p => p.ip === v.id))[0])
+      }
+    })
+    this.tabList[1].son = tempList1
+    this.tabList[2].son = tempList2
+    // console.log(999, temp2)
   },
   beforeCreate () {}, // 生命周期 - 创建之前
   beforeMount () {}, // 生命周期 - 挂载之前

+ 5 - 0
src/views/login/index.vue

@@ -32,6 +32,7 @@
 </template>
 
 <script>
+import { getTreePermissions } from '@/apis/system1'
 import { userLogin } from '@/apis/home'
 export default {
   name: 'Login',
@@ -62,6 +63,10 @@ export default {
         if (res.code === 0) {
           localStorage.setItem('daliCK', JSON.stringify(res.data))
           localStorage.setItem('daliCK_token', res.data.token)
+          // 获取角色权限树
+          const res2 = await getTreePermissions()
+          // 本地储存
+          localStorage.setItem('daliCK_limits', JSON.stringify(res2.data))
           this.$router.push('/layout/home')
           this.$message.success('登录成功')
         } else this.$message.error(res.msg)