feat: 添加自动化任务(automation_jobs)功能模块
This commit is contained in:
@@ -17,6 +17,7 @@ import 'package:social_app/features/auth/presentation/bloc/auth_event.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
|
||||
import 'package:social_app/features/friends/data/friends_api.dart';
|
||||
import 'package:social_app/features/settings/data/settings_api.dart';
|
||||
import 'package:social_app/features/settings/data/services/automation_jobs_api.dart';
|
||||
import 'package:social_app/features/settings/data/services/settings_user_cache.dart';
|
||||
import 'package:social_app/features/users/data/models/user_response.dart';
|
||||
import 'package:social_app/features/home/ui/navigation/home_return_policy.dart';
|
||||
@@ -34,12 +35,15 @@ class SettingsScreen extends StatefulWidget {
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
final FriendsApi _friendsApi = sl<FriendsApi>();
|
||||
final AutomationJobsApi _automationJobsApi = sl<AutomationJobsApi>();
|
||||
final SettingsUserCache _userCache = sl<SettingsUserCache>();
|
||||
|
||||
UserResponse? _user;
|
||||
bool _isLoading = true;
|
||||
int _friendsCount = 0;
|
||||
String? _firstFriendName;
|
||||
int _enabledJobsCount = 0;
|
||||
String? _firstEnabledJobTitle;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -83,6 +87,21 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
} catch (e) {
|
||||
// Keep profile available even when contacts fail.
|
||||
}
|
||||
|
||||
try {
|
||||
final jobs = await _automationJobsApi.list();
|
||||
final enabledJobs = jobs.where((job) => job.isActive).toList();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_enabledJobsCount = enabledJobs.length;
|
||||
_firstEnabledJobTitle = enabledJobs.isNotEmpty
|
||||
? enabledJobs.first.title
|
||||
: null;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Keep profile available even when automation jobs fail.
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -298,6 +317,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
return '已添加 $_friendsCount 位联系人';
|
||||
}
|
||||
|
||||
String _buildAutomationSubtitle() {
|
||||
if (_enabledJobsCount == 0) {
|
||||
return '暂无启用计划';
|
||||
}
|
||||
if (_enabledJobsCount == 1) {
|
||||
return '已启用:${_firstEnabledJobTitle ?? '周期计划'}';
|
||||
}
|
||||
return '已启用 $_enabledJobsCount 个计划';
|
||||
}
|
||||
|
||||
Widget _buildQuickActions(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
@@ -314,9 +343,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
Expanded(
|
||||
child: _buildActionCard(
|
||||
icon: Icons.auto_awesome,
|
||||
iconColor: AppColors.violet500,
|
||||
iconColor: AppColors.blue500,
|
||||
title: '周期计划',
|
||||
subtitle: '已启用:会议提醒',
|
||||
subtitle: _buildAutomationSubtitle(),
|
||||
onTap: () => context.push(AppRoutes.settingsFeatures),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user