useProject.ts 525 B

1234567891011121314151617181920
  1. import { fetchProject } from '@/api'
  2. import { router } from '@/router'
  3. import { useRealtime } from './useRealtime'
  4. import type { Project } from '@/api'
  5. export const useProject = (
  6. id: Project['projectId'],
  7. onErr?: (err: any) => void
  8. ) => useRealtime(() => fetchProject(id).catch(onErr))[0]
  9. export const useCurrentProject = () => {
  10. const id = Number(router.currentRoute.value.params.id)
  11. const back = () => router.back()
  12. if (!id || id < 0) {
  13. back()
  14. throw '错误页面'
  15. }
  16. return useProject(id, back)
  17. }