vue-confirm.ts 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { App, DirectiveBinding, VNode, createVNode } from "vue";
  2. import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
  3. import { Modal } from "ant-design-vue";
  4. import { listener, removeListener } from "@/helper";
  5. const confirmEvent = (binding: DirectiveBinding) => {
  6. Modal.confirm({
  7. title: "请确认您的操作",
  8. content: "确定删除该内容吗?",
  9. icon: createVNode(ExclamationCircleOutlined),
  10. okType: "danger",
  11. onOk: () => binding.value.call(),
  12. });
  13. };
  14. const bind = (
  15. el: HTMLElement | Element,
  16. binding: DirectiveBinding,
  17. vnode: VNode
  18. ) => {
  19. listener(el, () => confirmEvent(binding));
  20. };
  21. const unbind = (el: HTMLElement, binding: DirectiveBinding) => {
  22. removeListener(el, () => confirmEvent(binding));
  23. };
  24. const VueConfirmDirective = {
  25. install: (app: App<Element>) => {
  26. app.directive("confirm", {
  27. mounted: bind,
  28. unmounted: unbind,
  29. });
  30. },
  31. };
  32. export default VueConfirmDirective;