新增数据分析板块

This commit is contained in:
ucmao
2026-01-05 21:22:43 +08:00
parent 4e2303beae
commit a9d428bdd9
8 changed files with 591 additions and 84 deletions
+1
View File
@@ -33,6 +33,7 @@ CREATE TABLE IF NOT EXISTS `parse_library` (
`video_url` text COLLATE utf8mb4_general_ci NOT NULL COMMENT '视频播放URL',
`score` int(11) DEFAULT '0' COMMENT '视频评分',
`is_visible` tinyint(1) DEFAULT '1' COMMENT '是否显示给前端 (0:隐藏, 1:显示)',
`last_user_id` int(11) DEFAULT NULL COMMENT '最后解析该视频的用户ID',
`create_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`video_id`)
+129 -4
View File
@@ -1,7 +1,7 @@
from flask import Blueprint, render_template, request, session, redirect, url_for, flash, jsonify
import os
import json
from datetime import datetime
from datetime import datetime, timedelta
from configs.general_constants import DATABASE_CONFIG
from src.database.db_manager import DBManager
from configs.logging_config import logger
@@ -80,14 +80,25 @@ def dashboard():
cursor.execute("SELECT COUNT(*) as count FROM users")
user_count = cursor.fetchone()['count']
# 最近 10 条视频
cursor.execute("SELECT * FROM parse_library ORDER BY create_at DESC LIMIT 10")
# 今日活跃 (DAU)
cursor.execute("SELECT COUNT(*) as count FROM users WHERE DATE(updated_at) = CURDATE()")
active_user_count = cursor.fetchone()['count']
# 最近 10 条视频 (关联用户信息)
cursor.execute("""
SELECT pl.*, u.nickname as last_user_name
FROM parse_library pl
LEFT JOIN users u ON pl.last_user_id = u.user_id
ORDER BY pl.create_at DESC
LIMIT 10
""")
recent_videos = cursor.fetchall()
db.disconnect()
return render_template('admin_modern/dashboard.html',
video_count=video_count,
user_count=user_count,
active_user_count=active_user_count,
recent_videos=recent_videos)
@bp.route('/videos')
@@ -105,8 +116,13 @@ def videos():
# 搜索
search = request.args.get('search', '')
platform = request.args.get('platform', '')
visibility = request.args.get('visibility', '')
start_date = request.args.get('start_date', '')
end_date = request.args.get('end_date', '')
min_score = request.args.get('min_score', '')
max_score = request.args.get('max_score', '')
query = "SELECT * FROM parse_library WHERE 1=1"
query = "SELECT pl.*, u.nickname as last_user_name FROM parse_library pl LEFT JOIN users u ON pl.last_user_id = u.user_id WHERE 1=1"
params = []
if search:
@@ -115,6 +131,21 @@ def videos():
if platform:
query += " AND platform = %s"
params.append(platform)
if visibility != '':
query += " AND is_visible = %s"
params.append(visibility)
if start_date:
query += " AND DATE(create_at) >= %s"
params.append(start_date)
if end_date:
query += " AND DATE(create_at) <= %s"
params.append(end_date)
if min_score:
query += " AND score >= %s"
params.append(min_score)
if max_score:
query += " AND score <= %s"
params.append(max_score)
# 获取总数用于分页
cursor.execute(f"SELECT COUNT(*) as count FROM ({query}) as t", params)
@@ -141,6 +172,11 @@ def videos():
limit=limit,
search=search,
platform=platform,
visibility=visibility,
start_date=start_date,
end_date=end_date,
min_score=min_score,
max_score=max_score,
sort_by=sort_by,
order=order)
@@ -284,6 +320,95 @@ def clear_user_records():
finally:
db.disconnect()
@bp.route('/analysis')
@login_required
def analysis():
return render_template('admin_modern/analysis.html')
@bp.route('/api/analysis_data')
@login_required
def analysis_data():
db = get_db()
cursor = db.conn.cursor(dictionary=True)
try:
# 1. 最近 14 天活跃解析趋势 (基于 parse_library.create_at)
cursor.execute("""
SELECT DATE_FORMAT(create_at, '%m-%d') as date, COUNT(*) as count
FROM parse_library
WHERE create_at >= DATE_SUB(CURDATE(), INTERVAL 14 DAY)
GROUP BY DATE(create_at)
ORDER BY DATE(create_at) ASC
""")
parse_trend = cursor.fetchall()
# 2. 最近 14 天新用户增长趋势
cursor.execute("""
SELECT DATE_FORMAT(created_at, '%m-%d') as date, COUNT(*) as count
FROM users
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL 14 DAY)
GROUP BY DATE(created_at)
ORDER BY DATE(created_at) ASC
""")
user_trend = cursor.fetchall()
# 3. 平台分布 (饼图)
cursor.execute("""
SELECT platform, COUNT(*) as count
FROM parse_library
GROUP BY platform
""")
platform_dist = cursor.fetchall()
# 4. 用户地域分布 (Top 10 省份)
cursor.execute("""
SELECT province, COUNT(*) as count
FROM users
WHERE province IS NOT NULL AND province != ''
GROUP BY province
ORDER BY count DESC
LIMIT 10
""")
province_dist = cursor.fetchall()
# 5. 总计数据
cursor.execute("SELECT COUNT(*) as total FROM parse_library")
total_parses = cursor.fetchone()['total']
cursor.execute("SELECT COUNT(*) as total FROM users")
total_users = cursor.fetchone()['total']
# 今日解析
cursor.execute("SELECT COUNT(*) as total FROM parse_library WHERE DATE(create_at) = CURDATE()")
today_parses = cursor.fetchone()['total']
# 今日新用户
cursor.execute("SELECT COUNT(*) as total FROM users WHERE DATE(created_at) = CURDATE()")
today_new_users = cursor.fetchone()['total']
# 今日活跃用户 (DAU)
cursor.execute("SELECT COUNT(*) as total FROM users WHERE DATE(updated_at) = CURDATE()")
today_active_users = cursor.fetchone()['total']
return jsonify({
'success': True,
'parse_trend': parse_trend,
'user_trend': user_trend,
'platform_dist': platform_dist,
'province_dist': province_dist,
'stats': {
'total_parses': total_parses,
'total_users': total_users,
'today_parses': today_parses,
'today_new_users': today_new_users,
'today_active_users': today_active_users
}
})
except Exception as e:
logger.error(f"Analysis data error: {e}")
return jsonify({'success': False, 'message': str(e)}), 500
finally:
db.disconnect()
@bp.route('/scores')
@login_required
def scores():
+2
View File
@@ -59,6 +59,7 @@ class DataStorageManager:
try:
if data_dict.get('video_url'):
self.update_dict.update(data_dict)
self.update_dict['last_user_id'] = user_id
manager.update_table_parse_library(**self.update_dict)
manager.add_video(user_id, video_id)
finally:
@@ -69,6 +70,7 @@ class DataStorageManager:
try:
if data_dict.get('video_url'):
self.update_dict.update(data_dict)
self.update_dict['last_user_id'] = user_id
manager.upsert_table_parse_library(**self.update_dict)
manager.add_video(user_id, video_id)
finally:
+282
View File
@@ -0,0 +1,282 @@
{% extends "admin_modern/base.html" %}
{% block title %}数据统计分析 - Ucmao Admin{% endblock %}
{% block content %}
<div class="mb-8">
<h1 class="text-3xl font-black text-slate-800 tracking-tight">数据统计分析</h1>
<p class="text-slate-500 mt-2 font-medium">全方位洞察系统运行状态与用户行为趋势</p>
</div>
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 flex items-center space-x-4">
<div class="w-14 h-14 bg-indigo-50 text-indigo-600 rounded-2xl flex items-center justify-center text-2xl shadow-inner">
<i class="fas fa-users"></i>
</div>
<div>
<div class="text-slate-400 text-xs font-bold uppercase tracking-widest mb-1">总用户数</div>
<div class="text-2xl font-black text-slate-800" id="stat-total-users">-</div>
<div class="text-[10px] text-emerald-500 font-bold mt-1">今日新增: +<span id="stat-today-users">-</span></div>
</div>
</div>
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 flex items-center space-x-4">
<div class="w-14 h-14 bg-emerald-50 text-emerald-600 rounded-2xl flex items-center justify-center text-2xl shadow-inner">
<i class="fas fa-bolt"></i>
</div>
<div>
<div class="text-slate-400 text-xs font-bold uppercase tracking-widest mb-1">今日活跃 (DAU)</div>
<div class="text-2xl font-black text-slate-800" id="stat-active-users">-</div>
<div class="text-[10px] text-slate-400 font-medium mt-1">基于用户最后交互时间</div>
</div>
</div>
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 flex items-center space-x-4">
<div class="w-14 h-14 bg-amber-50 text-amber-600 rounded-2xl flex items-center justify-center text-2xl shadow-inner">
<i class="fas fa-file-video"></i>
</div>
<div>
<div class="text-slate-400 text-xs font-bold uppercase tracking-widest mb-1">总解析量</div>
<div class="text-2xl font-black text-slate-800" id="stat-total-parses">-</div>
<div class="text-[10px] text-emerald-500 font-bold mt-1">今日解析: +<span id="stat-today-parses">-</span></div>
</div>
</div>
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 flex items-center space-x-4">
<div class="w-14 h-14 bg-rose-50 text-rose-600 rounded-2xl flex items-center justify-center text-2xl shadow-inner">
<i class="fas fa-chart-line"></i>
</div>
<div>
<div class="text-slate-400 text-xs font-bold uppercase tracking-widest mb-1">解析转化率</div>
<div class="text-2xl font-black text-slate-800" id="stat-conversion">-</div>
<div class="text-[10px] text-slate-400 font-medium mt-1">平均每人解析次数</div>
</div>
</div>
</div>
<!-- Main Trend Chart -->
<div class="bg-white p-8 rounded-[2.5rem] shadow-sm border border-slate-100 mb-8">
<div class="flex items-center justify-between mb-6">
<div>
<h3 class="text-xl font-black text-slate-800">业务增长趋势</h3>
<p class="text-slate-400 text-sm font-medium">最近 14 天的解析量与新用户增长对比</p>
</div>
<div class="flex items-center space-x-4">
<div class="flex items-center text-xs font-bold text-slate-500">
<span class="w-3 h-3 bg-indigo-500 rounded-full mr-2"></span> 解析量
</div>
<div class="flex items-center text-xs font-bold text-slate-500">
<span class="w-3 h-3 bg-emerald-500 rounded-full mr-2"></span> 新用户
</div>
</div>
</div>
<div id="trend-chart" class="h-80 w-full"></div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<!-- Platform Distribution -->
<div class="bg-white p-8 rounded-[2.5rem] shadow-sm border border-slate-100">
<h3 class="text-xl font-black text-slate-800 mb-6">平台使用分布</h3>
<div id="platform-chart" class="h-80 w-full"></div>
</div>
<!-- Geographic Distribution -->
<div class="bg-white p-8 rounded-[2.5rem] shadow-sm border border-slate-100">
<h3 class="text-xl font-black text-slate-800 mb-6">用户地区活跃排行 (Top 10)</h3>
<div id="geo-chart" class="h-80 w-full"></div>
</div>
</div>
<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
fetchAnalysisData();
});
function fetchAnalysisData() {
fetch('/admin/api/analysis_data')
.then(response => response.json())
.then(data => {
if(data.success) {
updateStats(data.stats);
renderTrendChart(data.parse_trend, data.user_trend);
renderPlatformChart(data.platform_dist);
renderGeoChart(data.province_dist);
} else {
showToast('获取数据失败: ' + data.message, 'error');
}
})
.catch(err => {
console.error(err);
showToast('系统错误,请重试', 'error');
});
}
function updateStats(stats) {
document.getElementById('stat-total-users').textContent = stats.total_users;
document.getElementById('stat-today-users').textContent = stats.today_new_users;
document.getElementById('stat-active-users').textContent = stats.today_active_users;
document.getElementById('stat-total-parses').textContent = stats.total_parses;
document.getElementById('stat-today-parses').textContent = stats.today_parses;
const conversion = stats.total_users > 0 ? (stats.total_parses / stats.total_users).toFixed(1) : '0';
document.getElementById('stat-conversion').textContent = conversion + 'x';
}
function renderTrendChart(parseTrend, userTrend) {
const dates = [...new Set([...parseTrend.map(i => i.date), ...userTrend.map(i => i.date)])].sort();
const parseData = dates.map(d => {
const found = parseTrend.find(i => i.date === d);
return found ? found.count : 0;
});
const userData = dates.map(d => {
const found = userTrend.find(i => i.date === d);
return found ? found.count : 0;
});
const options = {
series: [
{ name: '解析量', data: parseData },
{ name: '新用户', data: userData }
],
chart: {
height: 350,
type: 'area',
toolbar: { show: false },
fontFamily: 'Inter, sans-serif'
},
colors: ['#6366f1', '#10b981'],
dataLabels: { enabled: false },
stroke: { curve: 'smooth', width: 3 },
fill: {
type: 'gradient',
gradient: {
shadeIntensity: 1,
opacityFrom: 0.45,
opacityTo: 0.05,
stops: [20, 100]
}
},
xaxis: {
categories: dates,
axisBorder: { show: false },
axisTicks: { show: false },
labels: { style: { colors: '#94a3b8', fontWeight: 600 } }
},
yaxis: {
labels: { style: { colors: '#94a3b8', fontWeight: 600 } }
},
grid: {
borderColor: '#f1f5f9',
strokeDashArray: 4
},
legend: { show: false },
tooltip: {
theme: 'light',
x: { show: true },
y: {
formatter: function(val, { seriesIndex }) {
return val + (seriesIndex === 0 ? ' 次' : ' 人');
}
}
}
};
new ApexCharts(document.querySelector("#trend-chart"), options).render();
}
function renderPlatformChart(dist) {
const options = {
series: dist.map(i => i.count),
labels: dist.map(i => i.platform || '未知'),
chart: {
type: 'donut',
height: 350,
fontFamily: 'Inter, sans-serif'
},
colors: ['#6366f1', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4'],
stroke: { width: 0 },
plotOptions: {
pie: {
donut: {
size: '75%',
labels: {
show: true,
total: {
show: true,
label: '总解析量',
color: '#94a3b8',
fontWeight: 600,
formatter: w => w.globals.seriesTotals.reduce((a, b) => a + b, 0) + ' 次'
}
}
}
}
},
dataLabels: { enabled: false },
legend: {
position: 'bottom',
fontFamily: 'Inter',
fontWeight: 600,
labels: { colors: '#64748b' }
}
};
new ApexCharts(document.querySelector("#platform-chart"), options).render();
}
function renderGeoChart(dist) {
const options = {
series: [{
name: '活跃用户',
data: dist.map(i => i.count)
}],
chart: {
type: 'bar',
height: 350,
toolbar: { show: false },
fontFamily: 'Inter, sans-serif'
},
colors: ['#6366f1'],
plotOptions: {
bar: {
borderRadius: 10,
horizontal: true,
barHeight: '60%',
distributed: false,
}
},
dataLabels: {
enabled: true,
style: { fontWeight: 'bold' }
},
xaxis: {
categories: dist.map(i => i.province),
axisBorder: { show: false },
axisTicks: { show: false },
labels: { style: { colors: '#94a3b8', fontWeight: 600 } }
},
yaxis: {
labels: { style: { colors: '#94a3b8', fontWeight: 600 } }
},
grid: {
borderColor: '#f1f5f9',
strokeDashArray: 4,
xaxis: { lines: { show: true } },
yaxis: { lines: { show: false } }
},
tooltip: {
theme: 'light',
y: { formatter: val => val + ' 人' }
}
};
new ApexCharts(document.querySelector("#geo-chart"), options).render();
}
</script>
{% endblock %}
+4
View File
@@ -33,6 +33,10 @@
<i class="fas fa-chart-line w-5 mr-3"></i>
<span class="font-medium">仪表盘概览</span>
</a>
<a href="{{ url_for('admin_modern.analysis') }}" class="flex items-center px-6 py-3 text-slate-600 hover:bg-slate-50 hover:text-indigo-600 transition-colors {{ 'sidebar-item-active' if request.endpoint == 'admin_modern.analysis' }}">
<i class="fas fa-chart-pie w-5 mr-3"></i>
<span class="font-medium">数据统计分析</span>
</a>
<a href="{{ url_for('admin_modern.videos') }}" class="flex items-center px-6 py-3 text-slate-600 hover:bg-slate-50 hover:text-indigo-600 transition-colors {{ 'sidebar-item-active' if request.endpoint == 'admin_modern.videos' }}">
<i class="fas fa-video w-5 mr-3"></i>
<span class="font-medium">视频库管理</span>
+27 -15
View File
@@ -10,33 +10,35 @@
<!-- Stats Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-10">
<div class="bg-white p-8 rounded-3xl shadow-sm border border-slate-100 flex items-center space-x-6">
<div class="w-16 h-16 bg-indigo-50 text-indigo-600 rounded-2xl flex items-center justify-center text-2xl">
<a href="{{ url_for('admin_modern.videos') }}" class="bg-white p-8 rounded-3xl shadow-sm border border-slate-100 flex items-center space-x-6 hover:shadow-md hover:border-indigo-100 transition-all group">
<div class="w-16 h-16 bg-indigo-50 text-indigo-600 rounded-2xl flex items-center justify-center text-2xl group-hover:bg-indigo-600 group-hover:text-white transition-colors">
<i class="fas fa-video"></i>
</div>
<div>
<div class="text-slate-400 text-sm font-semibold uppercase tracking-wider">总视频量</div>
<div class="text-4xl font-extrabold text-slate-800">{{ video_count }}</div>
</div>
</div>
</a>
<div class="bg-white p-8 rounded-3xl shadow-sm border border-slate-100 flex items-center space-x-6">
<div class="w-16 h-16 bg-emerald-50 text-emerald-600 rounded-2xl flex items-center justify-center text-2xl">
<a href="{{ url_for('admin_modern.users') }}" class="bg-white p-8 rounded-3xl shadow-sm border border-slate-100 flex items-center space-x-6 hover:shadow-md hover:border-emerald-100 transition-all group">
<div class="w-16 h-16 bg-emerald-50 text-emerald-600 rounded-2xl flex items-center justify-center text-2xl group-hover:bg-emerald-600 group-hover:text-white transition-colors">
<i class="fas fa-user-check"></i>
</div>
<div>
<div class="text-slate-400 text-sm font-semibold uppercase tracking-wider">注册用户</div>
<div class="text-4xl font-extrabold text-slate-800">{{ user_count }}</div>
</div>
</div>
</a>
<div class="bg-indigo-600 p-8 rounded-3xl shadow-xl flex items-center justify-between text-white overflow-hidden relative">
<div class="relative z-10">
<div class="text-indigo-100 text-sm font-semibold uppercase tracking-wider">系统运行正常</div>
<div class="text-xl font-bold mt-1">版本 v2.0.0 (LTS)</div>
<a href="{{ url_for('admin_modern.analysis') }}" class="bg-white p-8 rounded-3xl shadow-sm border border-slate-100 flex items-center space-x-6 hover:shadow-md hover:border-amber-100 transition-all group">
<div class="w-16 h-16 bg-amber-50 text-amber-600 rounded-2xl flex items-center justify-center text-2xl group-hover:bg-amber-600 group-hover:text-white transition-colors">
<i class="fas fa-bolt"></i>
</div>
<i class="fas fa-rocket text-7xl text-indigo-500/30 absolute -right-4 -bottom-4 transform rotate-12"></i>
</div>
<div>
<div class="text-slate-400 text-sm font-semibold uppercase tracking-wider">今日活跃 (DAU)</div>
<div class="text-4xl font-extrabold text-slate-800">{{ active_user_count }}</div>
</div>
</a>
</div>
<!-- Recent Records -->
@@ -52,6 +54,7 @@
<th class="px-8 py-4">平台</th>
<th class="px-8 py-4">封面</th>
<th class="px-8 py-4">标题</th>
<th class="px-8 py-4">解析用户</th>
<th class="px-8 py-4">积分</th>
<th class="px-8 py-4">创建时间</th>
</tr>
@@ -70,16 +73,25 @@
{% endif %}
</td>
<td class="px-8 py-5">
<div class="max-w-md truncate font-medium text-slate-700">{{ video.title or '无标题' }}</div>
<div class="max-w-lg truncate font-medium text-slate-700">{{ video.title or '无标题' }}</div>
</td>
<td class="px-8 py-5 font-bold text-indigo-600">{{ video.score }}</td>
<td class="px-8 py-5">
{% if video.last_user_name %}
<a href="{{ url_for('admin_modern.users', search=video.last_user_name) }}" class="text-indigo-600 hover:text-indigo-800 font-bold hover:underline transition-all">
{{ video.last_user_name }}
</a>
{% else %}
<span class="text-slate-300">系统/匿名</span>
{% endif %}
</td>
<td class="px-8 py-5 font-bold text-indigo-600">+{{ video.score }}</td>
<td class="px-8 py-5 text-sm text-slate-400 font-medium">
{{ video.create_at.strftime('%m-%d %H:%M') if video.create_at else '-' }}
</td>
</tr>
{% endfor %}
{% if not recent_videos %}
<tr><td colspan="5" class="px-8 py-20 text-center text-slate-400 font-medium">暂无数据</td></tr>
<tr><td colspan="6" class="px-8 py-20 text-center text-slate-400 font-medium">暂无数据</td></tr>
{% endif %}
</tbody>
</table>
+1 -1
View File
@@ -52,7 +52,7 @@
</td>
<td class="px-8 py-6">
<div class="flex items-center space-x-4">
<img src="{{ user.avatar_url or '/static/default-avatar.png' }}" class="w-12 h-12 rounded-full border-2 border-slate-100 shadow-sm object-cover" onerror="this.src='https://ui-avatars.com/api/?name={{ user.nickname or 'User' }}&background=6366f1&color=fff'">
<img src="{{ user.avatar_url or url_for('static', filename='images/default-avatar.png') }}" class="w-12 h-12 rounded-full border-2 border-slate-100 shadow-sm object-cover" onerror="this.src='{{ url_for('static', filename='images/default-avatar.png') }}'; this.onerror=null;">
<div>
<div class="font-bold text-slate-800">{{ user.nickname or '微信用户' }}</div>
<div class="text-xs text-slate-400 font-mono tracking-tighter">{{ user.open_id }}</div>
+145 -64
View File
@@ -11,26 +11,72 @@
</div>
<!-- Filters -->
<div class="bg-white p-6 rounded-3xl shadow-sm border border-slate-100 mb-8">
<form method="GET" class="flex flex-wrap gap-4">
<div class="flex-1 min-w-[240px] relative">
<i class="fas fa-search absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>
<input type="text" name="search" value="{{ search }}"
class="w-full pl-11 pr-4 py-3 bg-slate-50 border border-slate-100 rounded-2xl focus:ring-2 focus:ring-indigo-500 focus:bg-white outline-none transition-all font-medium"
placeholder="搜索标题或视频ID...">
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 mb-8">
<form method="GET" class="space-y-4">
<div class="flex flex-wrap gap-4 items-center">
<!-- Main Search -->
<div class="flex-1 min-w-[300px] relative">
<i class="fas fa-search absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>
<input type="text" name="search" value="{{ search }}"
class="w-full pl-11 pr-4 py-3 bg-slate-50 border border-slate-100 rounded-2xl focus:ring-2 focus:ring-indigo-500 focus:bg-white outline-none transition-all font-medium text-sm"
placeholder="搜索标题或视频ID...">
</div>
<!-- Platform Selector -->
<div class="relative">
<i class="fas fa-layer-group absolute left-4 top-1/2 -translate-y-1/2 text-slate-400 z-10"></i>
<select name="platform" class="pl-11 pr-10 py-3 bg-slate-50 border border-slate-100 rounded-2xl focus:ring-2 focus:ring-indigo-500 focus:bg-white outline-none transition-all font-bold text-slate-600 appearance-none text-sm min-w-[140px]">
<option value="">所有平台</option>
<option value="抖音" {{ 'selected' if platform == '抖音' }}>抖音</option>
<option value="快手" {{ 'selected' if platform == '快手' }}>快手</option>
<option value="小红书" {{ 'selected' if platform == '小红书' }}>小红书</option>
<option value="哔哩哔哩" {{ 'selected' if platform == '哔哩哔哩' }}>哔哩哔哩</option>
</select>
<i class="fas fa-chevron-down absolute right-4 top-1/2 -translate-y-1/2 text-slate-300 pointer-events-none text-[10px]"></i>
</div>
<!-- Action Buttons -->
<div class="flex items-center space-x-2">
<button type="submit" class="px-8 py-3 bg-indigo-600 text-white rounded-2xl font-bold hover:bg-indigo-700 transition-all shadow-lg shadow-indigo-100 flex items-center">
<i class="fas fa-search mr-2"></i>查找
</button>
{% if search or platform or visibility or start_date or end_date or min_score or max_score %}
<a href="{{ url_for('admin_modern.videos') }}" class="px-6 py-3 bg-slate-100 text-slate-500 rounded-2xl font-bold hover:bg-slate-200 transition-all text-sm">重置</a>
{% endif %}
</div>
</div>
<!-- Advanced Filters -->
<div class="flex flex-wrap gap-4 pt-4 border-t border-slate-50 items-center">
<div class="text-[10px] font-black text-slate-400 uppercase tracking-widest mr-2">高级筛选:</div>
<!-- Visibility Selector -->
<div class="relative">
<i class="fas fa-eye absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 z-10 text-xs"></i>
<select name="visibility" class="pl-9 pr-8 py-1.5 bg-slate-50 border border-slate-100 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:bg-white outline-none transition-all font-bold text-slate-600 appearance-none text-[11px] min-w-[100px]">
<option value="">全部状态</option>
<option value="1" {{ 'selected' if visibility == '1' }}>仅可见</option>
<option value="0" {{ 'selected' if visibility == '0' }}>仅隐藏</option>
</select>
<i class="fas fa-chevron-down absolute right-3 top-1/2 -translate-y-1/2 text-slate-300 pointer-events-none text-[8px]"></i>
</div>
<!-- Date Range -->
<div class="flex items-center space-x-2 bg-slate-50 p-1.5 rounded-xl border border-slate-100">
<i class="far fa-calendar-alt text-slate-400 ml-2"></i>
<input type="date" name="start_date" value="{{ start_date }}" class="bg-transparent border-none outline-none text-xs font-bold text-slate-600 focus:ring-0 p-0 w-28">
<span class="text-slate-300">至</span>
<input type="date" name="end_date" value="{{ end_date }}" class="bg-transparent border-none outline-none text-xs font-bold text-slate-600 focus:ring-0 p-0 w-28">
</div>
<!-- Score Range -->
<div class="flex items-center space-x-2 bg-slate-50 p-1.5 rounded-xl border border-slate-100">
<i class="fas fa-star text-slate-400 ml-2"></i>
<input type="number" name="min_score" value="{{ min_score }}" placeholder="最小积分" class="bg-transparent border-none outline-none text-xs font-bold text-slate-600 focus:ring-0 p-0 w-16 text-center">
<span class="text-slate-300">-</span>
<input type="number" name="max_score" value="{{ max_score }}" placeholder="最大积分" class="bg-transparent border-none outline-none text-xs font-bold text-slate-600 focus:ring-0 p-0 w-16 text-center">
</div>
</div>
<select name="platform" class="px-6 py-3 bg-slate-50 border border-slate-100 rounded-2xl focus:ring-2 focus:ring-indigo-500 focus:bg-white outline-none transition-all font-bold text-slate-600 appearance-none pr-10 relative">
<option value="">所有平台</option>
<option value="抖音" {{ 'selected' if platform == '抖音' }}>抖音</option>
<option value="快手" {{ 'selected' if platform == '快手' }}>快手</option>
<option value="小红书" {{ 'selected' if platform == '小红书' }}>小红书</option>
<option value="哔哩哔哩" {{ 'selected' if platform == '哔哩哔哩' }}>哔哩哔哩</option>
</select>
<button type="submit" class="px-8 py-3 bg-indigo-600 text-white rounded-2xl font-bold hover:bg-indigo-700 transition-all shadow-lg shadow-indigo-100">筛选</button>
{% if search or platform %}
<a href="{{ url_for('admin_modern.videos') }}" class="px-6 py-3 bg-slate-100 text-slate-600 rounded-2xl font-bold hover:bg-slate-200 transition-all flex items-center">重置</a>
{% endif %}
</form>
</div>
@@ -91,91 +137,107 @@
<table class="w-full text-left">
<thead class="bg-slate-50/50 text-slate-500 text-xs font-bold uppercase tracking-widest">
<tr>
<th class="px-6 py-4 w-10">
<th class="px-4 py-3 w-8">
<input type="checkbox" id="select-all" class="w-4 h-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500" onclick="toggleAll(this)">
</th>
<th class="px-6 py-4">封面</th>
<th class="px-6 py-4">视频信息 (点击标题编辑)</th>
<th class="px-6 py-4 cursor-pointer hover:text-indigo-600 transition-colors" onclick="sortBy('platform')">
<th class="px-4 py-3">封面</th>
<th class="px-4 py-3">视频信息 (点击标题编辑)</th>
<th class="px-4 py-3">解析用户</th>
<th class="px-4 py-3 cursor-pointer hover:text-indigo-600 transition-colors" onclick="sortBy('platform')">
平台 {% if sort_by == 'platform' %}<i class="fas fa-sort-{{ 'down' if order == 'desc' else 'up' }}"></i>{% endif %}
</th>
<th class="px-6 py-4 text-center cursor-pointer hover:text-indigo-600 transition-colors" onclick="sortBy('score')">
<th class="px-4 py-3 text-center cursor-pointer hover:text-indigo-600 transition-colors" onclick="sortBy('score')">
积分 {% if sort_by == 'score' %}<i class="fas fa-sort-{{ 'down' if order == 'desc' else 'up' }}"></i>{% endif %}
</th>
<th class="px-6 py-4 cursor-pointer hover:text-indigo-600 transition-colors" onclick="sortBy('create_at')">
<th class="px-4 py-3 cursor-pointer hover:text-indigo-600 transition-colors" onclick="sortBy('create_at')">
创建时间 {% if sort_by == 'create_at' %}<i class="fas fa-sort-{{ 'down' if order == 'desc' else 'up' }}"></i>{% endif %}
</th>
<th class="px-6 py-4 text-center">前端可见</th>
<th class="px-6 py-4 text-center">操作</th>
<th class="px-4 py-3 text-center">前端可见</th>
<th class="px-4 py-3 text-center">操作</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-50">
{% for video in videos %}
<tr class="hover:bg-slate-50/50 transition-colors group">
<td class="px-6 py-6">
<td class="px-4 py-4">
<input type="checkbox" class="video-checkbox w-4 h-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500" value="{{ video.video_id }}" onclick="updateSelection()">
</td>
<td class="px-6 py-6">
<td class="px-4 py-4">
{% if video.cover_url %}
<div class="relative w-24 h-24 cursor-pointer group/thumb shadow-md rounded-2xl overflow-hidden" onclick="playVideo('{{ video.video_url }}', '{{ video.title }}')">
<div class="relative w-20 h-20 cursor-pointer group/thumb shadow-md rounded-2xl overflow-hidden" onclick="playVideo('{{ video.video_url }}', '{{ video.title }}')">
<img src="{{ video.cover_url }}" class="w-full h-full object-cover transition-transform group-hover/thumb:scale-110" onerror="this.src='{{ url_for('static', filename='images/default-cover.png') }}'; this.onerror=null;">
<div class="absolute inset-0 bg-black/20 flex items-center justify-center opacity-0 group-hover/thumb:opacity-100 transition-opacity">
<i class="fas fa-play text-white text-2xl"></i>
<i class="fas fa-play text-white text-xl"></i>
</div>
</div>
{% else %}
<div class="w-24 h-24 bg-slate-100 rounded-2xl flex items-center justify-center text-slate-400 text-xl font-bold cursor-pointer shadow-inner" onclick="playVideo('{{ video.video_url }}', '{{ video.title }}')">
<div class="w-20 h-20 bg-slate-100 rounded-2xl flex items-center justify-center text-slate-400 text-xl font-bold cursor-pointer shadow-inner" onclick="playVideo('{{ video.video_url }}', '{{ video.title }}')">
<i class="fas fa-video"></i>
</div>
{% endif %}
</td>
<td class="px-6 py-6">
<td class="px-4 py-4">
<div class="max-w-md">
<div class="font-bold text-slate-800 text-lg mb-1 {{ 'cursor-text hover:text-indigo-600' if session.get('admin_role') == 'admin' else '' }} transition-colors flex items-start group/title" {% if session.get('admin_role') == 'admin' %}onclick="showEditModal('title', '{{ video.video_id }}', '{{ video.title or '' }}', this)"{% endif %}>
<div class="font-bold text-slate-800 text-base mb-1 {{ 'cursor-text hover:text-indigo-600' if session.get('admin_role') == 'admin' else '' }} transition-colors flex items-start group/title" {% if session.get('admin_role') == 'admin' %}onclick="showEditModal('title', '{{ video.video_id }}', '{{ video.title or '' }}', this)"{% endif %}>
<span class="title-text line-clamp-3 leading-snug">{{ video.title or '未命名视频' }}</span>
{% if session.get('admin_role') == 'admin' %}
<i class="fas fa-edit ml-2 mt-1.5 text-slate-300 opacity-0 group-hover/title:opacity-100 transition-opacity text-xs flex-shrink-0"></i>
<i class="fas fa-edit ml-2 mt-1 text-slate-300 opacity-0 group-hover/title:opacity-100 transition-opacity text-[10px] flex-shrink-0"></i>
{% endif %}
</div>
<div class="text-xs text-slate-400 font-mono tracking-tighter">{{ video.video_id }}</div>
<div class="text-[10px] text-slate-400 font-mono tracking-tighter">{{ video.video_id }}</div>
</div>
</td>
<td class="px-6 py-6">
<span class="px-3 py-1 bg-indigo-50 text-indigo-600 rounded-full text-xs font-extrabold">{{ video.platform }}</span>
<td class="px-4 py-4">
{% if video.last_user_name %}
<a href="{{ url_for('admin_modern.users', search=video.last_user_name) }}" class="text-indigo-600 hover:text-indigo-800 font-bold hover:underline transition-all text-sm whitespace-nowrap">
{{ video.last_user_name }}
</a>
{% else %}
<span class="text-slate-300 text-sm">系统/匿名</span>
{% endif %}
</td>
<td class="px-6 py-6 text-center">
<td class="px-4 py-4">
<span class="px-3 py-1 bg-indigo-50 text-indigo-600 rounded-full text-xs font-bold">{{ video.platform }}</span>
</td>
<td class="px-4 py-4 text-center">
<div class="{{ 'cursor-pointer hover:bg-indigo-50' if session.get('admin_role') == 'admin' else '' }} py-1 rounded-lg transition-colors group/score" {% if session.get('admin_role') == 'admin' %}onclick="showEditModal('score', '{{ video.video_id }}', '{{ video.score }}', this)"{% endif %}>
<span class="score-value text-indigo-600 font-black text-xl">{{ video.score }}</span>
<span class="score-value text-indigo-600 font-black text-lg">{{ video.score }}</span>
{% if session.get('admin_role') == 'admin' %}
<i class="fas fa-edit ml-1 text-slate-300 opacity-0 group-hover/score:opacity-100 transition-opacity text-xs"></i>
<i class="fas fa-edit ml-1 text-slate-300 opacity-0 group-hover/score:opacity-100 transition-opacity text-[10px]"></i>
{% endif %}
</div>
</td>
<td class="px-6 py-6 text-sm text-slate-400 font-medium whitespace-nowrap">
<td class="px-4 py-4 text-[11px] text-slate-400 font-medium whitespace-nowrap">
{{ video.create_at.strftime('%Y-%m-%d %H:%M') if video.create_at else '-' }}
</td>
<td class="px-6 py-6 text-center">
<button {% if session.get('admin_role') == 'admin' %}onclick="toggleVisibility('{{ video.video_id }}', {{ 1 if video.is_visible else 0 }}, this)"{% else %}disabled{% endif %}
class="relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none {{ 'bg-indigo-600' if video.is_visible else 'bg-slate-200' }} {{ 'cursor-not-allowed opacity-50' if session.get('admin_role') != 'admin' else '' }}">
<span class="inline-block h-4 w-4 transform rounded-full bg-white transition-transform {{ 'translate-x-6' if video.is_visible else 'translate-x-1' }}"></span>
<td class="px-4 py-4 text-center">
{% if video.is_visible %}
<button {% if session.get('admin_role') == 'admin' %}onclick="toggleVisibility('{{ video.video_id }}', 1, this)"{% else %}disabled{% endif %}
class="px-4 py-1.5 bg-emerald-50 text-emerald-600 rounded-full text-xs font-black hover:bg-emerald-100 transition-all {{ 'cursor-pointer' if session.get('admin_role') == 'admin' else 'cursor-default' }}">
可见
</button>
{% else %}
<button {% if session.get('admin_role') == 'admin' %}onclick="toggleVisibility('{{ video.video_id }}', 0, this)"{% else %}disabled{% endif %}
class="px-4 py-1.5 bg-slate-100 text-slate-400 rounded-full text-xs font-black hover:bg-slate-200 transition-all {{ 'cursor-pointer' if session.get('admin_role') == 'admin' else 'cursor-default' }}">
隐藏
</button>
{% endif %}
</td>
<td class="px-6 py-6 text-center">
<div class="flex items-center justify-center space-x-3 opacity-0 group-hover:opacity-100 transition-opacity">
<button onclick="playVideo('{{ video.video_url }}', '{{ video.title }}')" class="text-slate-400 hover:text-indigo-600" title="播放视频">
<i class="fas fa-play-circle text-2xl"></i>
</button>
<td class="px-4 py-4 text-center">
<div class="flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
{% if session.get('admin_role') == 'admin' %}
<button onclick="deleteVideo('{{ video.video_id }}')" class="text-slate-400 hover:text-red-600" title="删除记录">
<i class="fas fa-trash-alt text-lg"></i>
<button onclick="deleteVideo('{{ video.video_id }}')" class="text-slate-300 hover:text-red-500 transition-colors" title="删除记录">
<i class="fas fa-trash-alt"></i>
</button>
{% else %}
<span class="text-slate-200 text-xs">-</span>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
{% if not videos %}
<tr><td colspan="8" class="px-8 py-32 text-center text-slate-400 font-medium">没有找到匹配的记录</td></tr>
<tr><td colspan="9" class="px-8 py-32 text-center text-slate-400 font-medium">没有找到匹配的记录</td></tr>
{% endif %}
</tbody>
</table>
@@ -187,10 +249,10 @@
<div class="text-sm text-slate-500 font-medium">共 {{ total }} 条记录</div>
<div class="flex space-x-2">
{% if page > 1 %}
<a href="{{ url_for('admin_modern.videos', page=page-1, search=search, platform=platform, sort_by=sort_by, order=order) }}" class="px-4 py-2 bg-white border border-slate-200 rounded-xl font-bold hover:bg-indigo-50 transition-all">上一页</a>
<a href="{{ url_for('admin_modern.videos', page=page-1, search=search, platform=platform, visibility=visibility, start_date=start_date, end_date=end_date, min_score=min_score, max_score=max_score, sort_by=sort_by, order=order) }}" class="px-4 py-2 bg-white border border-slate-200 rounded-xl font-bold hover:bg-indigo-50 transition-all">上一页</a>
{% endif %}
{% if total > page * limit %}
<a href="{{ url_for('admin_modern.videos', page=page+1, search=search, platform=platform, sort_by=sort_by, order=order) }}" class="px-4 py-2 bg-white border border-slate-200 rounded-xl font-bold hover:bg-indigo-50 transition-all">下一页</a>
<a href="{{ url_for('admin_modern.videos', page=page+1, search=search, platform=platform, visibility=visibility, start_date=start_date, end_date=end_date, min_score=min_score, max_score=max_score, sort_by=sort_by, order=order) }}" class="px-4 py-2 bg-white border border-slate-200 rounded-xl font-bold hover:bg-indigo-50 transition-all">下一页</a>
{% endif %}
</div>
</div>
@@ -347,6 +409,7 @@
}
function toggleVisibility(videoId, currentStatus, btn) {
if (userRole !== 'admin') return;
const newStatus = currentStatus === 1 ? 0 : 1;
fetch("{{ url_for('admin_modern.toggle_visibility') }}", {
method: 'POST',
@@ -354,12 +417,15 @@
body: JSON.stringify({ video_id: videoId, is_visible: newStatus })
}).then(r => r.json()).then(data => {
if(data.success) {
btn.classList.toggle('bg-indigo-600');
btn.classList.toggle('bg-slate-200');
btn.querySelector('span').classList.toggle('translate-x-6');
btn.querySelector('span').classList.toggle('translate-x-1');
if(newStatus === 1) {
btn.className = 'px-4 py-1.5 bg-emerald-50 text-emerald-600 rounded-full text-xs font-black hover:bg-emerald-100 transition-all cursor-pointer';
btn.textContent = '可见';
} else {
btn.className = 'px-4 py-1.5 bg-slate-100 text-slate-400 rounded-full text-xs font-black hover:bg-slate-200 transition-all cursor-pointer';
btn.textContent = '隐藏';
}
btn.setAttribute('onclick', `toggleVisibility('${videoId}', ${newStatus}, this)`);
showToast(newStatus ? '已设置为显示' : '已成功隐藏');
showToast(newStatus ? '已设置为可见' : '已成功隐藏');
}
});
}
@@ -384,7 +450,12 @@
video_ids: selected,
is_visible: status,
search: urlParams.get('search') || '',
platform: urlParams.get('platform') || ''
platform: urlParams.get('platform') || '',
visibility: urlParams.get('visibility') || '',
start_date: urlParams.get('start_date') || '',
end_date: urlParams.get('end_date') || '',
min_score: urlParams.get('min_score') || '',
max_score: urlParams.get('max_score') || ''
})
}).then(r => r.json()).then(data => {
if(data.success) {
@@ -452,7 +523,12 @@
video_ids: selected,
score_delta: val,
search: urlParams.get('search') || '',
platform: urlParams.get('platform') || ''
platform: urlParams.get('platform') || '',
visibility: urlParams.get('visibility') || '',
start_date: urlParams.get('start_date') || '',
end_date: urlParams.get('end_date') || '',
min_score: urlParams.get('min_score') || '',
max_score: urlParams.get('max_score') || ''
})
}).then(r => r.json()).then(data => {
if(data.success) {
@@ -484,7 +560,12 @@
body: JSON.stringify({
video_ids: selected,
search: urlParams.get('search') || '',
platform: urlParams.get('platform') || ''
platform: urlParams.get('platform') || '',
visibility: urlParams.get('visibility') || '',
start_date: urlParams.get('start_date') || '',
end_date: urlParams.get('end_date') || '',
min_score: urlParams.get('min_score') || '',
max_score: urlParams.get('max_score') || ''
})
}).then(r => r.json()).then(data => {
if(data.success) {