Add transfer tracking and secure admin access
This commit is contained in:
@@ -17,10 +17,12 @@ class RecognitionBatchPage extends StatefulWidget {
|
||||
|
||||
class _RecognitionBatchPageState extends State<RecognitionBatchPage> {
|
||||
List<RecognitionBatch> _batches = const [];
|
||||
List<RecognitionCandidate> _candidates = const [];
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
String? _restoringId;
|
||||
String? _confirmingId;
|
||||
String? _ignoringId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -30,10 +32,14 @@ class _RecognitionBatchPageState extends State<RecognitionBatchPage> {
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
final batches = await ScreenshotChannel.listRecognitionBatches();
|
||||
final results = await Future.wait([
|
||||
ScreenshotChannel.listRecognitionCandidates(),
|
||||
ScreenshotChannel.listRecognitionBatches(),
|
||||
]);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_batches = batches;
|
||||
_candidates = results[0] as List<RecognitionCandidate>;
|
||||
_batches = results[1] as List<RecognitionBatch>;
|
||||
_loading = false;
|
||||
_error = null;
|
||||
});
|
||||
@@ -84,10 +90,43 @@ class _RecognitionBatchPageState extends State<RecognitionBatchPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _confirmCandidate(RecognitionCandidate item) async {
|
||||
setState(() => _confirmingId = item.id);
|
||||
try {
|
||||
await RecognitionImportService.handleAction(context, {
|
||||
'action': 'recognition_confirm',
|
||||
'candidateId': item.id,
|
||||
});
|
||||
await _load();
|
||||
} finally {
|
||||
if (mounted) setState(() => _confirmingId = null);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _ignoreCandidate(RecognitionCandidate item) async {
|
||||
setState(() => _ignoringId = item.id);
|
||||
try {
|
||||
final ignored = await ScreenshotChannel.acknowledgeRecognitionCandidate(
|
||||
item.id,
|
||||
'expired',
|
||||
);
|
||||
if (!ignored) throw StateError('这条识别结果已处理');
|
||||
await _load();
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(apiErrorMessage(error))));
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _ignoringId = null);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('最近 AI 对账')),
|
||||
appBar: AppBar(title: const Text('识别记录')),
|
||||
body: RefreshIndicator(onRefresh: _load, child: _body()),
|
||||
);
|
||||
}
|
||||
@@ -114,26 +153,108 @@ class _RecognitionBatchPageState extends State<RecognitionBatchPage> {
|
||||
],
|
||||
);
|
||||
}
|
||||
if (_batches.isEmpty) {
|
||||
final pending = _candidates
|
||||
.where((item) => item.state == 'pending_confirm')
|
||||
.toList(growable: false);
|
||||
if (_batches.isEmpty && pending.isEmpty) {
|
||||
return ListView(
|
||||
children: [
|
||||
SizedBox(height: MediaQuery.sizeOf(context).height * 0.3),
|
||||
Icon(Icons.fact_check_outlined, size: 42, color: context.jz.text3),
|
||||
const SizedBox(height: 12),
|
||||
Center(
|
||||
child: Text(
|
||||
'暂无 AI 对账记录',
|
||||
style: TextStyle(color: context.jz.text3),
|
||||
),
|
||||
child: Text('暂无识别记录', style: TextStyle(color: context.jz.text3)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return ListView.separated(
|
||||
return ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 28),
|
||||
itemCount: _batches.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (_, index) => _batchCard(_batches[index]),
|
||||
children: [
|
||||
if (pending.isNotEmpty) ...[
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(2, 4, 2, 10),
|
||||
child: Text(
|
||||
'待确认',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
for (final item in pending) ...[
|
||||
_candidateCard(item),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
],
|
||||
if (_batches.isNotEmpty) ...[
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(2, 10, 2, 10),
|
||||
child: Text(
|
||||
'AI 对账历史',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
for (final batch in _batches) ...[
|
||||
_batchCard(batch),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _candidateCard(RecognitionCandidate item) {
|
||||
final confirming = _confirmingId == item.id;
|
||||
final ignoring = _ignoringId == item.id;
|
||||
final ambiguous = item.identityConfidence == 'ambiguous_repeat';
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
ambiguous ? Icons.content_copy_rounded : Icons.receipt_long_rounded,
|
||||
color: ambiguous ? AppTheme.orange : AppTheme.primary,
|
||||
),
|
||||
title: Text(
|
||||
item.merchant?.trim().isNotEmpty == true
|
||||
? item.merchant!.trim()
|
||||
: '${item.appName}账单',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(ambiguous ? '疑似连续同额交易,请确认是否为新账单' : '识别证据不足,请确认后入账'),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${item.isIncome ? '+' : '-'}¥${item.amount.toStringAsFixed(2)}',
|
||||
style: const TextStyle(fontWeight: FontWeight.w700),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '忽略',
|
||||
onPressed: ignoring || confirming
|
||||
? null
|
||||
: () => _ignoreCandidate(item),
|
||||
icon: ignoring
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.close_rounded),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '确认入账',
|
||||
onPressed: confirming || ignoring
|
||||
? null
|
||||
: () => _confirmCandidate(item),
|
||||
icon: confirming
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.check_rounded),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -218,13 +339,11 @@ class _RecognitionBatchPageState extends State<RecognitionBatchPage> {
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${item.type == 'income' ? '+' : '-'}¥${item.amount.toStringAsFixed(2)}',
|
||||
'${item.isIncome ? '+' : '-'}¥${item.amount.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: item.type == 'income'
|
||||
? AppTheme.primary
|
||||
: AppTheme.red,
|
||||
color: item.isIncome ? AppTheme.primary : AppTheme.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user