万纯 6f6bf341dd feat: 优化plugin-access和plugin-layout
plugin-access:
1. 添加<Access />组件控制权限
2. 添加v-access指令控制权限
3. 权限的范围改为role和accesId的并集

plugin-layout:
1. 判断是否加载locale插件改为使用api.hasPlugins
2. 提示优化
2021-01-14 12:56:31 +08:00

47 lines
1.2 KiB
JavaScript

import { watch } from 'vue';
const cache = new WeakMap();
const setDispaly = (el, access) => {
if (access.value) {
el.style.display = el._display;
} else {
el.style.display = 'none';
}
};
export default function createDirective(useAccess) {
return {
beforeMount(el) {
const ctx = {};
ctx.watch = (path) => {
el._display = el._display || el.style.display;
const access = useAccess(path);
setDispaly(el, access);
return watch(access, () => {
setDispaly(el, access);
});
};
cache.set(el, ctx);
},
mounted(el, binding) {
const ctx = cache.get(el);
if (ctx.unwatch) {
ctx.unwatch();
}
ctx.unwatch = ctx.watch(binding.value);
},
updated(el, binding) {
const ctx = cache.get(el);
if (ctx.unwatch) {
ctx.unwatch();
}
ctx.unwatch = ctx.watch(binding.value);
},
beforeUnmount(el) {
const ctx = cache.get(el);
if (ctx.unwatch) {
ctx.unwatch();
}
}
};
}