version 0.1
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { TrendingUp, TrendingDown, AlertCircle, FileText, RefreshCcw } from 'lucide-react';
|
||||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, PieChart, Pie, Cell } from 'recharts';
|
||||
import { getOverview, getMonthly, formatAmount } from '../hooks/useApi';
|
||||
|
||||
const COLORS = ['#4f46e5', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4', '#f97316', '#84cc16', '#14b8a6', '#6366f1', '#e11d48'];
|
||||
|
||||
export default function Dashboard() {
|
||||
const [overview, setOverview] = useState(null);
|
||||
const [monthly, setMonthly] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
async function loadData() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [overviewData, monthlyData] = await Promise.all([
|
||||
getOverview(),
|
||||
getMonthly(12)
|
||||
]);
|
||||
setOverview(overviewData);
|
||||
setMonthly(monthlyData);
|
||||
} catch (err) {
|
||||
console.error('加载数据失败:', err);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="loading">
|
||||
<div className="spinner"></div>
|
||||
加载中...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const ov = overview?.overview || {};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h2>📊 财务仪表盘</h2>
|
||||
<p>全面掌握你的收支情况</p>
|
||||
</div>
|
||||
|
||||
{/* Stats Cards */}
|
||||
<div className="stats-grid">
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">💰 总收入</div>
|
||||
<div className="stat-value income">{formatAmount(ov.total_income)}</div>
|
||||
<div className="stat-sub">所有来源收入合计</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">💸 总支出</div>
|
||||
<div className="stat-value expense">{formatAmount(ov.total_expense)}</div>
|
||||
<div className="stat-sub">所有支出合计</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">📈 净收支</div>
|
||||
<div className={`stat-value ${(ov.total_income - ov.total_expense) >= 0 ? 'income' : 'expense'}`}>
|
||||
{formatAmount(ov.total_income - ov.total_expense)}
|
||||
</div>
|
||||
<div className="stat-sub">收入 - 支出</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">📝 交易总数</div>
|
||||
<div className="stat-value primary">{ov.total_count || 0}</div>
|
||||
<div className="stat-sub">已导入 {ov.matched_count || 0} 笔已对账</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">⚠️ 待确认</div>
|
||||
<div className="stat-value warning">{ov.pending_review || 0}</div>
|
||||
<div className="stat-sub">≥100元 未确认交易</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Charts Row */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20, marginBottom: 24 }}>
|
||||
{/* Monthly Trend */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>📅 月度收支趋势</h3>
|
||||
</div>
|
||||
{monthly.length > 0 ? (
|
||||
<ResponsiveContainer width="100%" height={280}>
|
||||
<BarChart data={monthly}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="#e2e8f0" />
|
||||
<XAxis dataKey="month" tick={{ fontSize: 11 }} />
|
||||
<YAxis tick={{ fontSize: 11 }} />
|
||||
<Tooltip
|
||||
formatter={(value) => formatAmount(value)}
|
||||
labelStyle={{ fontWeight: 600 }}
|
||||
/>
|
||||
<Bar dataKey="income" name="收入" fill="#10b981" radius={[4,4,0,0]} />
|
||||
<Bar dataKey="expense" name="支出" fill="#ef4444" radius={[4,4,0,0]} />
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">📭</div>
|
||||
<p>暂无数据,请先导入账单</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Category Pie */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>🏷️ 支出分类占比</h3>
|
||||
</div>
|
||||
{overview?.categoryStats?.length > 0 ? (
|
||||
<ResponsiveContainer width="100%" height={280}>
|
||||
<PieChart>
|
||||
<Pie
|
||||
data={overview.categoryStats.slice(0, 8)}
|
||||
cx="50%"
|
||||
cy="50%"
|
||||
outerRadius={100}
|
||||
dataKey="total_amount"
|
||||
nameKey="category"
|
||||
label={({ category, percent }) => `${category} ${(percent * 100).toFixed(0)}%`}
|
||||
labelLine={false}
|
||||
>
|
||||
{overview.categoryStats.slice(0, 8).map((_, idx) => (
|
||||
<Cell key={idx} fill={COLORS[idx % COLORS.length]} />
|
||||
))}
|
||||
</Pie>
|
||||
<Tooltip formatter={(value) => formatAmount(value)} />
|
||||
</PieChart>
|
||||
</ResponsiveContainer>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">📭</div>
|
||||
<p>暂无分类数据</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Source Summary */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>🏦 各来源汇总</h3>
|
||||
</div>
|
||||
{overview?.sourceStats?.length > 0 ? (
|
||||
<div className="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>来源</th>
|
||||
<th>交易笔数</th>
|
||||
<th>收入合计</th>
|
||||
<th>支出合计</th>
|
||||
<th>净额</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{overview.sourceStats.map((s, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<span className={`source-type-label source-${s.source_type}`}>
|
||||
{s.source_type === 'alipay' && '支付宝'}
|
||||
{s.source_type === 'wechat' && '微信支付'}
|
||||
{s.source_type === 'bank_debit' && '银行借记卡'}
|
||||
{s.source_type === 'bank_credit' && '银行贷记卡'}
|
||||
{s.source_type === 'credit_card' && '信用卡'}
|
||||
</span>
|
||||
</td>
|
||||
<td>{s.count}</td>
|
||||
<td style={{ color: 'var(--success)' }}>{formatAmount(s.total_income)}</td>
|
||||
<td style={{ color: 'var(--danger)' }}>{formatAmount(s.total_expense)}</td>
|
||||
<td className={s.total_income - s.total_expense >= 0 ? 'stat-value income' : 'stat-value expense'}>
|
||||
{formatAmount(s.total_income - s.total_expense)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">📭</div>
|
||||
<p>暂无数据,请先导入账单</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import {
|
||||
Upload,
|
||||
FileText,
|
||||
CheckCircle,
|
||||
AlertCircle,
|
||||
Trash2,
|
||||
RefreshCw,
|
||||
} from "lucide-react";
|
||||
import { uploadFile, getSources, deleteSource } from "../hooks/useApi";
|
||||
|
||||
const SOURCE_TYPES = [
|
||||
{
|
||||
value: "alipay",
|
||||
label: "支付宝",
|
||||
icon: "\uD83D\uDD35",
|
||||
desc: "支付宝账单 CSV/XLSX 文件",
|
||||
},
|
||||
{
|
||||
value: "wechat",
|
||||
label: "微信支付",
|
||||
icon: "\uD83D\uDFE2",
|
||||
desc: "微信支付账单 XLSX/CSV 文件",
|
||||
},
|
||||
{
|
||||
value: "bank_debit",
|
||||
label: "银行借记卡",
|
||||
icon: "\uD83C\uDFE6",
|
||||
desc: "工资卡/储蓄卡流水文件",
|
||||
},
|
||||
{
|
||||
value: "credit_card",
|
||||
label: "信用卡",
|
||||
icon: "\uD83D\uDCB3",
|
||||
desc: "信用卡账单文件",
|
||||
},
|
||||
];
|
||||
|
||||
const ALLOWED_EXTS = ["csv", "txt", "xlsx", "xls"];
|
||||
|
||||
export default function Import() {
|
||||
const [sourceType, setSourceType] = useState("alipay");
|
||||
const [sourceName, setSourceName] = useState("");
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [uploadResult, setUploadResult] = useState(null);
|
||||
const [sources, setSources] = useState([]);
|
||||
const [error, setError] = useState("");
|
||||
const [dragOver, setDragOver] = useState(false);
|
||||
const fileInputRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadSources();
|
||||
}, []);
|
||||
|
||||
async function loadSources() {
|
||||
try {
|
||||
const data = await getSources();
|
||||
setSources(data);
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function handleFile(file) {
|
||||
if (!file) return;
|
||||
const ext = file.name.split(".").pop().toLowerCase();
|
||||
if (!ALLOWED_EXTS.includes(ext)) {
|
||||
setError("仅支持 CSV / TXT / XLSX / XLS 文件格式");
|
||||
return;
|
||||
}
|
||||
setError("");
|
||||
setUploading(true);
|
||||
setUploadResult(null);
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("source_type", sourceType);
|
||||
formData.append(
|
||||
"source_name",
|
||||
sourceName ||
|
||||
`${SOURCE_TYPES.find((s) => s.value === sourceType)?.label}_${new Date().toLocaleDateString()}`,
|
||||
);
|
||||
const result = await uploadFile(formData);
|
||||
setUploadResult(result);
|
||||
await loadSources();
|
||||
} catch (err) {
|
||||
setError(err.response?.data?.error || err.message || "上传失败");
|
||||
}
|
||||
setUploading(false);
|
||||
}
|
||||
|
||||
async function handleDeleteSource(id) {
|
||||
if (!window.confirm("确定要删除这个导入来源及其所有交易记录吗?")) return;
|
||||
try {
|
||||
await deleteSource(id);
|
||||
await loadSources();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
function handleDrop(e) {
|
||||
e.preventDefault();
|
||||
setDragOver(false);
|
||||
const file = e.dataTransfer.files[0];
|
||||
handleFile(file);
|
||||
}
|
||||
|
||||
const SOURCE_LABEL_MAP = {
|
||||
alipay: "支付宝",
|
||||
wechat: "微信支付",
|
||||
bank_debit: "银行借记卡",
|
||||
bank_credit: "银行贷记卡",
|
||||
credit_card: "信用卡",
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h2>📥 导入账单</h2>
|
||||
<p>
|
||||
上传支付宝、微信、银行卡等账单文件(CSV/TXT/XLSX/XLS),系统自动解析并分类
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 类型选择 */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>选择账单类型</h3>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(180px, 1fr))",
|
||||
gap: 12,
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
{SOURCE_TYPES.map((st) => (
|
||||
<div
|
||||
key={st.value}
|
||||
onClick={() => setSourceType(st.value)}
|
||||
style={{
|
||||
padding: "16px",
|
||||
cursor: "pointer",
|
||||
textAlign: "center",
|
||||
borderRadius: "12px",
|
||||
border: `2px solid ${sourceType === st.value ? "var(--primary)" : "var(--border)"}`,
|
||||
background:
|
||||
sourceType === st.value ? "var(--primary-bg)" : "white",
|
||||
transition: "all 0.2s",
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 32, marginBottom: 8 }}>{st.icon}</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 14 }}>{st.label}</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-secondary)",
|
||||
marginTop: 4,
|
||||
}}
|
||||
>
|
||||
{st.desc}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>账单名称(可选)</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="如:工商银行工资卡、招商银行信用卡..."
|
||||
value={sourceName}
|
||||
onChange={(e) => setSourceName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 上传区域 */}
|
||||
<div
|
||||
className={`upload-zone ${dragOver ? "drag-over" : ""}`}
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault();
|
||||
setDragOver(true);
|
||||
}}
|
||||
onDragLeave={() => setDragOver(false)}
|
||||
onDrop={handleDrop}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
>
|
||||
<div className="upload-icon">
|
||||
{uploading ? (
|
||||
<RefreshCw
|
||||
size={48}
|
||||
style={{ animation: "spin 1s linear infinite" }}
|
||||
/>
|
||||
) : (
|
||||
<Upload size={48} />
|
||||
)}
|
||||
</div>
|
||||
<div style={{ fontSize: 16, fontWeight: 500, marginBottom: 8 }}>
|
||||
{uploading ? "正在解析..." : "拖拽文件到此处,或点击选择"}
|
||||
</div>
|
||||
<div style={{ fontSize: 13, color: "var(--text-secondary)" }}>
|
||||
支持 .csv / .txt / .xlsx / .xls 文件,最大 20MB
|
||||
</div>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".csv,.txt,.xlsx,.xls"
|
||||
style={{ display: "none" }}
|
||||
onChange={(e) => handleFile(e.target.files[0])}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div
|
||||
style={{
|
||||
marginTop: 16,
|
||||
padding: "12px 16px",
|
||||
background: "#fef2f2",
|
||||
borderRadius: 8,
|
||||
color: "var(--danger)",
|
||||
fontSize: 14,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<AlertCircle size={18} />
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{uploadResult && (
|
||||
<div
|
||||
style={{
|
||||
marginTop: 16,
|
||||
padding: "16px",
|
||||
background: "#f0fdf4",
|
||||
borderRadius: 8,
|
||||
border: "1px solid #bbf7d0",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
marginBottom: 8,
|
||||
}}
|
||||
>
|
||||
<CheckCircle size={20} color="var(--success)" />
|
||||
<span style={{ fontWeight: 600, color: "var(--success)" }}>
|
||||
导入成功!
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 13, color: "var(--text-secondary)" }}>
|
||||
共导入 <strong>{uploadResult.record_count}</strong> 笔, 写入{" "}
|
||||
<strong>
|
||||
{uploadResult.inserted ?? uploadResult.record_count}
|
||||
</strong>{" "}
|
||||
笔
|
||||
{uploadResult.skipped > 0 && (
|
||||
<span>(跳过 {uploadResult.skipped} 笔重复)</span>
|
||||
)}
|
||||
, 分类 <strong>{uploadResult.classified || 0}</strong> 笔 (
|
||||
{uploadResult.classify_source === "llm"
|
||||
? "大模型"
|
||||
: uploadResult.classify_source === "rules"
|
||||
? "规则匹配"
|
||||
: "待分类"}
|
||||
)
|
||||
</div>
|
||||
{uploadResult.sample?.length > 0 && (
|
||||
<div style={{ marginTop: 12 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, marginBottom: 6 }}>
|
||||
示例数据:
|
||||
</div>
|
||||
<div className="table-container">
|
||||
<table style={{ fontSize: 12 }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日期</th>
|
||||
<th>对方</th>
|
||||
<th>描述</th>
|
||||
<th>金额</th>
|
||||
<th>方向</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{uploadResult.sample.map((s, i) => (
|
||||
<tr key={i}>
|
||||
<td>{s.transaction_date}</td>
|
||||
<td>{s.counterparty}</td>
|
||||
<td>{s.description}</td>
|
||||
<td
|
||||
className={
|
||||
s.direction === "income"
|
||||
? "stat-value income"
|
||||
: "stat-value expense"
|
||||
}
|
||||
>
|
||||
{s.amount.toFixed(2)}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
className={`tag ${s.direction === "income" ? "tag-income" : "tag-expense"}`}
|
||||
>
|
||||
{s.direction === "income" ? "收入" : "支出"}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 已导入列表 */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>📋 已导入的账单</h3>
|
||||
<button className="btn btn-secondary btn-sm" onClick={loadSources}>
|
||||
<RefreshCw size={14} /> 刷新
|
||||
</button>
|
||||
</div>
|
||||
{sources.length > 0 ? (
|
||||
<div className="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>账单名称</th>
|
||||
<th>类型</th>
|
||||
<th>文件名</th>
|
||||
<th>记录数</th>
|
||||
<th>导入时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sources.map((s) => (
|
||||
<tr key={s.id}>
|
||||
<td>
|
||||
<FileText size={14} style={{ marginRight: 6 }} />
|
||||
{s.source_name}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
className={`source-type-label source-${s.source_type}`}
|
||||
>
|
||||
{SOURCE_LABEL_MAP[s.source_type] || s.source_type}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
style={{ fontSize: 12, color: "var(--text-secondary)" }}
|
||||
>
|
||||
{s.file_name}
|
||||
</td>
|
||||
<td>{s.tx_count || s.record_count}</td>
|
||||
<td style={{ fontSize: 12 }}>{s.imported_at}</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn btn-danger btn-sm"
|
||||
onClick={() => handleDeleteSource(s.id)}
|
||||
>
|
||||
<Trash2 size={12} /> 删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">📭</div>
|
||||
<p>还没有导入任何账单</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { CheckCircle, X, Edit3, Brain, Search, Filter } from 'lucide-react';
|
||||
import { getTransactions, updateTransaction, formatAmount, formatDate, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
|
||||
|
||||
export default function Review() {
|
||||
const [transactions, setTransactions] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [categories, setCategories] = useState([]);
|
||||
const [editingTx, setEditingTx] = useState(null);
|
||||
const [showReviewed, setShowReviewed] = useState(false);
|
||||
const [keyword, setKeyword] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
loadCategories();
|
||||
loadReviewTransactions();
|
||||
}, [showReviewed, keyword]);
|
||||
|
||||
async function loadCategories() {
|
||||
try {
|
||||
const cats = await getCategories();
|
||||
setCategories(cats);
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function loadReviewTransactions() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = {
|
||||
min_amount: 100, // Only >= 100 RMB
|
||||
limit: 200,
|
||||
sort_by: 'amount',
|
||||
sort_order: 'DESC'
|
||||
};
|
||||
if (!showReviewed) params.reviewed = 0;
|
||||
if (keyword) params.keyword = keyword;
|
||||
|
||||
const result = await getTransactions(params);
|
||||
setTransactions(result.transactions);
|
||||
setTotal(result.total);
|
||||
|
||||
// Update badge count in sidebar
|
||||
try {
|
||||
const badge = document.getElementById('review-badge');
|
||||
if (badge) {
|
||||
// Get fresh unreviewed count
|
||||
const { getOverview } = require('../hooks/useApi');
|
||||
// Just use local count
|
||||
if (!showReviewed) badge.textContent = result.total;
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (err) {}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
async function handleConfirm(tx) {
|
||||
try {
|
||||
await updateTransaction(tx.id, { reviewed: 1 });
|
||||
loadReviewTransactions();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function handleUpdateTx(id, updates) {
|
||||
try {
|
||||
await updateTransaction(id, updates);
|
||||
setEditingTx(null);
|
||||
loadReviewTransactions();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function handleConfirmAll() {
|
||||
if (!window.confirm(`确定要批量确认当前显示的 ${transactions.length} 笔交易吗?`)) return;
|
||||
for (const tx of transactions) {
|
||||
if (!tx.reviewed) {
|
||||
try { await updateTransaction(tx.id, { reviewed: 1 }); } catch (err) {}
|
||||
}
|
||||
}
|
||||
loadReviewTransactions();
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h2>🔍 大额交易确认</h2>
|
||||
<p>逐笔确认 ≥100 元的交易,核对AI分类和描述是否正确</p>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<div style={{ display: 'flex', gap: 10, marginBottom: 20, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||
<div className="form-group" style={{ marginBottom: 0, minWidth: 200 }}>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="🔍 搜索对方/描述..."
|
||||
value={keyword}
|
||||
onChange={e => setKeyword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer', fontSize: 14 }}>
|
||||
<input type="checkbox" checked={showReviewed} onChange={e => setShowReviewed(e.target.checked)} />
|
||||
显示已确认
|
||||
</label>
|
||||
<div style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 14, color: 'var(--text-secondary)' }}>
|
||||
共 <strong>{total}</strong> 笔大额交易
|
||||
{!showReviewed && <span style={{ color: 'var(--warning)' }}>(待确认)</span>}
|
||||
</span>
|
||||
<button className="btn btn-success btn-sm" onClick={handleConfirmAll}>
|
||||
<CheckCircle size={14} /> 全部确认
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Review List */}
|
||||
<div className="card">
|
||||
{loading ? (
|
||||
<div className="loading"><div className="spinner"></div>加载中...</div>
|
||||
) : transactions.length > 0 ? (
|
||||
<div>
|
||||
{transactions.map(tx => (
|
||||
<div key={tx.id} className={`review-item ${tx.reviewed ? 'reviewed' : ''}`}>
|
||||
<div className={`amount-col ${tx.direction === 'income' ? 'stat-value income' : 'stat-value expense'}`}>
|
||||
{formatAmount(tx.amount)}
|
||||
</div>
|
||||
|
||||
<div className="info-col">
|
||||
<div className="title">
|
||||
{tx.ai_description || tx.description || '无描述'}
|
||||
</div>
|
||||
<div className="meta">
|
||||
{formatDate(tx.transaction_date)} ·
|
||||
<span className={`source-type-label source-${tx.source_type}`} style={{ marginLeft: 4 }}>
|
||||
{SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
|
||||
</span>
|
||||
{tx.counterparty && <span> · {tx.counterparty}</span>}
|
||||
{tx.category && (
|
||||
<span className="tag tag-matched" style={{ marginLeft: 6 }}>{tx.category}</span>
|
||||
)}
|
||||
{tx.reviewed && <span style={{ marginLeft: 6, color: 'var(--success)' }}>✓ 已确认</span>}
|
||||
{tx.matched_transaction_id && (
|
||||
<span className="tag tag-matched" style={{ marginLeft: 6 }}>已对账</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="action-col">
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => setEditingTx({ ...tx })}>
|
||||
<Edit3 size={12} /> 编辑
|
||||
</button>
|
||||
{!tx.reviewed && (
|
||||
<button className="btn btn-success btn-sm" onClick={() => handleConfirm(tx)}>
|
||||
<CheckCircle size={12} /> 确认
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">✅</div>
|
||||
<p>{showReviewed ? '没有已确认的大额交易' : '所有大额交易已确认!'}</p>
|
||||
<p style={{ fontSize: 13, marginTop: 8 }}>
|
||||
{showReviewed ? '尝试切换显示模式' : '可以去交易明细页面查看所有记录'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Edit Modal */}
|
||||
{editingTx && (
|
||||
<div className="modal-overlay" onClick={() => setEditingTx(null)}>
|
||||
<div className="modal" onClick={e => e.stopPropagation()}>
|
||||
<h3>编辑交易分类与描述</h3>
|
||||
|
||||
<div style={{
|
||||
marginBottom: 16, padding: 12, background: 'var(--bg)',
|
||||
borderRadius: 8, fontSize: 13
|
||||
}}>
|
||||
<div style={{ fontWeight: 600, marginBottom: 4 }}>
|
||||
{formatAmount(editingTx.amount)} · {formatDate(editingTx.transaction_date)}
|
||||
</div>
|
||||
<div style={{ color: 'var(--text-secondary)' }}>
|
||||
{editingTx.counterparty} · {editingTx.description}
|
||||
</div>
|
||||
<div style={{ fontFamily: 'monospace', fontSize: 11, color: 'var(--text-secondary)', marginTop: 4 }}>
|
||||
编码: {editingTx.transaction_code}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>分类</label>
|
||||
<select className="form-select" value={editingTx.category || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, category: e.target.value })}>
|
||||
<option value="">选择分类</option>
|
||||
{categories.map(c => (
|
||||
<option key={c.id} value={c.name}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>交易描述</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
value={editingTx.ai_description || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, ai_description: e.target.value })}
|
||||
placeholder="简要描述这笔交易..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>备注</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
value={editingTx.review_notes || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, review_notes: e.target.value })}
|
||||
placeholder="人工备注(可选)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 10, justifyContent: 'flex-end', marginTop: 20 }}>
|
||||
<button className="btn btn-secondary" onClick={() => setEditingTx(null)}>取消</button>
|
||||
<button className="btn btn-primary" onClick={() => handleUpdateTx(editingTx.id, {
|
||||
category: editingTx.category,
|
||||
ai_description: editingTx.ai_description,
|
||||
review_notes: editingTx.review_notes,
|
||||
reviewed: 1
|
||||
})}>
|
||||
保存并确认
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Save, Zap, Plus, Trash2, RefreshCw } from 'lucide-react';
|
||||
import { getConfig, updateConfig, testLLM, getCategories, updateCategory } from '../hooks/useApi';
|
||||
|
||||
export default function SettingsPage() {
|
||||
const [config, setConfig] = useState({
|
||||
llm_api_key: '',
|
||||
llm_base_url: 'https://api.openai.com/v1',
|
||||
llm_model: 'gpt-4o-mini'
|
||||
});
|
||||
const [categories, setCategories] = useState([]);
|
||||
const [llmStatus, setLLMStatus] = useState(null);
|
||||
const [testingLlm, setTestingLlm] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [editingCat, setEditingCat] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadAll();
|
||||
}, []);
|
||||
|
||||
async function loadAll() {
|
||||
try {
|
||||
const [cfg, cats] = await Promise.all([getConfig(), getCategories()]);
|
||||
setConfig(prev => ({ ...prev, ...cfg }));
|
||||
setCategories(cats);
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function handleSaveConfig() {
|
||||
setSaving(true);
|
||||
try {
|
||||
await updateConfig(config);
|
||||
alert('配置保存成功!');
|
||||
} catch (err) {}
|
||||
setSaving(false);
|
||||
}
|
||||
|
||||
async function handleTestLLM() {
|
||||
setTestingLlm(true);
|
||||
setLLMStatus(null);
|
||||
// Save config first
|
||||
await updateConfig(config);
|
||||
try {
|
||||
const result = await testLLM();
|
||||
setLLMStatus({ success: true, message: `连接成功!模型: ${result.model}, 回复: ${result.reply}` });
|
||||
} catch (err) {
|
||||
setLLMStatus({ success: false, message: err.response?.data?.error || err.message });
|
||||
}
|
||||
setTestingLlm(false);
|
||||
}
|
||||
|
||||
async function handleUpdateCategory(id, field, value) {
|
||||
try {
|
||||
await updateCategory(id, { [field]: value });
|
||||
loadAll();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h2>⚙️ 系统设置</h2>
|
||||
<p>配置大模型API及管理交易分类</p>
|
||||
</div>
|
||||
|
||||
{/* LLM Configuration */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>🤖 大模型配置</h3>
|
||||
<span style={{ fontSize: 12, color: 'var(--text-secondary)' }}>
|
||||
支持 OpenAI 兼容API(Ollama、DeepSeek、通义千问等)
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>API Key</label>
|
||||
<input
|
||||
type="password"
|
||||
className="form-input"
|
||||
placeholder="sk-..."
|
||||
value={config.llm_api_key || ''}
|
||||
onChange={e => setConfig({ ...config, llm_api_key: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>API Base URL</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="https://api.openai.com/v1"
|
||||
value={config.llm_base_url || ''}
|
||||
onChange={e => setConfig({ ...config, llm_base_url: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>模型名称</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="gpt-4o-mini"
|
||||
value={config.llm_model || ''}
|
||||
onChange={e => setConfig({ ...config, llm_model: e.target.value })}
|
||||
/>
|
||||
<div style={{ fontSize: 11, color: 'var(--text-secondary)', marginTop: 4 }}>
|
||||
常用模型: gpt-4o-mini, gpt-4o, deepseek-chat, qwen-turbo, llama3
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 10 }}>
|
||||
<button className="btn btn-primary" onClick={handleSaveConfig} disabled={saving}>
|
||||
<Save size={16} /> {saving ? '保存中...' : '保存配置'}
|
||||
</button>
|
||||
<button className="btn btn-secondary" onClick={handleTestLLM} disabled={testingLlm}>
|
||||
<Zap size={16} /> {testingLlm ? '测试中...' : '测试连接'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{llmStatus && (
|
||||
<div style={{
|
||||
marginTop: 16, padding: '12px 16px', borderRadius: 8, fontSize: 14,
|
||||
background: llmStatus.success ? '#f0fdf4' : '#fef2f2',
|
||||
color: llmStatus.success ? 'var(--success)' : 'var(--danger)',
|
||||
border: `1px solid ${llmStatus.success ? '#bbf7d0' : '#fecaca'}`
|
||||
}}>
|
||||
{llmStatus.message}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Category Management */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>🏷️ 分类管理</h3>
|
||||
<button className="btn btn-secondary btn-sm" onClick={loadAll}>
|
||||
<RefreshCw size={14} /> 刷新
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style={{ fontSize: 13, color: 'var(--text-secondary)', marginBottom: 16 }}>
|
||||
管理交易分类及其关键词,AI会根据关键词进行自动分类
|
||||
</div>
|
||||
|
||||
<div className="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={{ width: 60 }}>ID</th>
|
||||
<th>分类名称</th>
|
||||
<th>关键词(逗号分隔)</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{categories.map(cat => (
|
||||
<tr key={cat.id}>
|
||||
<td>{cat.id}</td>
|
||||
<td>
|
||||
{editingCat?.id === cat.id ? (
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
style={{ width: 120 }}
|
||||
value={editingCat.name}
|
||||
onChange={e => setEditingCat({ ...editingCat, name: e.target.value })}
|
||||
/>
|
||||
) : (
|
||||
<strong>{cat.name}</strong>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{editingCat?.id === cat.id ? (
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
style={{ width: '100%' }}
|
||||
value={editingCat.keywords}
|
||||
onChange={e => setEditingCat({ ...editingCat, keywords: e.target.value })}
|
||||
/>
|
||||
) : (
|
||||
<span style={{ fontSize: 12, color: 'var(--text-secondary)' }}>
|
||||
{JSON.parse(cat.keywords || '[]').join(', ') || '(无关键词)'}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{editingCat?.id === cat.id ? (
|
||||
<div style={{ display: 'flex', gap: 6 }}>
|
||||
<button className="btn btn-primary btn-sm" onClick={async () => {
|
||||
const keywords = editingCat.keywords.split(',').map(k => k.trim()).filter(Boolean);
|
||||
await handleUpdateCategory(cat.id, 'name', editingCat.name);
|
||||
await handleUpdateCategory(cat.id, 'keywords', keywords);
|
||||
setEditingCat(null);
|
||||
}}>
|
||||
<Save size={12} /> 保存
|
||||
</button>
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => setEditingCat(null)}>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => setEditingCat({
|
||||
...cat,
|
||||
keywords: JSON.parse(cat.keywords || '[]').join(', ')
|
||||
})}>
|
||||
编辑
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* About */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>📦 关于 Reco</h3>
|
||||
</div>
|
||||
<div style={{ fontSize: 14, color: 'var(--text-secondary)', lineHeight: 1.8 }}>
|
||||
<p><strong>Reco</strong> —— 银行流水对账分析系统 v1.0.0</p>
|
||||
<p>🏦 支持支付宝、微信支付、银行卡、信用卡账单导入</p>
|
||||
<p>🔗 自动匹配跨来源的同一笔交易,实现智能对账</p>
|
||||
<p>🤖 集成大模型能力,自动分类和描述每一笔交易</p>
|
||||
<p>✅ 大额交易确认机制,确保重要交易准确无误</p>
|
||||
<p style={{ marginTop: 12, fontSize: 12 }}>
|
||||
数据存储位置:<code>data/reco.db</code>(SQLite 本地数据库)
|
||||
</p>
|
||||
<p style={{ fontSize: 12 }}>
|
||||
数据完全保存在本地,不会上传到任何服务器
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Search, Filter, RotateCcw, RefreshCw, Link2, Brain, ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
import { getTransactions, updateTransaction, runReconciliation, classifyAll, formatAmount, formatDate, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
|
||||
|
||||
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'
|
||||
});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [categories, setCategories] = useState([]);
|
||||
const [editingTx, setEditingTx] = useState(null);
|
||||
const [reconciling, setReconciling] = useState(false);
|
||||
const [classifying, setClassifying] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadCategories();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
loadTransactions();
|
||||
}, [filters]);
|
||||
|
||||
async function loadCategories() {
|
||||
try {
|
||||
const cats = await getCategories();
|
||||
setCategories(cats);
|
||||
} 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);
|
||||
} catch (err) {}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
function updateFilter(key, value) {
|
||||
setFilters(prev => ({ ...prev, [key]: value, page: key === 'page' ? value : 1 }));
|
||||
}
|
||||
|
||||
async function handleReconcile() {
|
||||
setReconciling(true);
|
||||
try {
|
||||
const result = await runReconciliation();
|
||||
alert(`对账完成!成功匹配 ${result.matched} 对交易(共检查 ${result.total} 笔)`);
|
||||
loadTransactions();
|
||||
} catch (err) {}
|
||||
setReconciling(false);
|
||||
}
|
||||
|
||||
async function handleClassifyAll() {
|
||||
setClassifying(true);
|
||||
try {
|
||||
const result = await classifyAll();
|
||||
alert(`分类完成!共分类 ${result.classified} 笔交易`);
|
||||
loadTransactions();
|
||||
} catch (err) {}
|
||||
setClassifying(false);
|
||||
}
|
||||
|
||||
async function handleUpdateTx(id, updates) {
|
||||
try {
|
||||
await updateTransaction(id, updates);
|
||||
setEditingTx(null);
|
||||
loadTransactions();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
function openEdit(tx) {
|
||||
setEditingTx({ ...tx });
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h2>📋 交易明细</h2>
|
||||
<p>查看、筛选、对账和分类所有交易记录</p>
|
||||
</div>
|
||||
|
||||
{/* Action Bar */}
|
||||
<div style={{ display: 'flex', gap: 10, marginBottom: 20, flexWrap: 'wrap' }}>
|
||||
<button className="btn btn-primary" onClick={handleReconcile} disabled={reconciling}>
|
||||
<Link2 size={16} /> {reconciling ? '对账中...' : '自动对账'}
|
||||
</button>
|
||||
<button className="btn btn-secondary" onClick={handleClassifyAll} disabled={classifying}>
|
||||
<Brain size={16} /> {classifying ? '分类中...' : 'AI 分类全部'}
|
||||
</button>
|
||||
<button className="btn btn-secondary" onClick={() => { setFilters({ page: 1, limit: 50, start_date: '', end_date: '', source_type: '', direction: '', category: '', reviewed: '', min_amount: '', keyword: '', sort_by: 'transaction_date', sort_order: 'DESC' }); }}>
|
||||
<RotateCcw size={16} /> 重置筛选
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Filter Bar */}
|
||||
<div className="card" style={{ padding: '16px 20px' }}>
|
||||
<div className="filter-bar">
|
||||
<div className="form-group">
|
||||
<label>开始日期</label>
|
||||
<input type="date" className="form-input" value={filters.start_date} onChange={e => updateFilter('start_date', e.target.value)} />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>结束日期</label>
|
||||
<input type="date" className="form-input" value={filters.end_date} onChange={e => updateFilter('end_date', e.target.value)} />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>来源</label>
|
||||
<select className="form-select" value={filters.source_type} onChange={e => updateFilter('source_type', e.target.value)}>
|
||||
<option value="">全部</option>
|
||||
{Object.entries(SOURCE_TYPE_MAP).map(([k, v]) => (
|
||||
<option key={k} value={k}>{v}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>方向</label>
|
||||
<select className="form-select" value={filters.direction} onChange={e => updateFilter('direction', e.target.value)}>
|
||||
<option value="">全部</option>
|
||||
<option value="income">收入</option>
|
||||
<option value="expense">支出</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>分类</label>
|
||||
<select className="form-select" value={filters.category} onChange={e => updateFilter('category', e.target.value)}>
|
||||
<option value="">全部</option>
|
||||
{categories.map(c => (
|
||||
<option key={c.id} value={c.name}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>确认状态</label>
|
||||
<select className="form-select" value={filters.reviewed} onChange={e => updateFilter('reviewed', e.target.value)}>
|
||||
<option value="">全部</option>
|
||||
<option value="0">未确认</option>
|
||||
<option value="1">已确认</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>关键词</label>
|
||||
<input type="text" className="form-input" placeholder="搜索对方/描述..." value={filters.keyword} onChange={e => updateFilter('keyword', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Transaction Table */}
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3>共 {data.total} 笔交易</h3>
|
||||
<span style={{ fontSize: 13, color: 'var(--text-secondary)' }}>
|
||||
第 {data.page}/{data.totalPages} 页
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="loading"><div className="spinner"></div>加载中...</div>
|
||||
) : data.transactions.length > 0 ? (
|
||||
<>
|
||||
<div className="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>交易编码</th>
|
||||
<th>日期</th>
|
||||
<th>来源</th>
|
||||
<th>对方</th>
|
||||
<th>描述</th>
|
||||
<th>分类</th>
|
||||
<th style={{ textAlign: 'right' }}>金额</th>
|
||||
<th>方向</th>
|
||||
<th>匹配</th>
|
||||
<th>确认</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.transactions.map(tx => (
|
||||
<tr key={tx.id}>
|
||||
<td style={{ fontFamily: 'monospace', fontSize: 11, color: 'var(--text-secondary)' }}>
|
||||
{tx.transaction_code}
|
||||
</td>
|
||||
<td>{formatDate(tx.transaction_date)}</td>
|
||||
<td>
|
||||
<span className={`source-type-label source-${tx.source_type}`}>
|
||||
{SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
|
||||
</span>
|
||||
</td>
|
||||
<td>{tx.counterparty || '--'}</td>
|
||||
<td style={{ maxWidth: 150, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{tx.ai_description || tx.description || '--'}
|
||||
</td>
|
||||
<td>
|
||||
{tx.category ? (
|
||||
<span className="tag tag-matched">{tx.category}</span>
|
||||
) : (
|
||||
<span style={{ color: 'var(--text-secondary)', fontSize: 11 }}>未分类</span>
|
||||
)}
|
||||
</td>
|
||||
<td style={{ textAlign: 'right', fontWeight: 600 }} className={tx.direction === 'income' ? 'stat-value income' : 'stat-value expense'}>
|
||||
{formatAmount(tx.amount)}
|
||||
</td>
|
||||
<td>
|
||||
<span className={`tag ${tx.direction === 'income' ? 'tag-income' : 'tag-expense'}`}>
|
||||
{tx.direction === 'income' ? '收入' : '支出'}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
{tx.matched_transaction_id ? (
|
||||
<span className="tag tag-matched" title={`匹配得分: ${tx.match_score}`}>已对账</span>
|
||||
) : <span style={{ fontSize: 11, color: 'var(--text-secondary)' }}>--</span>}
|
||||
</td>
|
||||
<td>
|
||||
{tx.reviewed ? (
|
||||
<span style={{ color: 'var(--success)', fontSize: 11 }}>✓ 已确认</span>
|
||||
) : (
|
||||
<span className="tag tag-unreviewed">待确认</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => openEdit(tx)}>
|
||||
编辑
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{data.totalPages > 1 && (
|
||||
<div className="pagination">
|
||||
<button disabled={data.page <= 1} onClick={() => updateFilter('page', data.page - 1)}>
|
||||
<ChevronLeft size={14} /> 上一页
|
||||
</button>
|
||||
{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 (
|
||||
<button key={pageNum} className={data.page === pageNum ? 'active' : ''}
|
||||
onClick={() => updateFilter('page', pageNum)}>
|
||||
{pageNum}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
<button disabled={data.page >= data.totalPages} onClick={() => updateFilter('page', data.page + 1)}>
|
||||
下一页 <ChevronRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">📭</div>
|
||||
<p>没有找到交易记录</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Edit Modal */}
|
||||
{editingTx && (
|
||||
<div className="modal-overlay" onClick={() => setEditingTx(null)}>
|
||||
<div className="modal" onClick={e => e.stopPropagation()}>
|
||||
<h3>编辑交易</h3>
|
||||
<div style={{ marginBottom: 12, fontSize: 13, color: 'var(--text-secondary)' }}>
|
||||
{editingTx.transaction_code} | {formatDate(editingTx.transaction_date)}
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>分类</label>
|
||||
<select className="form-select" value={editingTx.category || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, category: e.target.value })}>
|
||||
<option value="">选择分类</option>
|
||||
{categories.map(c => (
|
||||
<option key={c.id} value={c.name}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>AI描述</label>
|
||||
<input type="text" className="form-input" value={editingTx.ai_description || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, ai_description: e.target.value })} />
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>确认状态</label>
|
||||
<select className="form-select" value={editingTx.reviewed || 0}
|
||||
onChange={e => setEditingTx({ ...editingTx, reviewed: parseInt(e.target.value) })}>
|
||||
<option value={0}>未确认</option>
|
||||
<option value={1}>已确认</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 10, justifyContent: 'flex-end', marginTop: 20 }}>
|
||||
<button className="btn btn-secondary" onClick={() => setEditingTx(null)}>取消</button>
|
||||
<button className="btn btn-primary" onClick={() => handleUpdateTx(editingTx.id, {
|
||||
category: editingTx.category,
|
||||
ai_description: editingTx.ai_description,
|
||||
reviewed: editingTx.reviewed
|
||||
})}>保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user