2026-04-06 20:40:42 +08:00
|
|
|
|
import { useEffect, useState } from "react"
|
2026-04-06 20:53:13 +08:00
|
|
|
|
import { Link } from "react-router-dom"
|
2026-04-06 17:57:25 +08:00
|
|
|
|
import { FirearmApi } from "@/api"
|
|
|
|
|
|
import { Firearm, FirearmType } from "@/types"
|
2026-04-06 20:53:13 +08:00
|
|
|
|
import { Button, Card, Col, Pagination, Row, Select, Tag, Typography } from "antd"
|
2026-04-06 17:57:25 +08:00
|
|
|
|
|
|
|
|
|
|
const firearmTypeText: Record<FirearmType, string> = {
|
|
|
|
|
|
RIFLE: "步枪",
|
|
|
|
|
|
SUB_MACHINE_GUN: "冲锋枪",
|
|
|
|
|
|
SHOTGUN: "霰弹枪",
|
|
|
|
|
|
LIGHT_MACHINE_GUN: "轻机枪",
|
|
|
|
|
|
DESIGNATED_MARKSMAN_RIFLE: "射手步枪",
|
|
|
|
|
|
SNIPER_RIFLE: "狙击步枪",
|
|
|
|
|
|
PISTOL: "手枪",
|
|
|
|
|
|
SPECIAL: "特殊",
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-06 20:47:44 +08:00
|
|
|
|
const allTypeValue = "ALL"
|
|
|
|
|
|
type FirearmTypeFilter = FirearmType | typeof allTypeValue
|
|
|
|
|
|
|
2026-04-06 17:57:25 +08:00
|
|
|
|
export default function FirearmsPage() {
|
2026-04-06 20:40:42 +08:00
|
|
|
|
const [page, setPage] = useState<number>(1)
|
2026-04-06 20:47:44 +08:00
|
|
|
|
const [typeFilter, setTypeFilter] = useState<FirearmTypeFilter>(allTypeValue)
|
2026-04-06 20:40:42 +08:00
|
|
|
|
const [firearms, setFirearms] = useState<Firearm[]>([])
|
|
|
|
|
|
const [total, setTotal] = useState<number>(0)
|
2026-04-06 17:57:25 +08:00
|
|
|
|
|
2026-04-06 20:40:42 +08:00
|
|
|
|
useEffect(() => {
|
2026-04-06 17:57:25 +08:00
|
|
|
|
FirearmApi.getFirearms({
|
2026-04-06 20:40:42 +08:00
|
|
|
|
page: page - 1,
|
|
|
|
|
|
size: 12,
|
|
|
|
|
|
sortBy: "id",
|
2026-04-06 17:57:25 +08:00
|
|
|
|
direction: "ASC",
|
2026-04-06 20:47:44 +08:00
|
|
|
|
type: typeFilter === allTypeValue ? undefined : typeFilter,
|
2026-04-06 20:40:42 +08:00
|
|
|
|
}).then((pagedData) => {
|
|
|
|
|
|
setFirearms(pagedData.items)
|
|
|
|
|
|
setTotal(pagedData.totalElements)
|
2026-04-06 17:57:25 +08:00
|
|
|
|
})
|
2026-04-06 20:47:44 +08:00
|
|
|
|
}, [page, typeFilter])
|
2026-04-06 17:57:25 +08:00
|
|
|
|
|
|
|
|
|
|
return (
|
2026-04-06 20:40:42 +08:00
|
|
|
|
<>
|
2026-04-06 20:47:44 +08:00
|
|
|
|
<div className="mb-4 flex justify-end">
|
|
|
|
|
|
<Select<FirearmTypeFilter>
|
|
|
|
|
|
className="w-full sm:w-64"
|
|
|
|
|
|
value={typeFilter}
|
|
|
|
|
|
options={[
|
|
|
|
|
|
{ value: allTypeValue, label: "全部类型" },
|
|
|
|
|
|
...Object.entries(firearmTypeText).map(([value, label]) => ({
|
|
|
|
|
|
value,
|
|
|
|
|
|
label,
|
|
|
|
|
|
})),
|
|
|
|
|
|
]}
|
|
|
|
|
|
onChange={(nextType) => {
|
|
|
|
|
|
setPage(1)
|
|
|
|
|
|
setTypeFilter(nextType)
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2026-04-06 20:40:42 +08:00
|
|
|
|
<div className="mb-6">
|
|
|
|
|
|
<Row gutter={[16, 16]}>
|
|
|
|
|
|
{firearms.map((firearm) => (
|
|
|
|
|
|
<Col key={firearm.id} xs={24} md={12} lg={8}>
|
|
|
|
|
|
<Card
|
|
|
|
|
|
title={firearm.name}
|
|
|
|
|
|
variant="outlined"
|
|
|
|
|
|
styles={{
|
|
|
|
|
|
header: { minHeight: 56 },
|
|
|
|
|
|
}}
|
2026-04-06 20:53:13 +08:00
|
|
|
|
actions={[
|
|
|
|
|
|
<Link key={`mod-codes-${firearm.id}`} to={`/mod-codes?firearmId=${firearm.id}`}>
|
|
|
|
|
|
<Button type="link">查看改枪码</Button>
|
|
|
|
|
|
</Link>,
|
|
|
|
|
|
]}
|
2026-04-06 20:40:42 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<Tag color="blue">{firearmTypeText[firearm.type]}</Tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Typography.Text>
|
2026-04-06 20:47:44 +08:00
|
|
|
|
<strong>武器输出等级:</strong>
|
2026-04-06 20:40:42 +08:00
|
|
|
|
{firearm.level}
|
|
|
|
|
|
</Typography.Text>
|
2026-04-06 20:47:44 +08:00
|
|
|
|
<Typography.Paragraph style={{ marginBottom: 0 }} type="secondary" ellipsis={{ rows: 3 }}>
|
2026-04-06 20:40:42 +08:00
|
|
|
|
{firearm.review || "暂无描述"}
|
|
|
|
|
|
</Typography.Paragraph>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
))}
|
|
|
|
|
|
{firearms.length === 0 && (
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<Typography.Text type="secondary">暂无武器数据</Typography.Text>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Row>
|
2026-04-06 17:57:25 +08:00
|
|
|
|
</div>
|
2026-04-06 20:40:42 +08:00
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
|
<Pagination
|
|
|
|
|
|
align="end"
|
|
|
|
|
|
current={page}
|
|
|
|
|
|
pageSize={12}
|
|
|
|
|
|
total={total}
|
|
|
|
|
|
onChange={(nextPage) => {
|
|
|
|
|
|
setPage(nextPage)
|
|
|
|
|
|
}}
|
|
|
|
|
|
showSizeChanger={false}
|
|
|
|
|
|
/>
|
2026-04-06 17:57:25 +08:00
|
|
|
|
</div>
|
2026-04-06 20:40:42 +08:00
|
|
|
|
</>
|
2026-04-06 17:57:25 +08:00
|
|
|
|
)
|
|
|
|
|
|
}
|