feat(site): 方案 C - 「我常访问」个人榜(匿名 ID + localStorage 合并)
- NavClick 加 anon_id 字段(已为历史表自动迁移) - 后端静默下发 wk_anon cookie(uuid4,1 年,HttpOnly) - 点击埋点写入 anon_id;新增 GET /site/api/my-top 与 POST /site/api/my-clear - 首页服务端渲染「我常访问」区(时间衰减加权分),与「热门网址」共显 - 前端 localStorage 累计 + 与服务端榜取 max 合并;冷启动阈值 2 个网址 - 一键清除:清 localStorage + 服务端删该匿名 ID 的全部记录 - 移动端抽屉、顶部导航同步加「我常访问」入口 - 底部隐私说明更新
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
每条记录是用户点了一次某张 Nav 卡片跳出去的事件。
|
||||
- nav_id 关联 public_nav.id
|
||||
- anon_id 匿名访客 ID(后端静默下发的 cookie,不关联账号)
|
||||
- day YYYY-MM-DD 日期
|
||||
- ip 访客 IP(用于去重 / 隐私留存期控制)
|
||||
- clicked_at 点击时间
|
||||
@@ -16,6 +17,7 @@ class NavClick(db.Model):
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='记录ID')
|
||||
nav_id = db.Column(db.Integer, nullable=False, index=True, comment='被点击的导航ID')
|
||||
anon_id = db.Column(db.String(36), default='', index=True, comment='匿名访客ID')
|
||||
day = db.Column(db.String(10), default='', index=True, comment='日期 YYYY-MM-DD')
|
||||
ip = db.Column(db.String(64), default='', comment='访客IP')
|
||||
clicked_at = db.Column(db.DateTime, default=datetime.datetime.now, index=True, comment='点击时间')
|
||||
@@ -15,7 +15,10 @@ from collections import OrderedDict
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
|
||||
from applications.models import Nav, NavCategory
|
||||
from plugins.siteStats.view.stat import get_nav_visit_counts
|
||||
from plugins.siteStats.view.stat import get_nav_visit_counts, my_top_navs
|
||||
|
||||
# 「我常访问」冷启动阈值:至少点过这么多个不同网址才展示个人区
|
||||
MINE_MIN_ITEMS = 2
|
||||
|
||||
bp = Blueprint('public_nav', __name__, url_prefix='/site')
|
||||
|
||||
@@ -79,6 +82,7 @@ def get_category_meta() -> "dict[str, dict]":
|
||||
def _render_index():
|
||||
groups = _grouped_navs()
|
||||
total = sum(len(items) for items in groups.values())
|
||||
mine = my_top_navs(8)
|
||||
return render_template(
|
||||
'public/index.html',
|
||||
groups=groups,
|
||||
@@ -86,6 +90,7 @@ def _render_index():
|
||||
site_name='旺珂 · 导航',
|
||||
cat_meta=_category_meta(),
|
||||
top_navs=_top_navs(12),
|
||||
my_navs=mine if len(mine) >= MINE_MIN_ITEMS else [],
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user