mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-12-23 14:57:00 +08:00
plugin-access: 1. 添加<Access />组件控制权限 2. 添加v-access指令控制权限 3. 权限的范围改为role和accesId的并集 plugin-layout: 1. 判断是否加载locale插件改为使用api.hasPlugins 2. 提示优化
47 lines
1.2 KiB
JavaScript
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();
|
|
}
|
|
}
|
|
};
|
|
}
|