2026-04-26 11:40:30 +08:00
|
|
|
|
import {
|
|
|
|
|
|
App,
|
|
|
|
|
|
Button,
|
|
|
|
|
|
Card,
|
|
|
|
|
|
Col,
|
|
|
|
|
|
Pagination,
|
|
|
|
|
|
Popconfirm,
|
|
|
|
|
|
Row,
|
|
|
|
|
|
Select,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Tag,
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
} from "antd"
|
2026-04-23 16:12:48 +08:00
|
|
|
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
2026-04-06 21:02:16 +08:00
|
|
|
|
import { Link, useSearchParams } from "react-router-dom"
|
2026-04-07 11:59:37 +08:00
|
|
|
|
import { ModificationApi, TagApi } from "@/api"
|
2026-04-23 16:12:48 +08:00
|
|
|
|
import ModificationCreateModal from "@/components/modification-create-modal"
|
|
|
|
|
|
import ModificationEditModal from "@/components/modification-edit-modal"
|
2026-05-07 10:46:06 +08:00
|
|
|
|
import { useAppSelector } from "@/store/hooks"
|
2026-04-06 21:02:16 +08:00
|
|
|
|
import { Modification } from "@/types"
|
|
|
|
|
|
|
2026-05-06 01:31:05 +08:00
|
|
|
|
const pageSize = 10
|
2026-04-06 21:02:16 +08:00
|
|
|
|
|
|
|
|
|
|
export default function ModCodesPage() {
|
2026-04-14 11:57:43 +08:00
|
|
|
|
const user = useAppSelector((state) => state.auth.user)
|
2026-04-23 16:12:48 +08:00
|
|
|
|
const { message } = App.useApp()
|
2026-04-06 21:02:16 +08:00
|
|
|
|
const [searchParams] = useSearchParams()
|
|
|
|
|
|
const firearmId = useMemo(() => searchParams.get("firearmId") || undefined, [searchParams])
|
2026-04-23 16:12:48 +08:00
|
|
|
|
const parsedFirearmId = useMemo(() => {
|
|
|
|
|
|
if (!firearmId) {
|
|
|
|
|
|
return undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const value = Number(firearmId)
|
|
|
|
|
|
return Number.isFinite(value) ? value : undefined
|
|
|
|
|
|
}, [firearmId])
|
2026-04-06 21:02:16 +08:00
|
|
|
|
|
|
|
|
|
|
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-23 16:12:48 +08:00
|
|
|
|
const [deletingId, setDeletingId] = useState<number | null>(null)
|
|
|
|
|
|
const [createModalOpen, setCreateModalOpen] = useState(false)
|
|
|
|
|
|
const [editingModification, setEditingModification] = useState<Modification | null>(null)
|
2026-04-06 21:02:16 +08:00
|
|
|
|
|
2026-04-07 11:59:37 +08:00
|
|
|
|
useEffect(() => {
|
2026-04-23 16:12:48 +08:00
|
|
|
|
const _firearmId = firearmId ? +firearmId : void 0
|
2026-04-07 11:59:37 +08:00
|
|
|
|
TagApi.getTags(_firearmId).then((tags) => {
|
|
|
|
|
|
setTagOptions(tags)
|
|
|
|
|
|
})
|
2026-04-23 16:12:48 +08:00
|
|
|
|
}, [firearmId])
|
2026-04-07 11:59:37 +08:00
|
|
|
|
|
2026-04-25 15:31:17 +08:00
|
|
|
|
const loadModifications = useCallback(async () => {
|
2026-04-23 16:12:48 +08:00
|
|
|
|
return ModificationApi.getModifications({
|
2026-04-06 21:02:16 +08:00
|
|
|
|
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
|
|
|
|
|
2026-04-23 16:12:48 +08:00
|
|
|
|
useEffect(() => {
|
2026-04-25 15:31:17 +08:00
|
|
|
|
void loadModifications()
|
2026-04-23 16:12:48 +08:00
|
|
|
|
}, [loadModifications])
|
|
|
|
|
|
|
|
|
|
|
|
async function handleDelete(modification: Modification) {
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setDeletingId(modification.id)
|
|
|
|
|
|
try {
|
|
|
|
|
|
await ModificationApi.removeModification(modification.id)
|
|
|
|
|
|
message.success("改枪码删除成功")
|
|
|
|
|
|
if (modifications.length === 1 && page > 1) {
|
|
|
|
|
|
setPage(page - 1)
|
|
|
|
|
|
} else {
|
2026-04-25 15:31:17 +08:00
|
|
|
|
void loadModifications()
|
2026-04-23 16:12:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
message.error("改枪码删除失败,请稍后重试")
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setDeletingId(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 (
|
|
|
|
|
|
<>
|
2026-04-14 11:57:43 +08:00
|
|
|
|
<div className="mb-4 flex items-start 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-14 11:57:43 +08:00
|
|
|
|
<div className="flex flex-wrap items-center justify-end gap-3">
|
|
|
|
|
|
<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) && (
|
|
|
|
|
|
<Link to="/mod-codes">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="link"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setSelectedTags([])
|
|
|
|
|
|
setPage(1)
|
2026-04-26 11:40:30 +08:00
|
|
|
|
}}>
|
2026-04-14 11:57:43 +08:00
|
|
|
|
清除筛选
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Space>
|
2026-04-23 16:12:48 +08:00
|
|
|
|
{user && (
|
|
|
|
|
|
<Button type="primary" onClick={() => setCreateModalOpen(true)}>
|
|
|
|
|
|
添加改装
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
2026-04-14 11:57:43 +08:00
|
|
|
|
</div>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
|
<Row gutter={[16, 16]}>
|
|
|
|
|
|
{modifications.map((modification) => (
|
2026-04-23 16:12:48 +08:00
|
|
|
|
<Col key={modification.id} span={24}>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
<Card
|
|
|
|
|
|
title={modification.name}
|
2026-04-14 11:57:43 +08:00
|
|
|
|
extra={
|
|
|
|
|
|
user ? (
|
2026-04-23 16:12:48 +08:00
|
|
|
|
<div className="flex items-center gap-1">
|
2026-04-26 11:40:30 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type="link"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
onClick={() => setEditingModification(modification)}>
|
2026-04-23 16:12:48 +08:00
|
|
|
|
编辑
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Popconfirm
|
|
|
|
|
|
title="确认删除改枪码"
|
|
|
|
|
|
description={`确定要删除 ${modification.name} 吗?该操作不可撤销。`}
|
|
|
|
|
|
okText="删除"
|
|
|
|
|
|
cancelText="取消"
|
|
|
|
|
|
okButtonProps={{ danger: true, loading: deletingId === modification.id }}
|
2026-04-26 11:40:30 +08:00
|
|
|
|
onConfirm={() => handleDelete(modification)}>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="link"
|
|
|
|
|
|
danger
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
loading={deletingId === modification.id}>
|
2026-04-23 16:12:48 +08:00
|
|
|
|
删除
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
|
</div>
|
2026-04-14 11:57:43 +08:00
|
|
|
|
) : null
|
|
|
|
|
|
}
|
2026-04-06 21:02:16 +08:00
|
|
|
|
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-05-25 14:04:32 +08:00
|
|
|
|
|
2026-04-06 21:02:16 +08:00
|
|
|
|
<Typography.Text>
|
|
|
|
|
|
<strong>作者:</strong>
|
|
|
|
|
|
{modification.author || "未知"}
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
|
2026-04-23 16:12:48 +08:00
|
|
|
|
{(modification.tags?.length || 0) > 0 && (
|
2026-04-06 21:02:16 +08:00
|
|
|
|
<div className="flex flex-wrap gap-2">
|
2026-04-23 16:12:48 +08:00
|
|
|
|
{(modification.tags || []).map((tag) => (
|
2026-04-06 21:02:16 +08:00
|
|
|
|
<Tag key={`${modification.id}-${tag}`}>{tag}</Tag>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-04-23 16:12:48 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<Typography.Text strong>配件配置:</Typography.Text>
|
|
|
|
|
|
{(modification.accessories?.length || 0) > 0 ? (
|
|
|
|
|
|
<div className="mt-2 overflow-x-auto">
|
|
|
|
|
|
<div className="grid min-w-275 grid-cols-5 gap-2">
|
|
|
|
|
|
{(modification.accessories || []).map((accessory, accessoryIndex) => (
|
2026-04-26 11:40:30 +08:00
|
|
|
|
<div
|
|
|
|
|
|
key={`${modification.id}-accessory-${accessoryIndex}`}
|
|
|
|
|
|
className="rounded border border-gray-100 p-2">
|
2026-04-23 16:12:48 +08:00
|
|
|
|
<div className="flex items-center justify-between gap-2 rounded bg-gray-50 px-2 py-1">
|
2026-04-26 11:40:30 +08:00
|
|
|
|
<Typography color="blue" className="mr-0">
|
|
|
|
|
|
{accessory.slotName || "未填写槽位"}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
<Typography className="mr-0 text-[#4C1D95]">
|
|
|
|
|
|
{accessory.accessoryName || "未填写配件"}
|
|
|
|
|
|
</Typography>
|
2026-04-23 16:12:48 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
{(accessory.tunings?.length || 0) > 0 ? (
|
|
|
|
|
|
<div className="mt-2 flex flex-wrap gap-1">
|
|
|
|
|
|
{accessory.tunings.map((tuning, tuningIndex) => (
|
2026-04-26 11:40:30 +08:00
|
|
|
|
<Tag
|
|
|
|
|
|
key={`${modification.id}-${accessoryIndex}-tuning-${tuningIndex}`}
|
|
|
|
|
|
color="geekblue">
|
2026-04-23 16:12:48 +08:00
|
|
|
|
{tuning.tuningName || "未命名"}: {tuning.tuningValue ?? "-"}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Typography.Text type="secondary" className="block mt-1">
|
|
|
|
|
|
暂无配件信息
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</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>
|
2026-04-23 16:12:48 +08:00
|
|
|
|
|
|
|
|
|
|
<ModificationCreateModal
|
|
|
|
|
|
open={createModalOpen}
|
|
|
|
|
|
defaultFirearmId={parsedFirearmId}
|
|
|
|
|
|
lockedFirearmId={parsedFirearmId}
|
|
|
|
|
|
onCancel={() => setCreateModalOpen(false)}
|
|
|
|
|
|
onSuccess={() => {
|
|
|
|
|
|
setCreateModalOpen(false)
|
2026-04-24 19:47:03 +08:00
|
|
|
|
void loadModifications()
|
2026-04-23 16:12:48 +08:00
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<ModificationEditModal
|
|
|
|
|
|
open={!!editingModification}
|
|
|
|
|
|
modification={editingModification}
|
|
|
|
|
|
lockedFirearmId={parsedFirearmId}
|
|
|
|
|
|
onCancel={() => setEditingModification(null)}
|
|
|
|
|
|
onSuccess={() => {
|
|
|
|
|
|
setEditingModification(null)
|
2026-04-24 19:47:03 +08:00
|
|
|
|
void loadModifications()
|
2026-04-23 16:12:48 +08:00
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2026-04-06 21:02:16 +08:00
|
|
|
|
</>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|