Skip to content

Commit 1d245c1

Browse files
committedDec 30, 2023
🍻 记账-收尾优化
1 parent 70b5304 commit 1d245c1

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed
 

‎day-04/react-bill-test/server/data.json

+14
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@
132132
"date": "2023-12-30T14:30:52.959Z",
133133
"useFor": "food",
134134
"id": 22
135+
},
136+
{
137+
"type": "pay",
138+
"money": -110,
139+
"date": "2023-12-23T16:00:00.000Z",
140+
"useFor": "food",
141+
"id": 23
142+
},
143+
{
144+
"type": "pay",
145+
"money": -110,
146+
"date": "2023-12-23T16:00:00.000Z",
147+
"useFor": "food",
148+
"id": 24
135149
}
136150
]
137151
}

‎day-04/react-bill-test/src/pages/New/index.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {useNavigate} from 'react-router-dom'
77
import {useState} from "react"
88
import {useDispatch} from "react-redux"
99
import {addBillList} from "@/store/modules/billStore"
10+
import dayjs from "dayjs"
1011

1112
const New = () => {
1213
const navigate = useNavigate()
@@ -30,12 +31,18 @@ const New = () => {
3031
const data = {
3132
type: billType,
3233
money: billType === 'pay' ? -money : +money,
33-
date: new Date(),
34+
date: date,
3435
useFor: useFor
3536
}
3637
dispatch(addBillList(data))
3738
}
3839

40+
// 选择的时间
41+
const [date, setDate] = useState(new Date())
42+
43+
// 控制时间打开关闭
44+
const [dateVisible, setDateVisible] = useState(false)
45+
3946
return (
4047
<div className="keepAccounts">
4148
<NavBar className="nav" onBack={() => navigate(-1)}>
@@ -63,12 +70,20 @@ const New = () => {
6370
<div className="kaFormWrapper">
6471
<div className="kaForm">
6572
<div className="date">
66-
<Icon type="calendar" className="icon" />
67-
<span className="text">{'今天'}</span>
73+
<Icon type="calendar" className="icon"/>
74+
<span
75+
className="text"
76+
onClick={() => setDateVisible(true)}
77+
>
78+
{dayjs(date).format('YYYY-MM-DD')}
79+
</span>
6880
<DatePicker
6981
className="kaDate"
7082
title="记账日期"
7183
max={new Date()}
84+
visible={dateVisible}
85+
onClose={() => setDateVisible(false)}
86+
onConfirm={(value) => setDate(value)}
7287
/>
7388
</div>
7489
<div className="kaInput">
@@ -96,7 +111,7 @@ const New = () => {
96111
<div
97112
className={classNames(
98113
'item',
99-
''
114+
useFor === item.type ? 'selected' : ''
100115
)}
101116
key={item.type}
102117
onClick={() => setUseFor(item.type)}

0 commit comments

Comments
 (0)
Please sign in to comment.