Ben Lin
2024-06-18 ebbd788fbb2c0b45d4473798efc57eec8ba74a25
src/components/Drawer/src/useDrawer.ts
@@ -15,15 +15,15 @@
  toRaw,
  computed,
} from 'vue';
import { isProdMode } from '/@/utils/env';
import { isFunction } from '/@/utils/is';
import { isProdMode } from '@/utils/env';
import { isFunction } from '@/utils/is';
import { tryOnUnmounted } from '@vueuse/core';
import { isEqual } from 'lodash-es';
import { error } from '/@/utils/log';
import { error } from '@/utils/log';
const dataTransferRef = reactive<any>({});
const visibleData = reactive<{ [key: number]: boolean }>({});
const openData = reactive<{ [key: number]: boolean }>({});
/**
 * @description: Applicable to separate drawer and call outside
@@ -34,9 +34,9 @@
  }
  const drawer = ref<DrawerInstance | null>(null);
  const loaded = ref<Nullable<boolean>>(false);
  const uid = ref<string>('');
  const uid = ref<number>(0);
  function register(drawerInstance: DrawerInstance, uuid: string) {
  function register(drawerInstance: DrawerInstance, uuid: number) {
    isProdMode() &&
      tryOnUnmounted(() => {
        drawer.value = null;
@@ -51,8 +51,8 @@
    drawer.value = drawerInstance;
    loaded.value = true;
    drawerInstance.emitVisible = (visible: boolean, uid: number) => {
      visibleData[uid] = visible;
    drawerInstance.emitOpen = (open: boolean, uid: number) => {
      openData[uid] = open;
    };
  }
@@ -69,13 +69,13 @@
      getInstance()?.setDrawerProps(props);
    },
    getVisible: computed((): boolean => {
      return visibleData[~~unref(uid)];
    getOpen: computed((): boolean => {
      return openData[~~unref(uid)];
    }),
    openDrawer: <T = any>(visible = true, data?: T, openOnSet = true): void => {
    openDrawer: <T = any>(open = true, data?: T, openOnSet = true): void => {
      getInstance()?.setDrawerProps({
        visible: visible,
        open,
      });
      if (!data) return;
@@ -90,7 +90,7 @@
      }
    },
    closeDrawer: () => {
      getInstance()?.setDrawerProps({ visible: false });
      getInstance()?.setDrawerProps({ open: false });
    },
  };
@@ -100,7 +100,7 @@
export const useDrawerInner = (callbackFn?: Fn): UseDrawerInnerReturnType => {
  const drawerInstanceRef = ref<Nullable<DrawerInstance>>(null);
  const currentInstance = getCurrentInstance();
  const uidRef = ref<string>('');
  const uidRef = ref<number>(0);
  if (!getCurrentInstance()) {
    throw new Error('useDrawerInner() can only be used inside setup() or functional components!');
@@ -115,7 +115,7 @@
    return instance;
  };
  const register = (modalInstance: DrawerInstance, uuid: string) => {
  const register = (modalInstance: DrawerInstance, uuid: number) => {
    isProdMode() &&
      tryOnUnmounted(() => {
        drawerInstanceRef.value = null;
@@ -145,12 +145,12 @@
      changeOkLoading: (loading = true) => {
        getInstance()?.setDrawerProps({ confirmLoading: loading });
      },
      getVisible: computed((): boolean => {
        return visibleData[~~unref(uidRef)];
      getOpen: computed((): boolean => {
        return openData[~~unref(uidRef)];
      }),
      closeDrawer: () => {
        getInstance()?.setDrawerProps({ visible: false });
        getInstance()?.setDrawerProps({ open: false });
      },
      setDrawerProps: (props: Partial<DrawerProps>) => {