From 28b11b43655151af145d0a5b0c77483b8efdbae1 Mon Sep 17 00:00:00 2001 From: lz_db Date: Sat, 17 Oct 2026 09:41:11 +0800 Subject: [PATCH] 1 --- app/lib/core/config/app_config.dart | 17 ++- app/lib/main.dart | 3 + app/lib/screens/auth/register_screen.dart | 120 +++++++++++++++--- app/lib/screens/settings/settings_screen.dart | 6 +- app/pubspec.yaml | 5 +- .../api/v1/__pycache__/videos.cpython-311.pyc | Bin 15290 -> 15290 bytes server/app/redis_client.py | 3 +- 7 files changed, 126 insertions(+), 28 deletions(-) diff --git a/app/lib/core/config/app_config.dart b/app/lib/core/config/app_config.dart index 20fe131..1d96ef5 100644 --- a/app/lib/core/config/app_config.dart +++ b/app/lib/core/config/app_config.dart @@ -1,11 +1,20 @@ +import 'package:package_info_plus/package_info_plus.dart'; + /// 全局配置常量(域名发现、公共请求头、版本号,对应《01-开发文档》5.5/5.6/5.7) class AppConfig { AppConfig._(); - /// App 版本(对应 pubspec version 的 name 部分;version_code 对应 build 号) - /// ⚠️ 每次发版必须与 pubspec.yaml 的 version 同步递增,否则老用户会一直提示更新 - static const String appVersion = '1.2.0'; - static const int appVersionCode = 12; + /// App 版本(运行时从 PackageInfo 读取,始终与 APK 真实 versionName/versionCode 一致; + /// 不要改回硬编码——硬编码一旦与 pubspec 脱节,老用户会无限收到更新提示) + static late final String appVersion; + static late final int appVersionCode; + + /// 启动时初始化版本信息(main() 中 runApp 前必须调用) + static Future initVersion() async { + final info = await PackageInfo.fromPlatform(); + appVersion = info.version; + appVersionCode = int.tryParse(info.buildNumber) ?? 0; + } /// 平台标识(运行时按 iOS/Android 判定,见 platformName) static const String platformNameIOS = 'ios'; diff --git a/app/lib/main.dart b/app/lib/main.dart index 5f7ebf8..87244aa 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -6,11 +6,14 @@ import 'core/storage/local_store.dart'; import 'core/storage/search_history_store.dart'; import 'core/storage/watch_dedup_store.dart'; import 'core/theme/app_theme.dart'; +import 'core/config/app_config.dart'; import 'router.dart'; /// App 入口:本地存储 + MediaKit + MaterialApp.router Future main() async { WidgetsFlutterBinding.ensureInitialized(); + // 版本信息(版本检查/请求头 X-App-Version 依赖,必须先初始化) + await AppConfig.initVersion(); // MediaKit(libmpv 底层)全局初始化:每个进程必须且仅调一次 MediaKit.ensureInitialized(); // 本地存储初始化(设备指纹在 splash 阶段生成) diff --git a/app/lib/screens/auth/register_screen.dart b/app/lib/screens/auth/register_screen.dart index 3b6e63c..d611286 100644 --- a/app/lib/screens/auth/register_screen.dart +++ b/app/lib/screens/auth/register_screen.dart @@ -10,7 +10,7 @@ import '../../core/theme/app_theme.dart'; import '../../providers/auth_provider.dart'; import '../../services/auth_service.dart'; -/// 注册页:手机号 + 验证码 + 密码;邀请码选填(口令/模糊归因命中时自动预填) +/// 注册页:手机号/邮箱 + 验证码 + 密码;邀请码选填(口令/模糊归因命中时自动预填) class RegisterScreen extends ConsumerStatefulWidget { const RegisterScreen({super.key}); @@ -19,11 +19,16 @@ class RegisterScreen extends ConsumerStatefulWidget { } class _RegisterScreenState extends ConsumerState { - final _phone = TextEditingController(); + final _account = TextEditingController(); final _code = TextEditingController(); final _password = TextEditingController(); final _nickname = TextEditingController(); late final TextEditingController _inviteCode; + + /// 注册方式:phone / email + String _mode = 'phone'; + bool get _isEmail => _mode == 'email'; + bool _loading = false; String? _error; @@ -31,6 +36,9 @@ class _RegisterScreenState extends ConsumerState { int _countdown = 0; Timer? _timer; + /// 邮箱格式校验 + static final _emailReg = RegExp(r'^[\w.+-]+@[\w-]+\.[\w.-]+$'); + @override void initState() { super.initState(); @@ -41,7 +49,7 @@ class _RegisterScreenState extends ConsumerState { @override void dispose() { _timer?.cancel(); - _phone.dispose(); + _account.dispose(); _code.dispose(); _password.dispose(); _nickname.dispose(); @@ -49,20 +57,41 @@ class _RegisterScreenState extends ConsumerState { super.dispose(); } + void _switchMode(String mode) { + if (mode == _mode) return; + setState(() { + _mode = mode; + _error = null; + // 切换方式后账号和验证码需要重新填写 + _account.clear(); + _code.clear(); + }); + } + Future _sendCode() async { - final phone = _phone.text.trim(); - if (!RegExp(r'^1\d{10}$').hasMatch(phone)) { - setState(() => _error = '请输入正确的手机号'); - return; + final account = _account.text.trim(); + if (_isEmail) { + if (!_emailReg.hasMatch(account)) { + setState(() => _error = '请输入正确的邮箱地址'); + return; + } + } else { + if (!RegExp(r'^1\d{10}$').hasMatch(account)) { + setState(() => _error = '请输入正确的手机号'); + return; + } } try { - final devCode = await AuthService.sendSmsCode(phone, 'register'); + // 未配置短信/邮件通道时服务端走开发模式,直接返回验证码 + final devCode = _isEmail + ? await AuthService.sendEmailCode(account, 'register') + : await AuthService.sendSmsCode(account, 'register'); setState(() { _error = null; _countdown = 60; }); if (devCode != null && mounted) { - // 短信通道未配置时的开发模式:直接展示验证码(上线配置短信后服务端不再返回) + // 通道未配置时的开发模式:直接展示验证码(上线配置后服务端不再返回) ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('开发模式验证码:$devCode(5 分钟内有效)'), duration: const Duration(seconds: 6)), ); @@ -84,11 +113,11 @@ class _RegisterScreenState extends ConsumerState { } Future _submit() async { - final phone = _phone.text.trim(); + final account = _account.text.trim(); final code = _code.text.trim(); final password = _password.text; - if (phone.isEmpty || code.isEmpty || password.isEmpty) { - setState(() => _error = '请填写手机号、验证码和密码'); + if (account.isEmpty || code.isEmpty || password.isEmpty) { + setState(() => _error = _isEmail ? '请填写邮箱、验证码和密码' : '请填写手机号、验证码和密码'); return; } setState(() { @@ -97,8 +126,8 @@ class _RegisterScreenState extends ConsumerState { }); try { final result = await AuthService.register( - type: 'phone', - account: phone, + type: _mode, + account: account, code: code, password: password, nickname: _nickname.text.trim(), @@ -132,11 +161,14 @@ class _RegisterScreenState extends ConsumerState { padding: const EdgeInsets.all(24), children: [ const Text('创建账号', style: TextStyle(fontSize: 26, fontWeight: FontWeight.w700)), - const SizedBox(height: 32), + const SizedBox(height: 24), + // 手机号 / 邮箱 切换 + _ModeSwitch(current: _mode, onChanged: _switchMode), + const SizedBox(height: 24), TextField( - controller: _phone, - keyboardType: TextInputType.phone, - decoration: const InputDecoration(hintText: '手机号'), + controller: _account, + keyboardType: _isEmail ? TextInputType.emailAddress : TextInputType.phone, + decoration: InputDecoration(hintText: _isEmail ? '邮箱' : '手机号'), ), const SizedBox(height: 16), Row( @@ -145,7 +177,7 @@ class _RegisterScreenState extends ConsumerState { child: TextField( controller: _code, keyboardType: TextInputType.number, - decoration: const InputDecoration(hintText: '短信验证码'), + decoration: InputDecoration(hintText: _isEmail ? '邮箱验证码' : '短信验证码'), ), ), const SizedBox(width: 12), @@ -201,3 +233,53 @@ class _RegisterScreenState extends ConsumerState { ); } } + +/// 注册方式切换条(手机号 / 邮箱) +class _ModeSwitch extends StatelessWidget { + const _ModeSwitch({required this.current, required this.onChanged}); + + final String current; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + color: AppColors.surface, + borderRadius: BorderRadius.circular(10), + ), + padding: const EdgeInsets.all(3), + child: Row( + children: [ + _tab(context, '手机号', 'phone'), + _tab(context, '邮箱', 'email'), + ], + ), + ); + } + + Widget _tab(BuildContext context, String label, String value) { + final selected = current == value; + return Expanded( + child: GestureDetector( + onTap: () => onChanged(value), + child: Container( + padding: const EdgeInsets.symmetric(vertical: 9), + alignment: Alignment.center, + decoration: BoxDecoration( + color: selected ? Theme.of(context).scaffoldBackgroundColor : Colors.transparent, + borderRadius: BorderRadius.circular(8), + ), + child: Text( + label, + style: TextStyle( + fontSize: 14, + fontWeight: selected ? FontWeight.w600 : FontWeight.w400, + color: selected ? AppColors.textPrimary : AppColors.textSecondary, + ), + ), + ), + ), + ); + } +} diff --git a/app/lib/screens/settings/settings_screen.dart b/app/lib/screens/settings/settings_screen.dart index ac0f8f0..d3fd642 100644 --- a/app/lib/screens/settings/settings_screen.dart +++ b/app/lib/screens/settings/settings_screen.dart @@ -18,9 +18,9 @@ class SettingsScreen extends ConsumerWidget { body: ListView( children: [ // 版本信息 - const ListTile( - leading: Icon(Icons.info_outline, color: AppColors.textSecondary), - title: Text('当前版本'), + ListTile( + leading: const Icon(Icons.info_outline, color: AppColors.textSecondary), + title: const Text('当前版本'), trailing: Text( 'v${AppConfig.appVersion} (${AppConfig.appVersionCode})', style: TextStyle(color: AppColors.textWeak, fontSize: 13), diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 18d9e2f..9153c4d 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -2,7 +2,7 @@ name: video_app description: "短视频应用(Flutter,iOS/Android 双端)" publish_to: 'none' -version: 1.2.0+12 +version: 1.2.0+13 environment: sdk: ^3.9.2 @@ -32,6 +32,9 @@ dependencies: cupertino_icons: ^1.0.8 + # 应用包信息(运行时读取真实 versionName/versionCode,修复更新弹窗误判) + package_info_plus: ^8.3.0 + # 状态管理(02-技术文档 2.1) flutter_riverpod: ^2.6.1 # 网络 diff --git a/server/app/api/v1/__pycache__/videos.cpython-311.pyc b/server/app/api/v1/__pycache__/videos.cpython-311.pyc index 635b3a10d88851aab1cc5cea8c2ca1ead554e420..ef714821f15e559c641efff8056a99686c485737 100644 GIT binary patch delta 19 Zcmdm0zN?&TIWI340}!0m-^jJW8UR141=;`r delta 19 Zcmdm0zN?&TIWI340}%WX*~qoQ8UR2&1?~U< diff --git a/server/app/redis_client.py b/server/app/redis_client.py index 25d543c..aaec8af 100644 --- a/server/app/redis_client.py +++ b/server/app/redis_client.py @@ -3,7 +3,8 @@ import redis.asyncio as aioredis from app.config import settings -redis_client: aioredis.Redis = aioredis.from_url(settings.redis_url, decode_responses=True) +# protocol=2:服务器为 Redis 5.x,不支持 RESP3 的 HELLO 握手(redis-py 8.x 默认尝试 3) +redis_client: aioredis.Redis = aioredis.from_url(settings.redis_url, decode_responses=True, protocol=2) async def get_redis() -> aioredis.Redis: