张延森 il y a 4 ans
Parent
révision
3d3152b73f
2 fichiers modifiés avec 28 ajouts et 0 suppressions
  1. 2
    0
      src/main.js
  2. 26
    0
      src/utils/plugins/shiro.js

+ 2
- 0
src/main.js Voir le fichier

@@ -7,10 +7,12 @@ import 'vant/lib/index.css';
7 7
 
8 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 18
 app.component('shiro', Shiro)

+ 26
- 0
src/utils/plugins/shiro.js Voir le fichier

@@ -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