Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
322ca28cb4 | ||
|
|
1a2d6ada88 |
@@ -31,12 +31,17 @@ def search_articles():
|
|||||||
"""搜索文章"""
|
"""搜索文章"""
|
||||||
keyword = request.args.get('q', '')
|
keyword = request.args.get('q', '')
|
||||||
category = request.args.get('category')
|
category = request.args.get('category')
|
||||||
|
limit = request.args.get('limit', type=int) # 支持limit参数
|
||||||
|
|
||||||
if not keyword:
|
if not keyword:
|
||||||
return jsonify({'error': '请提供搜索关键词'}), 400
|
return jsonify({'error': '请提供搜索关键词'}), 400
|
||||||
|
|
||||||
articles = db.search_articles(keyword, category)
|
articles = db.search_articles(keyword, category)
|
||||||
|
|
||||||
|
# 如果有limit参数,截取
|
||||||
|
if limit:
|
||||||
|
articles = articles[:limit]
|
||||||
|
|
||||||
# 解析JSON字段
|
# 解析JSON字段
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article['product_names'] = __import__('json').loads(article.get('product_names', '[]'))
|
article['product_names'] = __import__('json').loads(article.get('product_names', '[]'))
|
||||||
|
|||||||
@@ -102,6 +102,15 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-size-select {
|
||||||
|
padding: 10px 15px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
background: white;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.toolbar-right {
|
.toolbar-right {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
|||||||
+14
-2
@@ -4,7 +4,7 @@ const API_BASE = '';
|
|||||||
// 状态
|
// 状态
|
||||||
let articles = [];
|
let articles = [];
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
let pageSize = 100; // 增加每页数量
|
let pageSize = 100;
|
||||||
let totalCount = 0;
|
let totalCount = 0;
|
||||||
let selectedIds = new Set();
|
let selectedIds = new Set();
|
||||||
let currentArticleId = null;
|
let currentArticleId = null;
|
||||||
@@ -31,6 +31,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 改变每页数量
|
||||||
|
function changePageSize() {
|
||||||
|
pageSize = parseInt(document.getElementById('page-size').value);
|
||||||
|
currentPage = 1;
|
||||||
|
loadArticles();
|
||||||
|
}
|
||||||
|
|
||||||
// 加载文章列表
|
// 加载文章列表
|
||||||
async function loadArticles() {
|
async function loadArticles() {
|
||||||
const keyword = document.getElementById('search-input').value.trim();
|
const keyword = document.getElementById('search-input').value.trim();
|
||||||
@@ -42,7 +49,12 @@ async function loadArticles() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
const response = await fetch(`${API_BASE}/api/articles/search?q=${encodeURIComponent(keyword)}${category ? '&category=' + encodeURIComponent(category) : ''}`);
|
// 搜索时也传递 limit 参数
|
||||||
|
let searchUrl = `${API_BASE}/api/articles/search?q=${encodeURIComponent(keyword)}`;
|
||||||
|
if (category) searchUrl += `&category=${encodeURIComponent(category)}`;
|
||||||
|
searchUrl += `&limit=${pageSize}`;
|
||||||
|
|
||||||
|
const response = await fetch(searchUrl);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
|
|||||||
@@ -35,6 +35,13 @@
|
|||||||
<select id="category-filter" class="category-select">
|
<select id="category-filter" class="category-select">
|
||||||
<option value="">全部分类</option>
|
<option value="">全部分类</option>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="page-size" class="page-size-select" onchange="changePageSize()">
|
||||||
|
<option value="20">每页 20 条</option>
|
||||||
|
<option value="50">每页 50 条</option>
|
||||||
|
<option value="100" selected>每页 100 条</option>
|
||||||
|
<option value="200">每页 200 条</option>
|
||||||
|
<option value="500">每页 500 条</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="toolbar-right">
|
<div class="toolbar-right">
|
||||||
<button onclick="showAddModal()" class="btn btn-primary">
|
<button onclick="showAddModal()" class="btn btn-primary">
|
||||||
|
|||||||
Reference in New Issue
Block a user