/**
 * 请求响应处理
 * @param requestApi 请求接口
 * @param parameter 请求参数
 * @param loadingOrOptions ref-loading | vxe-loading (ref | obj)
 */
export async function useResponse(
    requestApi: any,
    parameter: any = {},
    loadingOrOptions?: Ref<boolean> | { loading?: boolean, value?: { loading: boolean } } | any
) {
  const setLoading = (value: boolean) => {
    if (isRef(loadingOrOptions)) {
      loadingOrOptions.value = value;
    } else if (typeof loadingOrOptions === 'object') {
      if ('loading' in loadingOrOptions) {
        loadingOrOptions.loading = value;
      } else if ('value' in loadingOrOptions && typeof loadingOrOptions.value === 'object') {
        loadingOrOptions.value.loading = value;
      }
    }
  };

  try {
    setLoading(true);
    return await requestApi(parameter);
  } catch (error) {
    console.error('Request Error==>', error);
  } finally {
    setLoading(false);
  }
}
