useFullScreen.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { computed, Ref, ref, unref } from 'vue';
  2. export interface UseFullScreenContext {
  3. wrapClassName: Ref<string | undefined>;
  4. modalWrapperRef: Ref<ComponentRef>;
  5. extHeightRef: Ref<number>;
  6. }
  7. export function useFullScreen(context: UseFullScreenContext) {
  8. const formerHeightRef = ref(0);
  9. const fullScreenRef = ref(false);
  10. const getWrapClassName = computed(() => {
  11. const clsName = unref(context.wrapClassName) || '';
  12. return unref(fullScreenRef) ? `fullscreen-modal ${clsName} ` : unref(clsName);
  13. });
  14. function handleFullScreen(e: Event) {
  15. e && e.stopPropagation();
  16. fullScreenRef.value = !unref(fullScreenRef);
  17. const modalWrapper = unref(context.modalWrapperRef);
  18. if (!modalWrapper) return;
  19. const wrapperEl = modalWrapper.$el as HTMLElement;
  20. if (!wrapperEl) return;
  21. const modalWrapSpinEl = wrapperEl.querySelector('.ant-spin-nested-loading') as HTMLElement;
  22. if (!modalWrapSpinEl) return;
  23. if (!unref(formerHeightRef) && unref(fullScreenRef)) {
  24. formerHeightRef.value = modalWrapSpinEl.offsetHeight;
  25. }
  26. if (unref(fullScreenRef)) {
  27. modalWrapSpinEl.style.height = `${window.innerHeight - unref(context.extHeightRef)}px`;
  28. } else {
  29. modalWrapSpinEl.style.height = `${unref(formerHeightRef)}px`;
  30. }
  31. }
  32. return { getWrapClassName, handleFullScreen, fullScreenRef };
  33. }