student-manage/apps/web/src/app/main/home/page.tsx

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-02-22 22:06:44 +08:00
import { api } from "@nice/client"
2025-02-23 20:17:53 +08:00
import { apiClient } from "@web/src/utils"
2025-02-23 19:37:11 +08:00
import { Button, Tag } from "antd"
import { useEffect, useMemo, useState } from "react"
2025-02-22 22:06:44 +08:00
2025-02-23 19:37:11 +08:00
function HomePage() {
2025-05-13 15:58:47 +08:00
const { data: staffData } = api.staff.findMany.useQuery({
2025-02-23 19:37:11 +08:00
take: 10
})
2025-05-13 15:58:47 +08:00
// 建议为不同的查询结果使用不同的变量名
const { data: goodsData } = api.goods.hello.useQuery({
name: "123"
})
2025-02-23 19:37:11 +08:00
const [counter, setCounter] = useState<number>(0)
const counterText = useMemo(() => {
return `当前计数为:${counter}`
}, [counter])
2025-02-23 20:17:53 +08:00
const getData = async () => {
2025-05-13 15:58:47 +08:00
// 第一种写法
// const res = await apiClient.get("/goods/hello")
// console.log(res)
//第二种写法
apiClient.get("/goods/hello")
.then(res => {
console.log(res)
})
2025-02-23 20:17:53 +08:00
}
2025-05-13 15:58:47 +08:00
useEffect(() => { getData() }, [])
2025-02-23 19:37:11 +08:00
return <div className="p-2 space-y-2">
<Tag>{counterText}</Tag>
<div className="space-x-2" >
<Button type="primary" onClick={() => {
setCounter(counter + 1)
}}>1</Button>
<Button danger
onClick={() => {
setCounter(counter - 1)
}}
>1</Button>
</div>
2025-05-13 15:58:47 +08:00
<div className="flex flex-wrap">{
staffData?.map(i => {
return <div className="p-2 rounded border shadow" key={i.id}>
2025-02-23 19:37:11 +08:00
<Tag>{i.username}</Tag>
</div>
})
2025-05-13 15:58:47 +08:00
} </div>
<Tag className="text-2xl">{goodsData}</Tag>
2025-02-23 19:37:11 +08:00
</div>
}
// export { HomePage }
export default HomePage