|
@@ -1,11 +1,25 @@
|
|
|
import { ObjectDirective } from 'vue';
|
|
import { ObjectDirective } from 'vue';
|
|
|
import { usePermission } from '@/hooks/web/usePermission';
|
|
import { usePermission } from '@/hooks/web/usePermission';
|
|
|
|
|
|
|
|
|
|
+/** 支持v-permission直接传入string, string[],以及兼容原来的方法 */
|
|
|
export const permission: ObjectDirective = {
|
|
export const permission: ObjectDirective = {
|
|
|
mounted(el: HTMLButtonElement, binding) {
|
|
mounted(el: HTMLButtonElement, binding) {
|
|
|
- if (binding.value == undefined) return;
|
|
|
|
|
- const { action, effect } = binding.value;
|
|
|
|
|
|
|
+ const val = binding.value;
|
|
|
|
|
+ if (val === undefined) return;
|
|
|
|
|
+
|
|
|
|
|
+ let permissionVal: string[] = [];
|
|
|
|
|
+ if (typeof val === 'string') {
|
|
|
|
|
+ permissionVal = [val];
|
|
|
|
|
+ } else if (val instanceof Array) {
|
|
|
|
|
+ permissionVal = val;
|
|
|
|
|
+ }
|
|
|
const { hasPermission } = usePermission();
|
|
const { hasPermission } = usePermission();
|
|
|
|
|
+ if (!hasPermission(permissionVal)) {
|
|
|
|
|
+ el.remove();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const { action, effect } = val;
|
|
|
|
|
+
|
|
|
if (!hasPermission(action)) {
|
|
if (!hasPermission(action)) {
|
|
|
if (effect == 'disabled') {
|
|
if (effect == 'disabled') {
|
|
|
el.disabled = true;
|
|
el.disabled = true;
|