## 后台管理页重构 - admin 端: add_doctor / doctors / home / patients 四页重构 - doctor 端: consultations / dashboard / followup_edit / followups / home / patient_detail / patients / profile / report_detail / reports / settings 十一页重构 - 新增 backoffice 共享模块: backoffice_refresh_providers + backoffice_formatters + backoffice_ui ## 后端 - AdminService 增强(分页/搜索/统计) - doctor_endpoints 微调 - appsettings.Development 调整 - 新增 admin_service_tests ## 前端其他 - 今日健康卡片 taskRow 行高 5->7(每行 44->48px) - 健康仪表盘配色定 #4FACFE 纯色蓝 - admin_drawer / doctor_drawer 微调 - api_client IP 适配 ## 启动脚本 - start-dev.bat: 加后端就绪检测(轮询 openapi 端点, 最多等 30s) ## 清理 - 删除旧品牌图(agent_welcome_abstract / login_background_v1) - 删除 app_status_badge 组件 - 删除旧 HANDOFF 文档, 新增 07-17 版 ## 测试 - 新增 backoffice_formatters / backoffice_refresh / backoffice_ui 三个测试 - app_router_test 扩展
238 lines
8.8 KiB
Dart
238 lines
8.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/app_colors.dart';
|
|
import '../../core/navigation_provider.dart';
|
|
import '../../providers/data_providers.dart' show adminServiceProvider;
|
|
import '../../providers/backoffice_refresh_providers.dart';
|
|
import '../../widgets/backoffice_ui.dart';
|
|
import '../../widgets/app_toast.dart';
|
|
|
|
class AdminDoctorsPage extends ConsumerStatefulWidget {
|
|
const AdminDoctorsPage({super.key});
|
|
@override
|
|
ConsumerState<AdminDoctorsPage> createState() => _AdminDoctorsPageState();
|
|
}
|
|
|
|
class _AdminDoctorsPageState extends ConsumerState<AdminDoctorsPage> {
|
|
List<Map<String, dynamic>> _doctors = [];
|
|
bool _loading = true;
|
|
String? _error;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_load();
|
|
}
|
|
|
|
Future<void> _load() async {
|
|
setState(() {
|
|
_loading = true;
|
|
_error = null;
|
|
});
|
|
try {
|
|
final res = await ref.read(adminServiceProvider).getDoctors();
|
|
if (!mounted) return;
|
|
setState(() {
|
|
if (res['code'] == 0) {
|
|
_doctors = List<Map<String, dynamic>>.from(res['data'] ?? []);
|
|
} else {
|
|
_error = res['message']?.toString() ?? '医生列表加载失败';
|
|
}
|
|
_loading = false;
|
|
});
|
|
} catch (e) {
|
|
if (mounted) {
|
|
setState(() {
|
|
_loading = false;
|
|
_error = '医生列表加载失败';
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _toggleActive(String id) async {
|
|
try {
|
|
await ref.read(adminServiceProvider).toggleDoctorActive(id);
|
|
await _load();
|
|
} catch (e) {
|
|
if (mounted) {
|
|
AppToast.show(context, '状态修改失败:$e', type: AppToastType.error);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _delete(String id) async {
|
|
final ok = await showDialog<bool>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('确认删除'),
|
|
content: const Text('只有没有绑定患者和问诊记录的医生才能删除;有历史数据的医生请使用“停用”。'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx, false),
|
|
child: const Text('取消'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx, true),
|
|
style: TextButton.styleFrom(foregroundColor: AppColors.error),
|
|
child: const Text('删除'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (ok == true) {
|
|
try {
|
|
await ref.read(adminServiceProvider).deleteDoctor(id);
|
|
await _load();
|
|
} catch (e) {
|
|
if (mounted) {
|
|
AppToast.show(context, '删除失败:$e', type: AppToastType.error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ref.listen(adminDoctorsRefreshSignalProvider, (previous, next) {
|
|
if (previous != null && previous != next) _load();
|
|
});
|
|
return Scaffold(
|
|
backgroundColor: AppColors.pageGrey,
|
|
floatingActionButton: FloatingActionButton(
|
|
backgroundColor: AppColors.primary,
|
|
onPressed: () => pushRoute(ref, 'adminAddDoctor'),
|
|
child: const Icon(Icons.add, color: Colors.white),
|
|
),
|
|
body: _loading
|
|
? const BackofficeLoadingState(message: '正在加载医生')
|
|
: _error != null
|
|
? BackofficeErrorState(message: _error!, onRetry: _load)
|
|
: _doctors.isEmpty
|
|
? const BackofficeEmptyState(
|
|
icon: Icons.medical_services_outlined,
|
|
title: '暂无医生',
|
|
description: '点击右下角按钮添加第一位医生',
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: _doctors.length,
|
|
itemBuilder: (_, i) {
|
|
final d = _doctors[i];
|
|
final active = d['isActive'] != false;
|
|
return BackofficeSectionCard(
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
padding: const EdgeInsets.all(14),
|
|
child: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundColor: active
|
|
? AppColors.successLight
|
|
: AppColors.background,
|
|
child: Icon(
|
|
Icons.local_hospital,
|
|
size: 20,
|
|
color: active
|
|
? AppColors.success
|
|
: AppColors.textHint,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
d['name'] ?? '',
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
if (!active)
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 6,
|
|
vertical: 2,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.errorLight,
|
|
borderRadius: BorderRadius.circular(4),
|
|
),
|
|
child: const Text(
|
|
'已停用',
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
color: AppColors.error,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'${d['title'] ?? ''} · ${d['department'] ?? ''}',
|
|
style: const TextStyle(
|
|
fontSize: 13,
|
|
color: AppColors.textSecondary,
|
|
),
|
|
),
|
|
if (d['professionalDirection'] != null)
|
|
Text(
|
|
d['professionalDirection']!,
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
color: AppColors.textHint,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
PopupMenuButton<String>(
|
|
onSelected: (v) {
|
|
if (v == 'edit') {
|
|
pushRoute(
|
|
ref,
|
|
'adminAddDoctor',
|
|
params: {
|
|
'id': d['id']?.toString() ?? '',
|
|
'phone': d['phone']?.toString() ?? '',
|
|
'name': d['name']?.toString() ?? '',
|
|
'title': d['title']?.toString() ?? '',
|
|
'department': d['department']?.toString() ?? '',
|
|
'direction':
|
|
d['professionalDirection']?.toString() ??
|
|
'',
|
|
},
|
|
);
|
|
}
|
|
if (v == 'toggle') _toggleActive(d['id']);
|
|
if (v == 'delete') _delete(d['id']);
|
|
},
|
|
itemBuilder: (_) => [
|
|
const PopupMenuItem(value: 'edit', child: Text('编辑')),
|
|
PopupMenuItem(
|
|
value: 'toggle',
|
|
child: Text(active ? '停用' : '启用'),
|
|
),
|
|
const PopupMenuItem(
|
|
value: 'delete',
|
|
child: Text(
|
|
'删除',
|
|
style: TextStyle(color: AppColors.error),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|