刘光辉
10 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
import type { ComputedRef } from 'vue';
 
import type { BasicTableProps } from '../types/table';
 
import { computed, ref, unref, watch } from 'vue';
 
export function useLoading(props: ComputedRef<BasicTableProps>) {
  const loadingRef = ref(unref(props).loading);
  const loadingTipRef = ref(unref(props).loadingTip);
 
  watch(
    () => [unref(props).loading, unref(props).loadingTip] as const,
    ([loading, loadingTip]) => {
      loadingRef.value = loading;
      loadingTipRef.value = loadingTip;
    },
  );
 
  const getLoading = computed(() => unref(loadingRef));
  const getLoadingTip = computed(() => unref(loadingTipRef));
 
  function setLoading(loading: boolean, tip?: string) {
    loadingRef.value = loading;
    loadingTipRef.value = loading ? tip : undefined;
  }
 
  return { getLoading, getLoadingTip, setLoading };
}