feat: add pure-admin-thin
This commit is contained in:
28
src/directives/elResizeDetector/index.ts
Normal file
28
src/directives/elResizeDetector/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Directive } from "vue";
|
||||
import type { DirectiveBinding, VNode } from "vue";
|
||||
import elementResizeDetectorMaker from "element-resize-detector";
|
||||
import type { Erd } from "element-resize-detector";
|
||||
import { emitter } from "/@/utils/mitt";
|
||||
|
||||
const erd: Erd = elementResizeDetectorMaker({
|
||||
strategy: "scroll"
|
||||
});
|
||||
|
||||
export const resize: Directive = {
|
||||
mounted(el: HTMLElement, binding?: DirectiveBinding, vnode?: VNode) {
|
||||
erd.listenTo(el, elem => {
|
||||
const width = elem.offsetWidth;
|
||||
const height = elem.offsetHeight;
|
||||
if (binding?.instance) {
|
||||
emitter.emit("resize", { detail: { width, height } });
|
||||
} else {
|
||||
vnode.el.dispatchEvent(
|
||||
new CustomEvent("resize", { detail: { width, height } })
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
unmounted(el: HTMLElement) {
|
||||
erd.uninstall(el);
|
||||
}
|
||||
};
|
2
src/directives/index.ts
Normal file
2
src/directives/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./permission";
|
||||
export * from "./elResizeDetector";
|
18
src/directives/permission/index.ts
Normal file
18
src/directives/permission/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
||||
import { Directive } from "vue";
|
||||
import type { DirectiveBinding } from "vue";
|
||||
|
||||
export const auth: Directive = {
|
||||
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
||||
const { value } = binding;
|
||||
if (value) {
|
||||
const authRoles = value;
|
||||
const hasAuth = usePermissionStoreHook().buttonAuth.includes(authRoles);
|
||||
if (!hasAuth) {
|
||||
el.style.display = "none";
|
||||
}
|
||||
} else {
|
||||
throw new Error("need roles! Like v-auth=\"['admin','test']\"");
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user