办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
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 type {
  DescInstance,
  DescriptionProps,
  UseDescReturnType,
} from './typing';
 
import { getCurrentInstance, ref, unref } from 'vue';
 
export function useDescription(
  props?: Partial<DescriptionProps>,
): UseDescReturnType {
  if (!getCurrentInstance()) {
    throw new Error(
      'useDescription() can only be used inside setup() or functional components!',
    );
  }
  const desc = ref<DescInstance | null>(null);
  const loaded = ref(false);
 
  function register(instance: DescInstance) {
    // if (unref(loaded) && import.meta.env.PROD) {
    //   return;
    // }
    desc.value = instance;
    props && instance.setDescProps(props);
    loaded.value = true;
  }
 
  const methods: DescInstance = {
    setDescProps: (
      descProps: Partial<DescriptionProps>,
      delay = false,
    ): void => {
      if (!delay) {
        unref(desc)?.setDescProps(descProps);
        return;
      }
      // 奇怪的问题 在modal中需要setTimeout才会生效
      setTimeout(() => unref(desc)?.setDescProps(descProps));
    },
  };
 
  return [register, methods];
}