diff --git a/client/src/pages/Transactions.js b/client/src/pages/Transactions.js
index 1cfd267..db2b71f 100644
--- a/client/src/pages/Transactions.js
+++ b/client/src/pages/Transactions.js
@@ -1,13 +1,18 @@
import React, { useState, useEffect } from 'react';
-import { Search, Filter, RotateCcw, RefreshCw, Link2, Brain, ChevronLeft, ChevronRight } from 'lucide-react';
-import { getTransactions, updateTransaction, runReconciliation, classifyAll, classifyTransactions, formatAmount, formatDate, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
+import { RotateCcw, Link2, Brain, ChevronLeft, ChevronRight, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
+import { getTransactions, updateTransaction, runReconciliation, classifyAll, classifyTransactions, formatAmount, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
+
+function fmtDatetime(dt) {
+ if (!dt) return '';
+ return String(dt).replace(/:00$/, '').substring(0, 16);
+}
export default function Transactions() {
const [data, setData] = useState({ transactions: [], total: 0, page: 1, totalPages: 0 });
const [filters, setFilters] = useState({
page: 1, limit: 50, start_date: '', end_date: '',
source_type: '', direction: '', category: '', reviewed: '', min_amount: '', keyword: '',
- sort_by: 'transaction_date', sort_order: 'DESC'
+ sort_by: 'transaction_time', sort_order: 'DESC'
});
const [loading, setLoading] = useState(true);
const [categories, setCategories] = useState([]);
@@ -16,31 +21,41 @@ export default function Transactions() {
const [classifying, setClassifying] = useState(false);
const [classifyProgress, setClassifyProgress] = useState(0);
+ // 恢复分类进度(刷新后轮询)
useEffect(() => {
- loadCategories();
+ const saved = sessionStorage.getItem('classifyTask');
+ if (!saved) return;
+ const task = JSON.parse(saved);
+ if (Date.now() - task.ts > 300000) { sessionStorage.removeItem('classifyTask'); return; }
+ setClassifying(true); setClassifyProgress(task.progress || 0);
+ const poll = setInterval(async () => {
+ try {
+ const res = await fetch('/api/transactions/needs-classify');
+ const { total } = await res.json();
+ const p = task.total > 0 ? Math.round((task.total - total) / task.total * 100) : 100;
+ setClassifyProgress(Math.min(Math.max(p, 0), 100));
+ if (total <= 0 || p >= 100) {
+ clearInterval(poll); setClassifying(false); setClassifyProgress(100);
+ sessionStorage.removeItem('classifyTask'); loadTransactions();
+ }
+ } catch (e) { clearInterval(poll); setClassifying(false); sessionStorage.removeItem('classifyTask'); }
+ }, 2000);
+ return () => clearInterval(poll);
}, []);
- useEffect(() => {
- loadTransactions();
- }, [filters]);
+ useEffect(() => { loadCategories(); }, []);
+ useEffect(() => { loadTransactions(); }, [filters]);
async function loadCategories() {
- try {
- const cats = await getCategories();
- setCategories(cats);
- } catch (err) {}
+ try { setCategories(await getCategories()); } catch (err) {}
}
async function loadTransactions() {
setLoading(true);
try {
- const params = { ...filters };
- // Remove empty filter values
- Object.keys(params).forEach(k => {
- if (params[k] === '' || params[k] === undefined) delete params[k];
- });
- const result = await getTransactions(params);
- setData(result);
+ const params = {};
+ for (const [k, v] of Object.entries(filters)) if (v !== '' && v !== undefined) params[k] = v;
+ setData(await getTransactions(params));
} catch (err) {}
setLoading(false);
}
@@ -49,54 +64,68 @@ export default function Transactions() {
setFilters(prev => ({ ...prev, [key]: value, page: key === 'page' ? value : 1 }));
}
+ function toggleSort(field) {
+ setFilters(prev => ({
+ ...prev, sort_by: field,
+ sort_order: prev.sort_by === field && prev.sort_order === 'DESC' ? 'ASC' : 'DESC', page: 1
+ }));
+ }
+
+ function SortIcon({ field }) {
+ if (filters.sort_by !== field) return ;
+ return filters.sort_order === 'ASC' ? : ;
+ }
+
+ function Th({ field, children, style }) {
+ return (
+
toggleSort(field)} style={{ cursor: 'pointer', userSelect: 'none', ...style }}>
+
+ {children}
+
+ |
+ );
+ }
+
async function handleReconcile() {
setReconciling(true);
- try {
- const result = await runReconciliation();
- alert(`对账完成!成功匹配 ${result.matched} 对交易(共检查 ${result.total} 笔)`);
- loadTransactions();
- } catch (err) {}
+ try { const r = await runReconciliation(); alert(`对账完成!成功匹配 ${r.matched} 对`); loadTransactions(); } catch (err) {}
setReconciling(false);
}
async function handleClassifyAll() {
setClassifying(true); setClassifyProgress(0);
+ sessionStorage.setItem('classifyTask', JSON.stringify({ total: 0, progress: 0, ts: Date.now() }));
try {
- const res = await fetch("/api/transactions/needs-classify");
+ const res = await fetch('/api/transactions/needs-classify');
const { ids, total } = await res.json();
- if (!ids.length) { alert("所有交易分类均有效!"); setClassifying(false); return; }
+ if (!ids.length) { alert('所有交易分类均有效!'); setClassifying(false); sessionStorage.removeItem('classifyTask'); return; }
+ sessionStorage.setItem('classifyTask', JSON.stringify({ total, progress: 0, ts: Date.now() }));
const B = 50; let done = 0;
for (let i = 0; i < ids.length; i += B) {
await classifyTransactions(ids.slice(i, i + B));
done += Math.min(B, ids.length - i);
- setClassifyProgress(Math.round(done / total * 100));
+ const pct = Math.round(done / total * 100);
+ setClassifyProgress(pct);
+ sessionStorage.setItem('classifyTask', JSON.stringify({ total, progress: pct, ts: Date.now() }));
}
- alert("分类完成!共重分类 " + total + " 笔交易");
+ sessionStorage.removeItem('classifyTask');
+ alert('分类完成!共重分类 ' + total + ' 笔交易');
loadTransactions();
- } catch (e) { alert("分类失败: " + (e.response?.data?.error || e.message)); }
+ } catch (e) { sessionStorage.removeItem('classifyTask'); alert('分类失败: ' + (e.response?.data?.error || e.message)); }
setClassifying(false);
}
async function handleUpdateTx(id, updates) {
- try {
- await updateTransaction(id, updates);
- setEditingTx(null);
- loadTransactions();
- } catch (err) {}
- }
-
- function openEdit(tx) {
- setEditingTx({ ...tx });
+ try { await updateTransaction(id, updates); setEditingTx(null); loadTransactions(); } catch (err) {}
}
return (
📋 交易明细
-
查看、筛选、对账和分类所有交易记录
+
查看、筛选、排序、对账和分类所有交易记录
- {/* Action Bar */}
- {/* Filter Bar */}
-
-
- updateFilter('start_date', e.target.value)} />
-
-
-
- updateFilter('end_date', e.target.value)} />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- updateFilter('keyword', e.target.value)} />
-
+
updateFilter('start_date', e.target.value)} />
+
updateFilter('end_date', e.target.value)} />
+
+
+
+
+
updateFilter('keyword', e.target.value)} />
- {/* Transaction Table */}
共 {data.total} 笔交易
-
- 第 {data.page}/{data.totalPages} 页
-
+ 第 {data.page}/{data.totalPages} 页 · 点击列头排序
{loading ? (
@@ -178,145 +175,73 @@ export default function Transactions() {
- | 交易编码 |
- 日期 |
- 来源 |
- 对方 |
- 描述 |
- 分类 |
- 金额 |
- 方向 |
- 匹配 |
- 确认 |
+ 日期时间 |
+ 来源 |
+ 对方 |
+ 描述 |
+ 分类 |
+ 金额 |
+ 方向 |
操作 |
{data.transactions.map(tx => (
- |
- {tx.transaction_code}
- |
- {formatDate(tx.transaction_date)} |
-
-
- {SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
-
+ |
+ {fmtDatetime(tx.transaction_time) || fmtDatetime(tx.transaction_date)}
|
+ {SOURCE_TYPE_MAP[tx.source_type] || tx.source_type} |
{tx.counterparty || '--'} |
-
+ |
{tx.ai_description || tx.description || '--'}
|
-
- {tx.category ? (
- {tx.category}
- ) : (
- 未分类
- )}
- |
-
+ | {tx.category ? {tx.category} : 未分类} |
+
{formatAmount(tx.amount)}
|
-
-
- {tx.direction === 'income' ? '收入' : '支出'}
-
- |
-
- {tx.matched_transaction_id ? (
- 已对账
- ) : --}
- |
-
- {tx.reviewed ? (
- ✓ 已确认
- ) : (
- 待确认
- )}
- |
-
- openEdit(tx)}>
- 编辑
-
- |
+ {tx.direction === 'income' ? '收入' : '支出'} |
+ setEditingTx({ ...tx })}>编辑 |
))}
- {/* Pagination */}
{data.totalPages > 1 && (
- updateFilter('page', data.page - 1)}>
- 上一页
-
+ updateFilter('page', data.page - 1)}> 上一页
{Array.from({ length: Math.min(data.totalPages, 7) }, (_, i) => {
- const pageNum = i + Math.max(1, data.page - 3);
- if (pageNum > data.totalPages) return null;
- return (
- updateFilter('page', pageNum)}>
- {pageNum}
-
- );
+ const p = i + Math.max(1, data.page - 3);
+ if (p > data.totalPages) return null;
+ return updateFilter('page', p)}>{p};
})}
- = data.totalPages} onClick={() => updateFilter('page', data.page + 1)}>
- 下一页
-
+ = data.totalPages} onClick={() => updateFilter('page', data.page + 1)}>下一页
)}
>
) : (
-
+
)}
- {/* Edit Modal */}
{editingTx && (
setEditingTx(null)}>
e.stopPropagation()}>
编辑交易
- {editingTx.transaction_code} | {formatDate(editingTx.transaction_date)}
+ {editingTx.transaction_code} | {fmtDatetime(editingTx.transaction_time)}
-
-
-
-
-
-
-
-
- setEditingTx({ ...editingTx, ai_description: e.target.value })} />
-
-
-
-
-
-
-
+
+
setEditingTx({ ...editingTx, ai_description: e.target.value })} />
+
setEditingTx(null)}>取消
- handleUpdateTx(editingTx.id, {
- category: editingTx.category,
- ai_description: editingTx.ai_description,
- reviewed: editingTx.reviewed
- })}>保存
+ handleUpdateTx(editingTx.id, { category: editingTx.category, ai_description: editingTx.ai_description, reviewed: editingTx.reviewed })}>保存
diff --git a/data/example/~$农行20260505.xlsx b/data/example/~$农行20260505.xlsx
deleted file mode 100644
index 7cde593..0000000
Binary files a/data/example/~$农行20260505.xlsx and /dev/null differ
diff --git a/server/services/llm.js b/server/services/llm.js
index de4745d..c2270e9 100644
--- a/server/services/llm.js
+++ b/server/services/llm.js
@@ -88,6 +88,7 @@ async function classifyTransactions(transactionIds) {
temperature: 0.3, max_tokens: 2000,
});
const content = response.choices[0].message.content;
+ console.log(content)
const jsonMatch = content.match(/\[[\s\S]*\]/);
if (jsonMatch) {
const results = JSON.parse(jsonMatch[0]);