2026-04-06 21:02:16 +08:00
|
|
|
|
import { useEffect, useMemo, useState } from "react"
|
|
|
|
|
|
import { Link, useSearchParams } from "react-router-dom"
|
2026-04-07 11:59:37 +08:00
|
|
|
|
import { Button, Card, Col, Pagination, Row, Select, Space, Tag, Typography } from "antd"
|
|
|
|
|
|
import { ModificationApi, TagApi } from "@/api"
|
2026-04-06 21:02:16 +08:00
|
|
|
|
import { Modification } from "@/types"
|
|
|
|
|
|
|
|
|
|
|
|
const pageSize = 12
|
|
|
|
|
|
|
|
|
|
|
|
export default function ModCodesPage() {
|
|
|
|
|
|
const [searchParams] = useSearchParams()
|
|
|
|
|
|
const firearmId = useMemo(() => searchParams.get("firearmId") || undefined, [searchParams])
|
|
|
|
|
|
|
|
|
|
|
|
const [page, setPage] = useState<number>(1)
|
|
|
|
|
|
const [modifications, setModifications] = useState<Modification[]>([])
|
2026-04-07 11:59:37 +08:00
|
|
|
|
const [tagOptions, setTagOptions] = useState<string[]>([])
|
|
|
|
|
|
const [selectedTags, setSelectedTags] = useState<string[]>([])
|
2026-04-06 21:02:16 +08:00
|
|
|
|
const [total, setTotal] = useState<number>(0)
|
|
|
|
|
|
|
2026-04-07 11:59:37 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const _firearmId = firearmId ? +firearmId : (void 0)
|
|
|
|
|
|
TagApi.getTags(_firearmId).then((tags) => {
|
|
|
|
|
|
setTagOptions(tags)
|
|
|
|
|
|
})
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
2026-04-06 21:02:16 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
ModificationApi.getModifications({
|
|
|
|
|
|
page: page - 1,
|
|
|
|
|
|
size: pageSize,
|
|
|
|
|
|
sortBy: "id",
|
|
|
|
|
|
direction: "ASC",
|
|
|
|
|
|
firearmId,
|
2026-04-07 11:59:37 +08:00
|
|
|
|
tags: selectedTags,
|
2026-04-06 21:02:16 +08:00
|
|
|
|
}).then((pagedData) => {
|
|
|
|
|
|
setModifications(pagedData.items)
|
|
|
|
|
|
setTotal(pagedData.totalElements)
|
|
|
|
|
|
})
|
2026-04-07 11:59:37 +08:00
|
|
|
|
}, [page, firearmId, selectedTags])
|
2026-04-06 21:02:16 +08:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setPage(1)
|
|
|
|
|
|
}, [firearmId])
|
|
|
|
|
|
|
2026-04-07 11:59:37 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setPage(1)
|
|
|
|
|
|
}, [selectedTags])
|
|
|
|
|
|
|
2026-04-06 21:02:16 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div className="mb-4 flex items-center justify-between gap-4">
|
2026-04-07 01:28:34 +08:00
|
|
|
|
<Typography.Title level={4} className="mb-0!">
|
2026-04-06 21:02:16 +08:00
|
|
|
|
改枪码列表
|
|
|
|
|
|
</Typography.Title>
|
2026-04-07 11:59:37 +08:00
|
|
|
|
<Space wrap>
|
|
|
|
|
|
<span>标签:</span>
|
|
|
|
|
|
<Select<string[]>
|
|
|
|
|
|
mode="multiple"
|
|
|
|
|
|
allowClear
|
|
|
|
|
|
placeholder="请选择标签"
|
|
|
|
|
|
className="w-64"
|
|
|
|
|
|
value={selectedTags}
|
|
|
|
|
|
options={tagOptions.map((tag) => ({ value: tag, label: tag }))}
|
|
|
|
|
|
onChange={(values) => {
|
|
|
|
|
|
setSelectedTags(values)
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{firearmId && <Tag color="geekblue">武器 ID: {firearmId}</Tag>}
|
|
|
|
|
|
{(firearmId || selectedTags.length > 0) && (
|
2026-04-06 21:02:16 +08:00
|
|
|
|
<Link to="/mod-codes">
|
2026-04-07 11:59:37 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type="link"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setSelectedTags([])
|
|
|
|
|
|
setPage(1)
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
清除筛选
|
|
|
|
|
|
</Button>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
</Link>
|
2026-04-07 11:59:37 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</Space>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
|
<Row gutter={[16, 16]}>
|
|
|
|
|
|
{modifications.map((modification) => (
|
|
|
|
|
|
<Col key={modification.id} xs={24} md={12} lg={8}>
|
|
|
|
|
|
<Card
|
|
|
|
|
|
title={modification.name}
|
|
|
|
|
|
variant="outlined"
|
|
|
|
|
|
styles={{
|
|
|
|
|
|
header: { minHeight: 56 },
|
2026-04-07 11:59:37 +08:00
|
|
|
|
}}>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
<div className="flex flex-col gap-3">
|
2026-04-07 11:17:14 +08:00
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
|
<span>
|
|
|
|
|
|
<strong>改枪码:</strong>
|
2026-04-07 11:59:37 +08:00
|
|
|
|
<code className="bg-gray-400 px-2 py-1 rounded text-sm text-white">
|
|
|
|
|
|
{modification.code}
|
|
|
|
|
|
</code>
|
2026-04-07 11:17:14 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
size="small"
|
2026-04-07 11:59:37 +08:00
|
|
|
|
onClick={() => navigator.clipboard.writeText(modification.code)}>
|
2026-04-07 11:17:14 +08:00
|
|
|
|
复制
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
|
|
|
|
|
|
<Typography.Text>
|
|
|
|
|
|
<strong>作者:</strong>
|
|
|
|
|
|
{modification.author || "未知"}
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
|
|
|
|
|
|
{modification.tags.length > 0 && (
|
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
|
{modification.tags.map((tag) => (
|
|
|
|
|
|
<Tag key={`${modification.id}-${tag}`}>{tag}</Tag>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-04-07 11:59:37 +08:00
|
|
|
|
<Typography.Paragraph
|
|
|
|
|
|
style={{ marginBottom: 0 }}
|
|
|
|
|
|
type="secondary"
|
|
|
|
|
|
ellipsis={{ rows: 3 }}>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
{modification.note || "暂无备注"}
|
|
|
|
|
|
</Typography.Paragraph>
|
|
|
|
|
|
|
|
|
|
|
|
{modification.videoUrl && (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<a href={modification.videoUrl} target="_blank" rel="noopener noreferrer">
|
|
|
|
|
|
查看视频
|
|
|
|
|
|
</a>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
|
|
{modifications.length === 0 && (
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<Typography.Text type="secondary">暂无改枪码数据</Typography.Text>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
|
<Pagination
|
|
|
|
|
|
align="end"
|
|
|
|
|
|
current={page}
|
|
|
|
|
|
pageSize={pageSize}
|
|
|
|
|
|
total={total}
|
|
|
|
|
|
onChange={(nextPage) => {
|
|
|
|
|
|
setPage(nextPage)
|
|
|
|
|
|
}}
|
|
|
|
|
|
showSizeChanger={false}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|