修改节点信息分页接口传参
This commit is contained in:
@@ -220,31 +220,17 @@ export type Edge = {
|
||||
}
|
||||
|
||||
// 获取节点信息
|
||||
export async function getEdgeNodes(props?: {
|
||||
export async function getEdgeNodes(page: number, size: number, props?: {
|
||||
macaddr?: string
|
||||
public?: string
|
||||
city?: string
|
||||
isp?: string
|
||||
},
|
||||
page: number = 1) {
|
||||
) {
|
||||
try {
|
||||
const size = 250
|
||||
const offset = Math.max(0, (page - 1)) * size
|
||||
// 构建查询条件
|
||||
let whereCondition = eq(edge.active, 1)
|
||||
const limit = Math.min(100, Math.max(10, size))
|
||||
|
||||
if (props?.macaddr) {
|
||||
whereCondition = sql`${whereCondition} AND ${edge.macaddr} = ${props.macaddr}`
|
||||
}
|
||||
if (props?.public) {
|
||||
whereCondition = sql`${whereCondition} AND ${edge.public} LIKE ${`%${props.public}%`}`
|
||||
}
|
||||
if (props?.city) {
|
||||
whereCondition = sql`${whereCondition} AND ${cityhash.city} LIKE ${`%${props.city}%`}`
|
||||
}
|
||||
if (props?.isp) {
|
||||
whereCondition = sql`${whereCondition} AND ${edge.isp} LIKE ${`%${props.isp}%`}`
|
||||
}
|
||||
const [total, data] = await Promise.all([
|
||||
drizzle.$count(edge, eq(edge.active, 1)),
|
||||
drizzle
|
||||
@@ -264,14 +250,15 @@ page: number = 1) {
|
||||
.where(eq(edge.active, 1))
|
||||
.orderBy(edge.id)
|
||||
.offset(offset)
|
||||
.limit(size),
|
||||
.limit(limit),
|
||||
|
||||
])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
totalCount: total,
|
||||
currentPage: Math.floor(offset / limit) + 1,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function Edge() {
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
fetchData({}, currentPage)
|
||||
fetchData({})
|
||||
}, [currentPage, itemsPerPage])
|
||||
|
||||
const fetchData = async (val: {
|
||||
@@ -52,11 +52,14 @@ export default function Edge() {
|
||||
public?: string
|
||||
city?: string
|
||||
isp?: string
|
||||
}, page: number = 1) => {
|
||||
}) => {
|
||||
try {
|
||||
setError(null)
|
||||
setLoading(true)
|
||||
const result = await getEdgeNodes(val, page)
|
||||
|
||||
// 计算偏移量
|
||||
const offset = (currentPage - 1) * itemsPerPage
|
||||
const result = await getEdgeNodes(offset, itemsPerPage, val)
|
||||
const validatedData = (result.data).map(item => ({
|
||||
id: item.id,
|
||||
macaddr: item.macaddr || '',
|
||||
@@ -90,7 +93,7 @@ export default function Edge() {
|
||||
isp: values.isp || undefined,
|
||||
}
|
||||
|
||||
fetchData(filters, 1)
|
||||
fetchData(filters)
|
||||
}
|
||||
|
||||
// 多IP节点格式化
|
||||
@@ -172,7 +175,7 @@ export default function Edge() {
|
||||
city: formValues.city || '',
|
||||
isp: formValues.isp || '',
|
||||
}
|
||||
fetchData(filters, page)
|
||||
fetchData(filters)
|
||||
}
|
||||
|
||||
// 处理每页显示数量变化
|
||||
@@ -186,7 +189,7 @@ export default function Edge() {
|
||||
city: formValues.city || '',
|
||||
isp: formValues.isp || '',
|
||||
}
|
||||
fetchData(filters, 1)
|
||||
fetchData(filters)
|
||||
}
|
||||
|
||||
if (loading) return (
|
||||
@@ -201,7 +204,7 @@ export default function Edge() {
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-4">节点列表</h2>
|
||||
<div className="text-center py-8 text-red-600">{error}</div>
|
||||
<button
|
||||
onClick={() => fetchData({}, 1)}
|
||||
onClick={() => fetchData({})}
|
||||
className="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors mx-auto block"
|
||||
>
|
||||
重试
|
||||
|
||||
Reference in New Issue
Block a user