Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
ed42bb6c
authored
Jul 17, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: charts
parent
246283ee
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
17 deletions
+33
-17
client/src/api/app.ts
+2
-2
client/src/pages/api/app/data/totalUsage.ts
+19
-3
client/src/pages/app/detail/components/Charts/TotalUsage.tsx
+2
-2
client/src/pages/app/detail/components/Settings.tsx
+4
-4
client/src/pages/number/components/BillTable.tsx
+0
-2
client/src/pages/number/index.tsx
+6
-4
No files found.
client/src/api/app.ts
View file @
ed42bb6c
...
@@ -48,6 +48,6 @@ export const triggerModelCollection = (appId: string) =>
...
@@ -48,6 +48,6 @@ export const triggerModelCollection = (appId: string) =>
export
const
getAppTotalUsage
=
(
data
:
{
appId
:
string
})
=>
export
const
getAppTotalUsage
=
(
data
:
{
appId
:
string
})
=>
POST
<
{
total
:
number
;
date
:
Date
}[]
>
(
`/app/data/totalUsage`
,
{
POST
<
{
total
:
number
;
date
:
Date
}[]
>
(
`/app/data/totalUsage`
,
{
...
data
,
...
data
,
start
:
addDays
(
new
Date
(),
-
7
),
start
:
addDays
(
new
Date
(),
-
13
).
setHours
(
0
,
0
,
0
,
0
),
end
:
new
Date
(
)
end
:
addDays
(
new
Date
(),
1
).
setHours
(
0
,
0
,
0
,
0
)
});
});
client/src/pages/api/app/data/totalUsage.ts
View file @
ed42bb6c
...
@@ -3,11 +3,27 @@ import { jsonRes } from '@/service/response';
...
@@ -3,11 +3,27 @@ import { jsonRes } from '@/service/response';
import
{
connectToDatabase
,
Bill
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
Bill
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
Types
}
from
'mongoose'
;
import
{
Types
}
from
'mongoose'
;
import
dayjs
from
'dayjs'
;
import
{
addDays
,
isSameDay
}
from
'date-fns'
;
const
fillMissingDates
=
(
start
:
number
,
end
:
number
,
data
:
{
date
:
Date
;
total
:
number
}[])
=>
{
const
result
:
{
date
:
Date
;
total
:
number
}[]
=
[];
const
dayStart
=
dayjs
(
start
);
const
dayEnd
=
dayjs
(
end
);
const
diff
=
+
dayEnd
.
diff
(
dayStart
,
'day'
);
for
(
let
i
=
0
;
i
<
diff
;
i
++
)
{
const
date
=
addDays
(
start
,
i
);
const
dataItem
=
data
.
find
((
item
)
=>
isSameDay
(
date
,
item
.
date
));
result
[
i
]
=
{
date
,
total
:
dataItem
?.
total
||
0
};
}
return
result
;
};
/* get one app chat history content number. */
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
try
{
try
{
const
{
appId
,
start
,
end
}
=
req
.
body
as
{
appId
:
string
;
start
:
Date
;
end
:
Date
};
const
{
appId
,
start
,
end
}
=
req
.
body
as
{
appId
:
string
;
start
:
number
;
end
:
number
};
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
await
connectToDatabase
();
await
connectToDatabase
();
...
@@ -41,7 +57,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -41,7 +57,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
]);
]);
jsonRes
(
res
,
{
jsonRes
(
res
,
{
data
:
result
data
:
fillMissingDates
(
start
,
end
,
result
)
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
...
...
client/src/pages/app/detail/components/Charts/TotalUsage.tsx
View file @
ed42bb6c
...
@@ -113,7 +113,7 @@ const TokenUsage = ({ appId }: { appId: string }) => {
...
@@ -113,7 +113,7 @@ const TokenUsage = ({ appId }: { appId: string }) => {
},
},
yAxis
:
{
yAxis
:
{
type
:
'value'
,
type
:
'value'
,
max
:
Math
.
max
(...
data
.
map
((
item
)
=>
item
.
total
))
,
splitNumber
:
3
,
min
:
0
min
:
0
},
},
grid
:
{
grid
:
{
...
@@ -145,7 +145,7 @@ const TokenUsage = ({ appId }: { appId: string }) => {
...
@@ -145,7 +145,7 @@ const TokenUsage = ({ appId }: { appId: string }) => {
data: data.map((item) => item.total),
data: data.map((item) => item.total),
type: 'line',
type: 'line',
showSymbol: true,
showSymbol: true,
animationDuration:
3
00,
animationDuration:
10
00,
animationEasingUpdate: 'linear',
animationEasingUpdate: 'linear',
areaStyle: {
areaStyle: {
color: map['blue'].backgroundColor
color: map['blue'].backgroundColor
...
...
client/src/pages/app/detail/components/Settings.tsx
View file @
ed42bb6c
import
React
,
{
useCallback
,
useState
,
useMemo
}
from
'react'
;
import
React
,
{
useCallback
,
useState
}
from
'react'
;
import
{
Box
,
Flex
,
Button
,
Grid
,
useTheme
,
BoxProps
,
IconButton
}
from
'@chakra-ui/react'
;
import
{
Box
,
Flex
,
Button
,
Grid
,
useTheme
,
IconButton
}
from
'@chakra-ui/react'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
{
useUserStore
}
from
'@/store/user'
;
...
@@ -12,10 +12,10 @@ import { AppSchema } from '@/types/mongoSchema';
...
@@ -12,10 +12,10 @@ import { AppSchema } from '@/types/mongoSchema';
import
Avatar
from
'@/components/Avatar'
;
import
Avatar
from
'@/components/Avatar'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
import
TotalUsage
from
'./Charts/TotalUsage'
;
const
InfoModal
=
dynamic
(()
=>
import
(
'./InfoModal'
));
const
InfoModal
=
dynamic
(()
=>
import
(
'./InfoModal'
));
const
TotalUsage
=
dynamic
(()
=>
import
(
'./Charts/TotalUsage'
),
{
ssr
:
false
});
const
AppEdit
=
dynamic
(()
=>
import
(
'./edit'
),
{
ssr
:
true
});
const
AppEdit
=
dynamic
(()
=>
import
(
'./edit'
),
{
ssr
:
false
});
import
styles
from
'../../list/index.module.scss'
;
import
styles
from
'../../list/index.module.scss'
;
const
Settings
=
({
appId
}:
{
appId
:
string
})
=>
{
const
Settings
=
({
appId
}:
{
appId
:
string
})
=>
{
...
...
client/src/pages/number/components/BillTable.tsx
View file @
ed42bb6c
...
@@ -21,8 +21,6 @@ const BillTable = () => {
...
@@ -21,8 +21,6 @@ const BillTable = () => {
data
:
bills
,
data
:
bills
,
isLoading
,
isLoading
,
Pagination
,
Pagination
,
pageSize
,
total
,
getData
getData
}
=
usePagination
<
UserBillType
>
({
}
=
usePagination
<
UserBillType
>
({
api
:
getUserBills
,
api
:
getUserBills
,
...
...
client/src/pages/number/index.tsx
View file @
ed42bb6c
...
@@ -278,10 +278,12 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -278,10 +278,12 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
);
);
};
};
export
default
NumberSetting
;
export
async
function
getServerSideProps
({
query
}:
any
)
{
NumberSetting
.
getInitialProps
=
({
query
,
req
}:
any
)
=>
{
return
{
return
{
props
:
{
tableType
:
query
?.
type
||
TableEnum
.
bill
tableType
:
query
?.
type
||
TableEnum
.
bill
}
};
};
};
}
export
default
NumberSetting
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment