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