Merge branch 'dev' of https://github.com/nbtca/Home into dev

This commit is contained in:
ClasWen 2024-09-24 22:19:41 +08:00
commit 4f94c77dbe
8 changed files with 193 additions and 32 deletions

View file

@ -1,11 +1,10 @@
--- ---
import BaseLayout from "../../layouts/BaseLayout.astro" import BaseLayout from "../../layouts/BaseLayout.astro"
// import { Button } from "@nextui-org/react"; import ReactChild from "./react/join.tsx";
import ReactChild from "./react/join.tsx"
--- ---
<BaseLayout title="Welcome to Astro."> <BaseLayout title="加入我们">
<main> <main>
<ReactChild client:visible /> <ReactChild client:load />
</main> </main>
</BaseLayout> </BaseLayout>

View file

@ -0,0 +1,10 @@
---
import BaseLayout from "../../layouts/BaseLayout.astro"
import ReactChild from "./react/list.tsx";
---
<BaseLayout title="加入我们">
<main>
<ReactChild client:load />
</main>
</BaseLayout>

View file

@ -1,27 +1,97 @@
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" 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<HTMLInputElement>) => {
const { name, value } = e.target
setFormData(prevData => ({
...prevData,
[name]: value,
}))
}
const handleSubmit = async () => {
try {
await activeClient.freshman.postFreshmanAdd({
requestBody: formData,
})
alert("提交成功! 后续请加群获取!")
window.location.href = "/about"
}
catch (error) {
console.error("Error submitting form:", error)
alert("Failed to submit form.")
}
}
return ( return (
<div> <div>
<Button <form>
onClick={() => { <Card>
// 提交表单 <CardBody>
activeClient.freshman.postFreshmanAdd({ <Input
requestBody: { name="name"
class: "1", placeholder="姓名"
name: "1", value={formData.name}
phone: "1", onChange={handleChange}
qq: "1", required
email: "1", />
number: "1", <Input
major: "1", name="class"
}, placeholder="班级"
}) value={formData.class}
}} onChange={handleChange}
> required
/>
</Button> <Input
name="number"
placeholder="学号"
value={formData.number}
onChange={handleChange}
required
/>
<Input
name="major"
placeholder="专业"
value={formData.major}
onChange={handleChange}
required
/>
<Input
name="phone"
placeholder="电话"
value={formData.phone}
onChange={handleChange}
required
/>
<Input
name="qq"
placeholder="QQ"
value={formData.qq}
onChange={handleChange}
required
/>
<Input
name="email"
placeholder="邮箱"
value={formData.email}
onChange={handleChange}
required
/>
</CardBody>
<CardFooter>
<Button onClick={handleSubmit}></Button>
</CardFooter>
</Card>
</form>
</div> </div>
) )
} }

View file

@ -0,0 +1,61 @@
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<GetFreshmanListResponse>({
list: [],
total: 0,
})
const [currentPage] = useState(1) // setCurrentPage
useEffect(() => {
const fetchFreshmen = async () => {
const result = await activeClient.freshman.getFreshmanList({
page: currentPage,
})
setFreshmen(result)
}
fetchFreshmen()
}, [])
return (
<div>
<Card>
<CardBody>
{freshmen.list.map(freshman => (
<div key={freshman.number}>
<div>{freshman.name}</div>
<div>{freshman.number}</div>
<div>{freshman.major}</div>
<div>{freshman.class}</div>
<div>{freshman.email}</div>
<div>{freshman.phone}</div>
<div>{freshman.qq}</div>
</div>
))}
</CardBody>
<CardFooter>
{/* <PaginationItem
// count={Math.ceil(freshmen.total / ITEMS_PER_PAGE)}
page={currentPage}
onChange={(page) => {
setCurrentPage(page);
}}
/> */}
</CardFooter>
</Card>
</div>
)
}
export default FreshmanList

View file

@ -4,10 +4,12 @@ import Tile from "../layouts/Tile.astro"
import MoreTile from "../layouts/MoreTile.astro" import MoreTile from "../layouts/MoreTile.astro"
const allPosts = await Astro.glob("../pages/posts/*.md") const allPosts = await Astro.glob("../pages/posts/*.md")
const Blogs = await Astro.glob("../pages/posts/blogs/**/*.md") const Blogs = await Astro.glob("../pages/posts/blogs/**/*.md")
allPosts.sort( allPosts.sort((a, b) => {
(a, b) => if ((a.frontmatter.title as string).startsWith("计算机协会入社指南")) {
Date.parse(b.frontmatter.pubDate) - Date.parse(a.frontmatter.pubDate), return -99999999999
) }
return Date.parse(b.frontmatter.pubDate) - Date.parse(a.frontmatter.pubDate)
})
Blogs.sort( Blogs.sort(
(a, b) => (a, b) =>

View file

@ -5,6 +5,7 @@ import type { BaseHttpRequest } from "./core/BaseHttpRequest";
import type { import type {
PostFreshmanAddData, PostFreshmanAddData,
PostFreshmanAddResponse, PostFreshmanAddResponse,
GetFreshmanListData,
GetFreshmanListResponse, GetFreshmanListResponse,
} from "./types.gen"; } from "./types.gen";
@ -15,7 +16,7 @@ export class FreshmanService {
* *
* @param data The data for the request. * @param data The data for the request.
* @param data.requestBody * @param data.requestBody
* @returns unknown Returns the created task * @returns unknown
* @throws ApiError * @throws ApiError
*/ */
public postFreshmanAdd( 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 * @throws ApiError
*/ */
public getFreshmanList(): CancelablePromise<GetFreshmanListResponse> { public getFreshmanList(
data: GetFreshmanListData = {},
): CancelablePromise<GetFreshmanListResponse> {
return this.httpRequest.request({ return this.httpRequest.request({
method: "GET", method: "GET",
url: "/api/freshman", url: "/api/freshman",
query: {
page: data.page,
},
errors: {
500: "服务器错误",
},
}); });
} }
} }

View file

@ -26,8 +26,14 @@ export type PostFreshmanAddResponse = {
error?: string; error?: string;
}; };
export type GetFreshmanListData = {
/**
*
*/
page?: number;
};
export type GetFreshmanListResponse = { export type GetFreshmanListResponse = {
success: boolean;
list: Array<{ list: Array<{
name: string; name: string;
number: string; number: string;
@ -37,4 +43,5 @@ export type GetFreshmanListResponse = {
phone: string; phone: string;
qq: string; qq: string;
}>; }>;
total: number;
}; };

View file

@ -11,3 +11,4 @@ export const saturdayClient = createClient<saturdayPaths>({
export const activeClient = new ApiClient({ export const activeClient = new ApiClient({
BASE: "/active", BASE: "/active",
}) })
export * from "./active/types.gen"