feat: 实现最新/热门/推荐标签功能
- 移除顶部热门工具排行榜模块 - 在标签下方添加三个tab(最新/热门/推荐) - 添加is_recommended字段到Site模型 - 创建数据库迁移脚本add_is_recommended.py - 更新后台管理界面支持推荐标记 - 更新分页链接保持tab状态 - 所有功能已本地测试验证通过 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
31
app.py
31
app.py
@@ -92,6 +92,7 @@ def create_app(config_name='default'):
|
||||
# 获取筛选参数
|
||||
tag_slug = request.args.get('tag')
|
||||
search_query = request.args.get('q', '').strip()
|
||||
current_tab = request.args.get('tab', 'latest') # 默认为"最新"
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = 100 # 每页显示100个站点
|
||||
|
||||
@@ -110,7 +111,8 @@ def create_app(config_name='default'):
|
||||
pagination = None
|
||||
return render_template('index_new.html', sites=sites, tags=tags,
|
||||
selected_tag=selected_tag, search_query=search_query,
|
||||
pagination=pagination, tag_counts=tag_counts)
|
||||
pagination=pagination, tag_counts=tag_counts,
|
||||
current_tab=current_tab)
|
||||
|
||||
# 搜索功能
|
||||
if search_query:
|
||||
@@ -125,19 +127,25 @@ def create_app(config_name='default'):
|
||||
)
|
||||
)
|
||||
|
||||
# 排序并分页
|
||||
query = query.order_by(Site.sort_order.desc(), Site.id.desc())
|
||||
# Tab筛选和排序
|
||||
if current_tab == 'popular':
|
||||
# 热门:按浏览次数倒序
|
||||
query = query.order_by(Site.view_count.desc(), Site.id.desc())
|
||||
elif current_tab == 'recommended':
|
||||
# 推荐:只显示is_recommended=True的
|
||||
query = query.filter_by(is_recommended=True).order_by(Site.sort_order.desc(), Site.id.desc())
|
||||
else:
|
||||
# 最新:按创建时间倒序(默认)
|
||||
query = query.order_by(Site.created_at.desc(), Site.id.desc())
|
||||
|
||||
# 分页
|
||||
pagination = query.paginate(page=page, per_page=per_page, error_out=False)
|
||||
sites = pagination.items
|
||||
|
||||
# 获取热门工具(按浏览次数排序,最多10个)
|
||||
popular_sites = Site.query.filter_by(is_active=True)\
|
||||
.order_by(Site.view_count.desc()).limit(10).all()
|
||||
|
||||
return render_template('index_new.html', sites=sites, tags=tags,
|
||||
selected_tag=selected_tag, search_query=search_query,
|
||||
pagination=pagination, tag_counts=tag_counts,
|
||||
popular_sites=popular_sites)
|
||||
current_tab=current_tab)
|
||||
|
||||
@app.route('/site/<code>')
|
||||
def site_detail(code):
|
||||
@@ -1349,9 +1357,9 @@ Sitemap: {}sitemap.xml
|
||||
column_display_actions = True
|
||||
action_disallowed_list = []
|
||||
|
||||
column_list = ['id', 'code', 'name', 'url', 'slug', 'is_active', 'view_count', 'created_at']
|
||||
column_list = ['id', 'code', 'name', 'url', 'slug', 'is_active', 'is_recommended', 'view_count', 'created_at']
|
||||
column_searchable_list = ['code', 'name', 'url', 'description']
|
||||
column_filters = ['is_active', 'tags']
|
||||
column_filters = ['is_active', 'is_recommended', 'tags']
|
||||
column_labels = {
|
||||
'id': 'ID',
|
||||
'code': '网站编码',
|
||||
@@ -1364,13 +1372,14 @@ Sitemap: {}sitemap.xml
|
||||
'features': '主要功能',
|
||||
'news_keywords': '新闻关键词',
|
||||
'is_active': '是否启用',
|
||||
'is_recommended': '是否推荐',
|
||||
'view_count': '浏览次数',
|
||||
'sort_order': '排序权重',
|
||||
'tags': '标签',
|
||||
'created_at': '创建时间',
|
||||
'updated_at': '更新时间'
|
||||
}
|
||||
form_columns = ['name', 'url', 'slug', 'logo', 'short_desc', 'description', 'features', 'news_keywords', 'tags', 'is_active', 'sort_order']
|
||||
form_columns = ['name', 'url', 'slug', 'logo', 'short_desc', 'description', 'features', 'news_keywords', 'tags', 'is_active', 'is_recommended', 'sort_order']
|
||||
|
||||
# 自定义编辑/删除文字
|
||||
column_extra_row_actions = None
|
||||
|
||||
Reference in New Issue
Block a user