v0.0.2 - 修复分页按钮,添加numberFilter参数
This commit is contained in:
parent
9c70250234
commit
3faac301a0
|
|
@ -42,18 +42,20 @@ export default function YichensBoard() {
|
|||
}
|
||||
}
|
||||
|
||||
const fetchPosts = async (p, cat, kw) => {
|
||||
const fetchPosts = async (p, cat, kw, numFilter) => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
const currentPage = p !== undefined ? p : page
|
||||
const currentCat = cat !== undefined ? cat : categoryFilter
|
||||
const searchKw = kw !== undefined ? kw : searchKeyword
|
||||
const numFilterVal = numFilter !== undefined ? numFilter : numberFilter
|
||||
|
||||
let url = '/api/yichens/posts?limit=390&offset=' + ((currentPage - 1) * 390)
|
||||
if (postTypeFilter === 'deal') url += '&post_type=deal'
|
||||
else if (postTypeFilter === 'want') url += '&post_type=want'
|
||||
else if (postTypeFilter === 'other') url += '&post_type=normal'
|
||||
if (searchKw && searchKw.trim()) url += '&keyword=' + encodeURIComponent(searchKw.trim())
|
||||
if (numFilterVal && numFilterVal !== '') url += '&number_filter=' + encodeURIComponent(numFilterVal)
|
||||
|
||||
try {
|
||||
console.log('YichensBoard: 请求 posts', url)
|
||||
|
|
@ -273,12 +275,12 @@ export default function YichensBoard() {
|
|||
</div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
{page > 1 ? (
|
||||
<button onClick={() => { const newPage = page - 1; setPage(newPage); fetchPosts(newPage, categoryFilter, searchKeyword) }} style={{ padding: '6px 12px', borderRadius: 6, border: 'none', background: '#3b82f6', color: '#fff', cursor: 'pointer', fontSize: 12 }}>上一页</button>
|
||||
<button onClick={() => { const newPage = page - 1; setPage(newPage); fetchPosts(newPage, categoryFilter, searchKeyword, numberFilter) }} style={{ padding: '6px 12px', borderRadius: 6, border: 'none', background: '#3b82f6', color: '#fff', cursor: 'pointer', fontSize: 12 }}>上一页</button>
|
||||
) : (
|
||||
<span style={{ padding: '6px 12px', borderRadius: 6, background: '#374151', color: '#6b7280', fontSize: 12 }}>上一页</span>
|
||||
)}
|
||||
{posts.length >= 390 && totalPosts > page * 390 ? (
|
||||
<button onClick={() => { const newPage = page + 1; setPage(newPage); fetchPosts(newPage, categoryFilter, searchKeyword) }} style={{ padding: '6px 12px', borderRadius: 6, border: 'none', background: '#3b82f6', color: '#fff', cursor: 'pointer', fontSize: 12 }}>下一页</button>
|
||||
{posts.length >= 390 ? (
|
||||
<button onClick={() => { const newPage = page + 1; setPage(newPage); fetchPosts(newPage, categoryFilter, searchKeyword, numberFilter) }} style={{ padding: '6px 12px', borderRadius: 6, border: 'none', background: '#3b82f6', color: '#fff', cursor: 'pointer', fontSize: 12 }}>下一页</button>
|
||||
) : (
|
||||
<span style={{ padding: '6px 12px', borderRadius: 6, background: '#374151', color: '#6b7280', fontSize: 12 }}>下一页</span>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Reference in New Issue