修改节点信息分页接口传参
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
|
macaddr?: string
|
||||||
public?: string
|
public?: string
|
||||||
city?: string
|
city?: string
|
||||||
isp?: string
|
isp?: string
|
||||||
},
|
},
|
||||||
page: number = 1) {
|
) {
|
||||||
try {
|
try {
|
||||||
const size = 250
|
|
||||||
const offset = Math.max(0, (page - 1)) * size
|
const offset = Math.max(0, (page - 1)) * size
|
||||||
// 构建查询条件
|
const limit = Math.min(100, Math.max(10, size))
|
||||||
let whereCondition = eq(edge.active, 1)
|
|
||||||
|
|
||||||
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([
|
const [total, data] = await Promise.all([
|
||||||
drizzle.$count(edge, eq(edge.active, 1)),
|
drizzle.$count(edge, eq(edge.active, 1)),
|
||||||
drizzle
|
drizzle
|
||||||
@@ -264,14 +250,15 @@ page: number = 1) {
|
|||||||
.where(eq(edge.active, 1))
|
.where(eq(edge.active, 1))
|
||||||
.orderBy(edge.id)
|
.orderBy(edge.id)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(size),
|
.limit(limit),
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
|
||||||
data,
|
data,
|
||||||
totalCount: total,
|
totalCount: total,
|
||||||
|
currentPage: Math.floor(offset / limit) + 1,
|
||||||
|
totalPages: Math.ceil(total / limit),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export default function Edge() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData({}, currentPage)
|
fetchData({})
|
||||||
}, [currentPage, itemsPerPage])
|
}, [currentPage, itemsPerPage])
|
||||||
|
|
||||||
const fetchData = async (val: {
|
const fetchData = async (val: {
|
||||||
@@ -52,11 +52,14 @@ export default function Edge() {
|
|||||||
public?: string
|
public?: string
|
||||||
city?: string
|
city?: string
|
||||||
isp?: string
|
isp?: string
|
||||||
}, page: number = 1) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
setError(null)
|
setError(null)
|
||||||
setLoading(true)
|
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 => ({
|
const validatedData = (result.data).map(item => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
macaddr: item.macaddr || '',
|
macaddr: item.macaddr || '',
|
||||||
@@ -90,7 +93,7 @@ export default function Edge() {
|
|||||||
isp: values.isp || undefined,
|
isp: values.isp || undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchData(filters, 1)
|
fetchData(filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 多IP节点格式化
|
// 多IP节点格式化
|
||||||
@@ -172,7 +175,7 @@ export default function Edge() {
|
|||||||
city: formValues.city || '',
|
city: formValues.city || '',
|
||||||
isp: formValues.isp || '',
|
isp: formValues.isp || '',
|
||||||
}
|
}
|
||||||
fetchData(filters, page)
|
fetchData(filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理每页显示数量变化
|
// 处理每页显示数量变化
|
||||||
@@ -186,7 +189,7 @@ export default function Edge() {
|
|||||||
city: formValues.city || '',
|
city: formValues.city || '',
|
||||||
isp: formValues.isp || '',
|
isp: formValues.isp || '',
|
||||||
}
|
}
|
||||||
fetchData(filters, 1)
|
fetchData(filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) return (
|
if (loading) return (
|
||||||
@@ -201,7 +204,7 @@ export default function Edge() {
|
|||||||
<h2 className="text-xl font-semibold text-gray-800 mb-4">节点列表</h2>
|
<h2 className="text-xl font-semibold text-gray-800 mb-4">节点列表</h2>
|
||||||
<div className="text-center py-8 text-red-600">{error}</div>
|
<div className="text-center py-8 text-red-600">{error}</div>
|
||||||
<button
|
<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"
|
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