feat: add Flutter mobile clients and staff delivery API
This commit is contained in:
143
apps/service_app/lib/ui/features/profile/profile_page.dart
Normal file
143
apps/service_app/lib/ui/features/profile/profile_page.dart
Normal file
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../app/dependencies.dart';
|
||||
import '../../../data/offline/encrypted_draft_store.dart';
|
||||
import '../../../data/repositories/service_repository.dart';
|
||||
import '../../../domain/models/service_models.dart';
|
||||
|
||||
class ProfilePage extends StatefulWidget {
|
||||
const ProfilePage({
|
||||
required this.session,
|
||||
required this.repository,
|
||||
required this.drafts,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final StaffSession session;
|
||||
final ServiceRepository repository;
|
||||
final EncryptedDraftStore drafts;
|
||||
|
||||
@override
|
||||
State<ProfilePage> createState() => _ProfilePageState();
|
||||
}
|
||||
|
||||
class _ProfilePageState extends State<ProfilePage> {
|
||||
late Future<(StaffProfile, Map<String, Object?>, int)> _future;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_future = _load();
|
||||
}
|
||||
|
||||
Future<(StaffProfile, Map<String, Object?>, int)> _load() async => (
|
||||
await widget.repository.profile(),
|
||||
await widget.repository.wallet(),
|
||||
await widget.drafts.count(widget.session.identity),
|
||||
);
|
||||
|
||||
Future<void> _logout(int draftCount) async {
|
||||
if (draftCount > 0) {
|
||||
final discard = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('仍有未同步现场草稿'),
|
||||
content: Text('当前账号有 $draftCount 份加密草稿。建议返回任务页完成上传;若确认放弃,将安全删除草稿和附件。'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('返回上传')),
|
||||
FilledButton(onPressed: () => Navigator.pop(context, true), child: const Text('放弃并删除')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (discard != true) return;
|
||||
await widget.drafts.discardAccount(widget.session.identity);
|
||||
}
|
||||
await widget.session.logout();
|
||||
if (mounted) context.go('/login');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const Text('我的工作台')),
|
||||
body: FutureBuilder<(StaffProfile, Map<String, Object?>, int)>(
|
||||
future: _future,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
if (snapshot.hasError) return Center(child: Text(snapshot.error.toString()));
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final (profile, wallet, drafts) = snapshot.data!;
|
||||
final balance = (wallet['balance'] as num?)?.toInt() ?? 0;
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 30,
|
||||
child: Text(profile.name.isEmpty ? '工' : profile.name.substring(0, 1)),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
profile.name,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w900),
|
||||
),
|
||||
Text('${roleName(profile.roleCode)} · ${profile.phone}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
Chip(label: Text(profile.workStatus == 'on_duty' ? '在岗' : '离岗')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.account_balance_wallet_outlined),
|
||||
title: const Text('钱包余额'),
|
||||
trailing: Text(
|
||||
'¥${(balance / 100).toStringAsFixed(2)}',
|
||||
style: const TextStyle(fontWeight: FontWeight.w900),
|
||||
),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.lock_outline),
|
||||
title: const Text('加密现场草稿'),
|
||||
subtitle: const Text('仅当前账号重新认证后可恢复'),
|
||||
trailing: Text('$drafts 份'),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.verified_user_outlined),
|
||||
title: const Text('重新执行作业前检查'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => context.go('/preflight'),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.logout),
|
||||
title: const Text('退出登录'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _logout(drafts),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user