55 lines
1.4 KiB
Markdown
55 lines
1.4 KiB
Markdown
|
||
|
||
使用:apps\popcore\lib\auth.ts中的loomart接口
|
||
封装 hooks 供页面使用
|
||
|
||
实例代码:
|
||
```tsx
|
||
import { loomart } from "@/lib/auth"
|
||
import { ApiError } from "@/lib/types"
|
||
import { useState } from "react"
|
||
export const useActivates = () => {
|
||
const [loading, setLoading] = useState<boolean>(false)
|
||
const [error, setError] = useState<ApiError | null>(null)
|
||
const [data, setData] = useState<{
|
||
activities: {
|
||
title: string;
|
||
titleEn: string;
|
||
desc: string;
|
||
descEn: string;
|
||
coverUrl: string;
|
||
link: string;
|
||
createdAt: Date;
|
||
updatedAt: Date;
|
||
id: string;
|
||
videoUrl?: string | null | undefined;
|
||
isActive?: boolean | null | undefined;
|
||
sortOrder?: number | null | undefined;
|
||
}[];
|
||
total: number;
|
||
page: number;
|
||
limit: number;
|
||
totalPages: number;
|
||
}>()
|
||
const load = async () => {
|
||
try {
|
||
setLoading(true)
|
||
const { data, error } = await loomart.activities.list({ isActive: true })
|
||
if (error) {
|
||
setError(error)
|
||
return;
|
||
}
|
||
setData(data)
|
||
} catch (e) {
|
||
setLoading(false)
|
||
}
|
||
}
|
||
|
||
return {
|
||
load,
|
||
loading,
|
||
error,
|
||
data
|
||
}
|
||
}
|
||
``` |