diff --git a/client/src/pages/Transactions.js b/client/src/pages/Transactions.js
index 506e582..5f9c1fa 100644
--- a/client/src/pages/Transactions.js
+++ b/client/src/pages/Transactions.js
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
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';
+import { getTransactions, runReconciliation, classifyTransactions, formatAmount, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
function fmtDatetime(dt) {
if (!dt) return '';
@@ -11,18 +11,17 @@ 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: '',
+ source_type: '', direction: '', keyword: '',
sort_by: 'transaction_time', sort_order: 'DESC'
});
const [loading, setLoading] = useState(true);
const [categories, setCategories] = useState([]);
- const [editingTx, setEditingTx] = useState(null);
const [reconciling, setReconciling] = useState(false);
const [classifying, setClassifying] = useState(false);
const [classifyProgress, setClassifyProgress] = useState(0);
const [deals, setDeals] = useState(null);
- // 恢复分类进度(刷新后轮询)
+ // 恢复分类进度
useEffect(() => {
const saved = sessionStorage.getItem('classifyTask');
if (!saved) return;
@@ -35,67 +34,44 @@ export default function Transactions() {
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();
- }
+ if (total <= 0 || p >= 100) { clearInterval(poll); setClassifying(false); sessionStorage.removeItem('classifyTask'); loadTransactions(); }
} catch (e) { clearInterval(poll); setClassifying(false); sessionStorage.removeItem('classifyTask'); }
}, 2000);
return () => clearInterval(poll);
}, []);
- useEffect(() => { loadCategories(); }, []);
+ useEffect(() => { loadCategories(); loadDeals(); }, []);
useEffect(() => { loadTransactions(); }, [filters]);
- async function loadCategories() {
- try { setCategories(await getCategories()); } catch (err) {}
- }
+ async function loadCategories() { try { setCategories(await getCategories()); } catch (e) {} }
+ async function loadDeals() { try { const r = await fetch('/api/deals'); setDeals((await r.json()).deals); } catch (e) {} }
async function loadTransactions() {
setLoading(true);
try {
- const params = {};
- for (const [k, v] of Object.entries(filters)) if (v !== '' && v !== undefined) params[k] = v;
- setData(await getTransactions(params));
- } catch (err) {}
+ const p = {}; for (const [k, v] of Object.entries(filters)) if (v !== '' && v !== undefined) p[k] = v;
+ setData(await getTransactions(p));
+ } catch (e) {}
setLoading(false);
}
- function updateFilter(key, value) {
- setFilters(prev => ({ ...prev, [key]: value, page: key === 'page' ? value : 1 }));
- }
+ function updateFilter(k, v) { setFilters(prev => ({ ...prev, [k]: v, page: k === 'page' ? v : 1 })); }
function toggleSort(field) {
- setFilters(prev => ({
- ...prev, sort_by: field,
- sort_order: prev.sort_by === field && prev.sort_order === 'DESC' ? 'ASC' : 'DESC', page: 1
- }));
+ 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
查看、筛选、排序、对账和分类所有交易记录
-查看、筛选、排序、对账和分类
| 日期时间 | -来源 | -对方 | -描述 | -金额 | -方向 | -操作 | +
|---|
| 日期时间 | +来源 | +对方 | +描述 | +金额 | +方向 | +||
|---|---|---|---|---|---|---|---|
| {fmtDatetime(tx.transaction_time) || fmtDatetime(tx.transaction_date)} | +{SOURCE_TYPE_MAP[tx.source_type] || tx.source_type} | +{tx.counterparty || '--'} | +{tx.description || '--'} | +{formatAmount(tx.amount)} | +{tx.direction === 'income' ? '收入' : '支出'} | ||
| - {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} : 未分类} | -- {formatAmount(tx.amount)} - | -{tx.direction === 'income' ? '收入' : '支出'} | -- |
| 日期 | 金额 | 对方 | 关联明细 | |||||
|---|---|---|---|---|---|---|---|---|
| 日期 | 金额 | 分类 | 对方 | 关联明细 | ||||
| {d.deal_date} | -= 0 ? "stat-value income" : "stat-value expense"}>{formatAmount(d.amount)} | -{d.counterparty || "--"} | -- {d.transactions?.map((t,i) => ( + | {d.deal_date} | += 0 ? 'stat-value income' : 'stat-value expense'}>{formatAmount(d.amount)} | +{d.category || 未分类} | +{d.counterparty || '--'} | ++ {d.transactions?.map((t, i) => ( - {SOURCE_TYPE_MAP[t.source_type]} - {" "}{t.description?.substring(0,20)}↔ + {SOURCE_TYPE_MAP[t.source_type]} + {' '}{t.description?.substring(0, 20)} ))} | @@ -258,27 +189,6 @@ export default function Transactions() {