添加后台管理功能
功能: - 数据概览仪表盘 - 用户管理(列表/编辑/删除) - 翻译记录管理 - 缓存管理 - 统计报表(图表) - 操作日志 管理员账号: admin / admin123 后台地址: /admin/
This commit is contained in:
21
app.py
21
app.py
@@ -15,6 +15,7 @@ from werkzeug.utils import secure_filename
|
||||
from config import *
|
||||
from models import db, User, Translation, TranslationCache, GuestTranslation
|
||||
from services import TranslationService, CacheService, TranslationTask
|
||||
from admin import admin_bp
|
||||
|
||||
# ==================== 创建应用 ====================
|
||||
app = Flask(__name__)
|
||||
@@ -26,6 +27,9 @@ app.config['MAX_CONTENT_LENGTH'] = MAX_FILE_SIZE
|
||||
# 初始化数据库
|
||||
db.init_app(app)
|
||||
|
||||
# 注册后台管理蓝图
|
||||
app.register_blueprint(admin_bp)
|
||||
|
||||
# 初始化服务
|
||||
cache_service = CacheService(CACHE_DIR, CACHE_EXPIRE_DAYS)
|
||||
|
||||
@@ -495,8 +499,23 @@ def init_app():
|
||||
# 创建数据库表
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
# 创建默认管理员账号
|
||||
admin = User.query.filter_by(username='admin').first()
|
||||
if not admin:
|
||||
admin = User(
|
||||
username='admin',
|
||||
email='admin@tphai.com',
|
||||
user_type='admin',
|
||||
is_admin=True,
|
||||
is_active=True
|
||||
)
|
||||
admin.set_password('admin123')
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
print("✅ 默认管理员账号已创建: admin / admin123")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_app()
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
app.run(host='0.0.0.0', port=19000, debug=True)
|
||||
Reference in New Issue
Block a user