feat: initial commit - oncology literature search platform
OncoLit: a multi-tenant oncology literature search, feed, and collaboration platform. Built with FastAPI + Vue 3 + PostgreSQL. Includes PubMed pipeline, drug approvals, AI summaries, and systematic review tools.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { ref, readonly, type Ref } from 'vue'
|
||||
|
||||
export function useApiRequest<T>(fetcher: (...args: any[]) => Promise<T>) {
|
||||
const data: Ref<T | null> = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function execute(...args: any[]): Promise<T | null> {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const result = await fetcher(...args)
|
||||
data.value = result
|
||||
return result
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.data?.detail || e?.message || '请求失败'
|
||||
error.value = msg
|
||||
return null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { data: readonly(data), loading: readonly(loading), error: readonly(error), execute }
|
||||
}
|
||||
Reference in New Issue
Block a user