From 805e7869fce2d9b1f2660fcb9f55c3f157c0359d Mon Sep 17 00:00:00 2001 From: LazuliKao Date: Tue, 24 Sep 2024 20:54:36 +0800 Subject: [PATCH] add page --- src/pages/freshman/join.astro | 7 +- src/pages/freshman/list.astro | 10 +++ src/pages/freshman/react/join.tsx | 103 ++++++++++++++++++++++++------ src/pages/freshman/react/list.tsx | 65 +++++++++++++++++++ src/utils/active/services.gen.ts | 17 ++++- src/utils/active/types.gen.ts | 9 ++- src/utils/client.ts | 1 + 7 files changed, 184 insertions(+), 28 deletions(-) create mode 100644 src/pages/freshman/list.astro create mode 100644 src/pages/freshman/react/list.tsx diff --git a/src/pages/freshman/join.astro b/src/pages/freshman/join.astro index 0438a4a..4ae9a36 100644 --- a/src/pages/freshman/join.astro +++ b/src/pages/freshman/join.astro @@ -1,11 +1,10 @@ --- import BaseLayout from "../../layouts/BaseLayout.astro" -// import { Button } from "@nextui-org/react"; -import ReactChild from "./react/join.tsx" +import ReactChild from "./react/join.tsx"; --- - +
- +
diff --git a/src/pages/freshman/list.astro b/src/pages/freshman/list.astro new file mode 100644 index 0000000..9704909 --- /dev/null +++ b/src/pages/freshman/list.astro @@ -0,0 +1,10 @@ +--- +import BaseLayout from "../../layouts/BaseLayout.astro" +import ReactChild from "./react/list.tsx"; +--- + + +
+ +
+
diff --git a/src/pages/freshman/react/join.tsx b/src/pages/freshman/react/join.tsx index 737ba40..283d250 100644 --- a/src/pages/freshman/react/join.tsx +++ b/src/pages/freshman/react/join.tsx @@ -1,27 +1,90 @@ -import { Button } from "@nextui-org/react" +import { useState } from "react" +import { Button, Input, Card, CardBody, CardFooter } from "@nextui-org/react" import { activeClient } from "../../../utils/client" -export default function Page() { +export default function JoinForm() { + const [formData, setFormData] = useState({ + name: "", + class: "", + number: "", + major: "", + phone: "", + qq: "", + email: "", + }) + + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target + setFormData(prevData => ({ + ...prevData, + [name]: value, + })) + } + + const handleSubmit = async () => { + try { + await activeClient.freshman.postFreshmanAdd({ + requestBody: formData, + }) + alert("Form submitted successfully!") + } + catch (error) { + console.error("Error submitting form:", error) + alert("Failed to submit form.") + } + } + return (
- + + + + + + + + + + + + + +
) } diff --git a/src/pages/freshman/react/list.tsx b/src/pages/freshman/react/list.tsx new file mode 100644 index 0000000..8349087 --- /dev/null +++ b/src/pages/freshman/react/list.tsx @@ -0,0 +1,65 @@ +import { + // Button, + // Input, + Card, + CardBody, + CardFooter, + // PaginationItem, +} from "@nextui-org/react" +import { + activeClient, + type GetFreshmanListResponse, +} from "../../../utils/client" +// activeClient.freshman.getFreshmanList(); +import { useEffect, useState } from "react" +// import { Pagination } from "@nextui-org/react"; +const FreshmanList = () => { + const [freshmen, setFreshmen] = useState({ + list: [], + total: 0, + }) + const [currentPage, setCurrentPage] = useState(0) + useEffect(() => { + const fetchFreshmen = async () => { + const result = await activeClient.freshman.getFreshmanList({ + page: currentPage, + }) + setFreshmen(result) + } + fetchFreshmen() + }, []) + setTimeout(() => { + setCurrentPage(1) + }, 1000) + return ( +
+ + {JSON.stringify(freshmen)} + + {freshmen.list.map(freshman => ( +
+
{freshman.name}
+
{freshman.number}
+
{freshman.major}
+
{freshman.class}
+
{freshman.email}
+
{freshman.phone}
+
{freshman.qq}
+
+ ))} +
+ + {/* { + setCurrentPage(page); + }} + /> */} + +
+
+ ) +} + +export default FreshmanList diff --git a/src/utils/active/services.gen.ts b/src/utils/active/services.gen.ts index 69227d9..b7c8014 100644 --- a/src/utils/active/services.gen.ts +++ b/src/utils/active/services.gen.ts @@ -5,6 +5,7 @@ import type { BaseHttpRequest } from "./core/BaseHttpRequest"; import type { PostFreshmanAddData, PostFreshmanAddResponse, + GetFreshmanListData, GetFreshmanListResponse, } from "./types.gen"; @@ -15,7 +16,7 @@ export class FreshmanService { * 添加新人 * @param data The data for the request. * @param data.requestBody - * @returns unknown Returns the created task + * @returns unknown 返回创建结果 * @throws ApiError */ public postFreshmanAdd( @@ -31,13 +32,23 @@ export class FreshmanService { /** * 获取新人列表 - * @returns unknown Returns a list of tasks + * @param data The data for the request. + * @param data.page 页码 + * @returns unknown 返回列表 * @throws ApiError */ - public getFreshmanList(): CancelablePromise { + public getFreshmanList( + data: GetFreshmanListData = {}, + ): CancelablePromise { return this.httpRequest.request({ method: "GET", url: "/api/freshman", + query: { + page: data.page, + }, + errors: { + 500: "服务器错误", + }, }); } } diff --git a/src/utils/active/types.gen.ts b/src/utils/active/types.gen.ts index d5820af..11d49cc 100644 --- a/src/utils/active/types.gen.ts +++ b/src/utils/active/types.gen.ts @@ -26,8 +26,14 @@ export type PostFreshmanAddResponse = { error?: string; }; +export type GetFreshmanListData = { + /** + * 页码 + */ + page?: number; +}; + export type GetFreshmanListResponse = { - success: boolean; list: Array<{ name: string; number: string; @@ -37,4 +43,5 @@ export type GetFreshmanListResponse = { phone: string; qq: string; }>; + total: number; }; diff --git a/src/utils/client.ts b/src/utils/client.ts index 95b4349..bb2ce1d 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -11,3 +11,4 @@ export const saturdayClient = createClient({ export const activeClient = new ApiClient({ BASE: "/active", }) +export * from "./active/types.gen"