ver1.00.00
bindQR
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data'; // 确保导入,因为 uploadStegImage 需要 Uint8List
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../model/user_model.dart';
|
||||
@@ -25,11 +26,11 @@ class UserProvider with ChangeNotifier {
|
||||
|
||||
String get scoreDataSource => _scoreDataSource;
|
||||
String? get selectedSegaId => _selectedSegaId;
|
||||
String? get selectedCnUserName => _selectedCnUserName; // Getter for CN username
|
||||
String? get selectedCnUserName => _selectedCnUserName;
|
||||
|
||||
List<SegaCard> get availableSegaCards => _user?.segaCards ?? [];
|
||||
|
||||
// 获取可用的国服账号列表 (从 userName2userId 提取 keys)
|
||||
// 获取可用的国服账号列表
|
||||
List<String> get availableCnUserNames {
|
||||
final map = _user?.userName2userId;
|
||||
if (map == null || map.isEmpty) return [];
|
||||
@@ -82,7 +83,6 @@ class UserProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// ... (login, register, logout 保持不变) ...
|
||||
Future<void> login(String username, String twoKeyCode) async {
|
||||
try {
|
||||
_token = await UserService.login(username, twoKeyCode);
|
||||
@@ -101,18 +101,22 @@ class UserProvider with ChangeNotifier {
|
||||
|
||||
Future<void> register(String username, String password, String inviter) async {
|
||||
await UserService.register(username, password, inviter);
|
||||
await login(username, password);
|
||||
// 注意:注册后通常不直接登录,或者根据业务需求决定。这里保持原逻辑。
|
||||
// await login(username, password);
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
_token = null;
|
||||
_user = null;
|
||||
_selectedSegaId = null;
|
||||
_selectedCnUserName = null;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove("token");
|
||||
await prefs.remove("selectedSegaId");
|
||||
await prefs.remove("selectedCnUserName");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// ... (saveUserInfo, refreshToken, fetchRadarData, fetchSexTags, updateUser 保持不变) ...
|
||||
Future<void> saveUserInfo() async {
|
||||
if (_token == null || _user == null) return;
|
||||
try {
|
||||
@@ -182,7 +186,7 @@ class UserProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// --- 【新增】设置选中的国服用户名 ---
|
||||
// --- 设置选中的国服用户名 ---
|
||||
Future<void> setSelectedCnUserName(String? userName) async {
|
||||
_selectedCnUserName = userName;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -203,7 +207,6 @@ class UserProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
try {
|
||||
// 调用上传
|
||||
final result = await UserService.uploadSegaRating(
|
||||
_token!,
|
||||
_selectedSegaId!,
|
||||
@@ -221,4 +224,38 @@ class UserProvider with ChangeNotifier {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// ================= 新增:上传隐写图片 =================
|
||||
|
||||
/// 上传带有隐写数据的图片
|
||||
/// [imageBytes] 原始图片的字节数据 (Uint8List)
|
||||
/// [segaId] 要隐藏进图片的 SegaID (如果为 null,则使用当前选中的 _selectedSegaId)
|
||||
Future<Map<String, dynamic>> uploadStegImage(Uint8List imageBytes, {String? segaId}) async {
|
||||
if (_token == null) {
|
||||
throw Exception("请先登录");
|
||||
}
|
||||
|
||||
// 如果未指定 segaId,则使用当前选中的
|
||||
final targetSegaId = segaId ?? _selectedSegaId;
|
||||
|
||||
if (targetSegaId == null || targetSegaId.isEmpty) {
|
||||
throw Exception("请提供或选择要隐藏的 SegaID");
|
||||
}
|
||||
|
||||
try {
|
||||
print("🚀 开始隐写并上传... SegaID: $targetSegaId");
|
||||
|
||||
final result = await UserService.uploadStegImage(
|
||||
token: _token!,
|
||||
segaId: targetSegaId,
|
||||
originalImageBytes: imageBytes,
|
||||
);
|
||||
|
||||
print("✅ 隐写上传成功: ${result['msg']}");
|
||||
return result;
|
||||
} catch (e) {
|
||||
print("❌ 隐写上传失败: $e");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user