50 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from flask import Blueprint, render_template, jsonify
 | 
						|
from flask_login import current_user, login_required
 | 
						|
from app.models import Scenario, ScenarioCategory, VoiceSample
 | 
						|
 | 
						|
main_bp = Blueprint('main', __name__)
 | 
						|
 | 
						|
@main_bp.route('/')
 | 
						|
def index():
 | 
						|
    """首页"""
 | 
						|
    return render_template('index.html')
 | 
						|
 | 
						|
@main_bp.route('/dashboard')
 | 
						|
@login_required
 | 
						|
def dashboard():
 | 
						|
    """用户主页(需要登录)"""
 | 
						|
    # 获取推荐场景
 | 
						|
    recommended_scenarios = Scenario.query.filter_by(is_active=True).limit(6).all()
 | 
						|
    
 | 
						|
    # 获取用户语音样本状态
 | 
						|
    user_voice_sample = current_user.get_latest_voice_sample() if current_user.is_authenticated else None
 | 
						|
    
 | 
						|
    return render_template('dashboard.html', 
 | 
						|
                         scenarios=recommended_scenarios,
 | 
						|
                         voice_sample=user_voice_sample)
 | 
						|
 | 
						|
@main_bp.route('/api/dashboard/stats')
 | 
						|
@login_required
 | 
						|
def get_dashboard_stats():
 | 
						|
    """获取用户Dashboard统计数据"""
 | 
						|
    try:
 | 
						|
        # 这里可以添加真实的统计查询
 | 
						|
        # 暂时返回模拟数据
 | 
						|
        stats = {
 | 
						|
            'learning_time': 0,  # 学习时长(分钟)
 | 
						|
            'conversation_count': 0,  # 对话次数
 | 
						|
            'stars_earned': 0,  # 获得星星
 | 
						|
            'scenarios_completed': 0,  # 完成场景
 | 
						|
        }
 | 
						|
        
 | 
						|
        return jsonify({
 | 
						|
            'success': True,
 | 
						|
            'stats': stats
 | 
						|
        })
 | 
						|
        
 | 
						|
    except Exception as e:
 | 
						|
        return jsonify({
 | 
						|
            'success': False,
 | 
						|
            'message': f'获取统计数据失败: {str(e)}'
 | 
						|
        })
 |