@@ -14,14 +14,24 @@ import {
14
14
import dayjs from 'dayjs' ;
15
15
16
16
const authStorageKey = 'tushan:auth' ;
17
+ const PRICE_SCALE = 100000 ;
17
18
18
- type UsersChartDataType = { count : number ; date : string ; increase : number ; increaseRate : string } ;
19
+ type fetchChatData = { count : number ; date : string ; increase ?: number ; increaseRate ?: string } ;
20
+
21
+ type chatDataType = {
22
+ date : string ;
23
+ userCount : number ;
24
+ userIncrease ?: number ;
25
+ userIncreaseRate ?: string ;
26
+ payCount : number ;
27
+ } ;
19
28
20
29
export const Dashboard : React . FC = React . memo ( ( ) => {
21
30
const [ userCount , setUserCount ] = useState ( 0 ) ; //用户数量
22
31
const [ kbCount , setkbCount ] = useState ( 0 ) ;
23
32
const [ modelCount , setmodelCount ] = useState ( 0 ) ;
24
- const [ usersData , setUsersData ] = useState < UsersChartDataType [ ] > ( [ ] ) ;
33
+
34
+ const [ chatData , setChatData ] = useState < chatDataType [ ] > ( [ ] ) ;
25
35
26
36
useEffect ( ( ) => {
27
37
const baseUrl = import . meta. env . VITE_PUBLIC_SERVER_URL ;
@@ -56,20 +66,29 @@ export const Dashboard: React.FC = React.memo(() => {
56
66
setmodelCount ( Number ( modelTotalCount ) ) ;
57
67
}
58
68
} ;
59
- const fetchUserData = async ( ) => {
60
- const userResponse : UsersChartDataType [ ] = await fetch ( `${ baseUrl } /users/data` , {
61
- headers
62
- } ) . then ( ( res ) => res . json ( ) ) ;
63
- setUsersData (
64
- userResponse . map ( ( item ) => ( {
65
- ...item ,
66
- date : dayjs ( item . date ) . format ( 'MM/DD' )
67
- } ) )
68
- ) ;
69
+
70
+ const fetchChatData = async ( ) => {
71
+ const [ userResponse , payResponse ] : fetchChatData [ ] [ ] = await Promise . all ( [
72
+ fetch ( `${ baseUrl } /users/data` , {
73
+ headers
74
+ } ) . then ( ( res ) => res . json ( ) ) ,
75
+ fetch ( `${ baseUrl } /pays/data` , {
76
+ headers
77
+ } ) . then ( ( res ) => res . json ( ) )
78
+ ] ) ;
79
+
80
+ const data = userResponse . map ( ( item , i ) => ( {
81
+ date : dayjs ( item . date ) . format ( 'MM/DD' ) ,
82
+ userCount : item . count ,
83
+ userIncrease : item . increase ,
84
+ userIncreaseRate : item . increaseRate ,
85
+ payCount : payResponse [ i ] . count / PRICE_SCALE
86
+ } ) ) ;
87
+ setChatData ( data ) ;
69
88
} ;
70
89
71
90
fetchCounts ( ) ;
72
- fetchUserData ( ) ;
91
+ fetchChatData ( ) ;
73
92
} , [ ] ) ;
74
93
75
94
return (
@@ -101,7 +120,13 @@ export const Dashboard: React.FC = React.memo(() => {
101
120
</ Grid . Row >
102
121
103
122
< Divider />
104
- < UserChart data = { usersData } />
123
+
124
+ < div >
125
+ < strong > 用户数量 & 支付情况 </ strong >
126
+ < UserChart data = { chatData } />
127
+ </ div >
128
+
129
+ < Divider />
105
130
</ Card >
106
131
</ Space >
107
132
</ div >
@@ -162,7 +187,7 @@ const DataItem = React.memo((props: { icon: React.ReactElement; title: string; c
162
187
DataItem . displayName = 'DataItem' ;
163
188
164
189
const CustomTooltip = ( { active, payload } : any ) => {
165
- const data = payload ?. [ 0 ] ?. payload as UsersChartDataType ;
190
+ const data = payload ?. [ 0 ] ?. payload as chatDataType ;
166
191
if ( active && data ) {
167
192
return (
168
193
< div
@@ -174,21 +199,24 @@ const CustomTooltip = ({ active, payload }: any) => {
174
199
} }
175
200
>
176
201
< p className = "label" >
177
- count: < strong > { data . count } </ strong >
202
+ 用户总数: < strong > { data . userCount } </ strong >
203
+ </ p >
204
+ < p className = "label" >
205
+ 60天累计支付: < strong > { data . payCount } </ strong > 元
178
206
</ p >
179
207
< p className = "label" >
180
- increase : < strong > { data . increase } </ strong >
208
+ 用户昨日增长数量 : < strong > { data . userIncrease } </ strong >
181
209
</ p >
182
210
< p className = "label" >
183
- increaseRate : < strong > { data . increaseRate } </ strong >
211
+ 用户昨日增长比例 : < strong > { data . userIncreaseRate } </ strong >
184
212
</ p >
185
213
</ div >
186
214
) ;
187
215
}
188
216
return null ;
189
217
} ;
190
218
191
- const UserChart = ( { data } : { data : UsersChartDataType [ ] } ) => {
219
+ const UserChart = ( { data } : { data : chatDataType [ ] } ) => {
192
220
return (
193
221
< ResponsiveContainer width = "100%" height = { 320 } >
194
222
< AreaChart
@@ -198,25 +226,32 @@ const UserChart = ({ data }: { data: UsersChartDataType[] }) => {
198
226
margin = { { top : 10 , right : 30 , left : 0 , bottom : 0 } }
199
227
>
200
228
< defs >
201
- < linearGradient id = "colorUv" x1 = "0" y1 = "0" x2 = "0" y2 = "1" >
202
- < stop offset = "5%" stopColor = "#8884d8" stopOpacity = { 0.8 } />
203
- < stop offset = "95%" stopColor = "#8884d8" stopOpacity = { 0 } />
204
- </ linearGradient >
205
- < linearGradient id = "colorPv" x1 = "0" y1 = "0" x2 = "0" y2 = "1" >
229
+ < linearGradient id = "userCount" x1 = "0" y1 = "0" x2 = "0" y2 = "1" >
206
230
< stop offset = "5%" stopColor = "#82ca9d" stopOpacity = { 0.8 } />
207
231
< stop offset = "95%" stopColor = "#82ca9d" stopOpacity = { 0 } />
208
232
</ linearGradient >
233
+ < linearGradient id = "payCount" x1 = "0" y1 = "0" x2 = "0" y2 = "1" >
234
+ < stop offset = "5%" stopColor = "#8884d8" stopOpacity = { 0.8 } />
235
+ < stop offset = "95%" stopColor = "#8884d8" stopOpacity = { 0 } />
236
+ </ linearGradient >
209
237
</ defs >
210
238
< XAxis dataKey = "date" />
211
239
< YAxis />
212
240
< CartesianGrid strokeDasharray = "3 3" />
213
241
< Tooltip content = { < CustomTooltip /> } />
214
242
< Area
215
243
type = "monotone"
216
- dataKey = "count "
244
+ dataKey = "userCount "
217
245
stroke = "#82ca9d"
218
246
fillOpacity = { 1 }
219
- fill = "url(#colorPv)"
247
+ fill = "url(#userCount)"
248
+ />
249
+ < Area
250
+ type = "monotone"
251
+ dataKey = "payCount"
252
+ stroke = "#8884d8"
253
+ fillOpacity = { 1 }
254
+ fill = "url(#payCount)"
220
255
/>
221
256
</ AreaChart >
222
257
</ ResponsiveContainer >
0 commit comments