Bladeren bron

Merge branch 'master' of http://git.ycjcjy.com/ershoufang/mp-agent into master

zlisen 4 jaren geleden
bovenliggende
commit
b98bc30c2b
5 gewijzigde bestanden met toevoegingen van 60 en 11 verwijderingen
  1. 10
    9
      src/components/Shiro/index.vue
  2. 4
    2
      src/main.js
  3. 2
    0
      src/store/index.js
  4. 18
    0
      src/store/models/shiro.js
  5. 26
    0
      src/utils/plugins/shiro.js

src/components/Authentication/index.vue → src/components/Shiro/index.vue Bestand weergeven

@@ -8,23 +8,24 @@
8 8
 
9 9
 <script>
10 10
 import { computed } from 'vue'
11
+import { useModel } from '@zjxpcyc/vue-tiny-store'
11 12
 
12 13
 export default {
13 14
   props: {
14
-    check: undefined,
15
+    name: undefined,
15 16
     error: String,
16 17
   },
17 18
   
18 19
   setup(props) {
19
-    const show = computed(() => {
20
-      if (typeof props.check === 'boolean') {
21
-        return props.check
22
-      } else if (typeof props.check === 'function') {
23
-        // 函数必须返回 boolean 值
24
-        return props.check()
25
-      } else {
26
-        return false
20
+    const { permissions, getPermission } = useModel('shiro')
21
+
22
+    const show = computed(async () => {
23
+      const permission = permissions[props.name]
24
+      if (typeof permission !== 'boolean') {
25
+        return await getPermission(props.name)
27 26
       }
27
+
28
+      return permission
28 29
     })
29 30
 
30 31
     return {

+ 4
- 2
src/main.js Bestand weergeven

@@ -5,14 +5,16 @@ import { router } from './router';
5 5
 import store from './store'
6 6
 import 'vant/lib/index.css';
7 7
 
8
-import Authentication from './components/Authentication'
8
+import Shiro from './components/Shiro'
9 9
 import XLoading from './components/XLoading'
10
+import shiro from './utils/plugins/shiro'
10 11
 
11 12
 const app = createApp(App);
12 13
 app.use(store);
13 14
 app.use(router);
15
+app.use(shiro);
14 16
 
15 17
 app.component('x-loading', XLoading)
16
-app.component('x-auth', Authentication)
18
+app.component('shiro', Shiro)
17 19
 
18 20
 app.mount('#app');

+ 2
- 0
src/store/index.js Bestand weergeven

@@ -1,8 +1,10 @@
1 1
 import createStore from '@zjxpcyc/vue-tiny-store'
2 2
 import loading from './models/loading'
3
+import shiro from './models/shiro'
3 4
 
4 5
 const store = createStore({
5 6
   loading,
7
+  shiro,
6 8
 })
7 9
 
8 10
 export default store

+ 18
- 0
src/store/models/shiro.js Bestand weergeven

@@ -0,0 +1,18 @@
1
+import { reactive } from "vue"
2
+import request from '../../utils/request'
3
+
4
+export default () => {
5
+  const permissions = reactive({})
6
+
7
+  const getPermission = x => {
8
+    request({
9
+      url: '/comm/rights',
10
+      data: x,
11
+    }).then(res => {
12
+      permissions[x] = Boolean(res)
13
+      return permissions[x]
14
+    })
15
+  }
16
+
17
+  return { permissions, getPermission }
18
+}

+ 26
- 0
src/utils/plugins/shiro.js Bestand weergeven

@@ -0,0 +1,26 @@
1
+import { useModel } from '@zjxpcyc/vue-tiny-store'
2
+
3
+const shiro = {
4
+  install: (app, options) => {
5
+    const { permissions, getPermission } = useModel('shiro')
6
+
7
+    const removeNode = el => el.parentNode.removeChild(el)
8
+
9
+    app.directive('shiro', (el, binding) => {
10
+      const permission = permissions[binding.value]
11
+      if (typeof permission !== 'boolean') {
12
+        getPermission(props.name).then(x => {
13
+          if (!x) {
14
+            removeNode(el)
15
+          }
16
+        })
17
+      } else {
18
+        if (!permission) {
19
+          removeNode(el)
20
+        }
21
+      }
22
+    })
23
+  }
24
+}
25
+
26
+export default shiro