Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14,975 changes: 9,174 additions & 5,801 deletions package-lock.json

Large diffs are not rendered by default.

204 changes: 204 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,207 @@ input[type='number'] {
width: 300px;
}
}

select {
border: 1px solid #dedede;
border-radius: 2px;
display: block;
font-size: 16px;
padding: 10px;
width: 100%;
background-color: #fff;
cursor: pointer;
}

input[type='date'] {
border: 1px solid #dedede;
border-radius: 2px;
display: block;
font-size: 16px;
padding: 10px;
width: 100%;
}

.list li {
background-color: #fff;
box-shadow: var(--box-shadow);
color: #333;
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
padding: 10px;
margin: 10px 0;
}

.transaction-info {
display: flex;
flex-direction: column;
flex: 1;
}

.transaction-text {
font-weight: bold;
margin-bottom: 4px;
}

.transaction-meta {
display: flex;
gap: 10px;
font-size: 12px;
color: #777;
}

.transaction-category {
background-color: #f0f0f0;
padding: 2px 6px;
border-radius: 4px;
}

.transaction-amount {
font-weight: bold;
margin-left: 10px;
}

.monthly-stats-container {
background-color: #fff;
box-shadow: var(--box-shadow);
padding: 20px;
margin: 20px 0;
border-radius: 4px;
}

.month-selector {
margin-bottom: 20px;
}

.month-selector label {
display: inline-block;
margin-right: 10px;
font-weight: bold;
}

.month-selector select {
display: inline-block;
width: auto;
min-width: 150px;
}

.stats-summary {
display: flex;
justify-content: space-between;
gap: 15px;
margin-bottom: 25px;
}

.stat-card {
flex: 1;
text-align: center;
padding: 15px;
border-radius: 4px;
}

.stat-card h4 {
margin: 0 0 8px 0;
font-size: 14px;
color: #666;
}

.stat-value {
font-size: 20px;
font-weight: bold;
margin: 0;
}

.stat-card.income {
background-color: rgba(46, 204, 113, 0.1);
border-left: 3px solid #2ecc71;
}

.stat-card.expense {
background-color: rgba(192, 57, 43, 0.1);
border-left: 3px solid #c0392b;
}

.stat-card.balance {
background-color: rgba(156, 136, 255, 0.1);
border-left: 3px solid #9c88ff;
}

.category-stats {
margin-top: 20px;
}

.category-stats h4 {
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 1px solid #eee;
}

.category-list {
display: flex;
flex-direction: column;
gap: 15px;
}

.category-item {
display: flex;
flex-direction: column;
gap: 8px;
}

.category-header {
display: flex;
justify-content: space-between;
align-items: center;
}

.category-name {
font-weight: bold;
font-size: 14px;
}

.category-amount {
font-size: 14px;
color: #666;
}

.progress-bar-container {
position: relative;
height: 20px;
background-color: #f0f0f0;
border-radius: 10px;
overflow: hidden;
}

.progress-bar {
height: 100%;
border-radius: 10px;
transition: width 0.3s ease;
}

.progress-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 12px;
font-weight: bold;
color: #333;
}

.no-data {
text-align: center;
color: #999;
font-style: italic;
padding: 20px;
}

.transaction-count {
margin-top: 20px;
padding-top: 15px;
border-top: 1px solid #eee;
text-align: center;
color: #666;
font-size: 14px;
}
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Balance } from './components/Balance';
import { IncomeExpenses } from './components/IncomeExpenses';
import { TransactionList } from './components/TransactionList';
import { AddTransaction } from './components/AddTransaction';
import { MonthlyStats } from './components/MonthlyStats';

import { GlobalProvider } from './context/GlobalState';

Expand All @@ -14,6 +15,7 @@ function App() {
<GlobalProvider>
<Header />
<div className="container">
<MonthlyStats />
<Balance />
<IncomeExpenses />
<TransactionList />
Expand Down
60 changes: 56 additions & 4 deletions src/components/AddTransaction.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,90 @@
import React, {useState, useContext} from 'react'
import { GlobalContext } from '../context/GlobalState';

const expenseCategories = ['餐饮', '住房', '交通', '购物', '娱乐', '其他'];
const incomeCategories = ['收入'];

export const AddTransaction = () => {
const [text, setText] = useState('');
const [amount, setAmount] = useState(0);
const [category, setCategory] = useState('餐饮');
const [date, setDate] = useState(new Date().toISOString().split('T')[0]);

const { addTransaction } = useContext(GlobalContext);

const handleAmountChange = (e) => {
const value = +e.target.value;
setAmount(value);
if (value > 0) {
setCategory('收入');
} else if (value < 0) {
setCategory('餐饮');
}
};

const onSubmit = e => {
e.preventDefault();

if (!text.trim()) {
alert('请输入交易描述');
return;
}

if (amount === 0) {
alert('请输入有效金额');
return;
}

const newTransaction = {
id: Math.floor(Math.random() * 100000000),
text,
amount: +amount
amount: +amount,
category,
date
}

addTransaction(newTransaction);

setText('');
setAmount(0);
setCategory('餐饮');
}

const availableCategories = amount > 0 ? incomeCategories : expenseCategories;

return (
<>
<h3>Add new transaction</h3>
<form onSubmit={onSubmit}>
<div className="form-control">
<label htmlFor="text">Text</label>
<input type="text" value={text} onChange={(e) => setText(e.target.value)} placeholder="Enter text..." />
<label htmlFor="text">Description</label>
<input type="text" value={text} onChange={(e) => setText(e.target.value)} placeholder="Enter description..." />
</div>
<div className="form-control">
<label htmlFor="amount"
>Amount <br />
(negative - expense, positive - income)</label
>
<input type="number" value={amount} onChange={(e) => setAmount(e.target.value)} placeholder="Enter amount..." />
<input type="number" value={amount} onChange={handleAmountChange} placeholder="Enter amount..." />
</div>
<div className="form-control">
<label htmlFor="category">Category</label>
<select
value={category}
onChange={(e) => setCategory(e.target.value)}
>
{availableCategories.map(cat => (
<option key={cat} value={cat}>{cat}</option>
))}
</select>
</div>
<div className="form-control">
<label htmlFor="date">Date</label>
<input
type="date"
value={date}
onChange={(e) => setDate(e.target.value)}
/>
</div>
<button className="btn">Add transaction</button>
</form>
Expand Down
Loading