From f362ba25896dea273eed893147cc37b84edd46ec Mon Sep 17 00:00:00 2001
From: archer <545436317@qq.com>
Date: Thu, 20 Jul 2023 21:15:20 +0800
Subject: [PATCH] perf: date and warning
---
client/src/api/app.ts | 8 ++++----
client/src/pages/api/app/data/totalUsage.ts | 19 +------------------
client/src/pages/api/openapi/plugin/vector.ts | 6 ++++++
.../detail/components/Charts/TotalUsage.tsx | 8 ++++++--
.../pages/app/detail/components/InfoModal.tsx | 6 +++---
.../pages/app/detail/components/Settings.tsx | 8 +++-----
.../src/pages/number/components/BillTable.tsx | 4 ++--
7 files changed, 25 insertions(+), 34 deletions(-)
diff --git a/client/src/api/app.ts b/client/src/api/app.ts
index d54e6daa1..324f3932b 100644
--- a/client/src/api/app.ts
+++ b/client/src/api/app.ts
@@ -46,8 +46,8 @@ export const triggerModelCollection = (appId: string) =>
// ====================== data
export const getAppTotalUsage = (data: { appId: string }) =>
- POST<{ total: number; date: Date }[]>(`/app/data/totalUsage`, {
+ POST<{ date: Date; total: number }[]>(`/app/data/totalUsage`, {
...data,
- start: addDays(new Date(), -13).setHours(0, 0, 0, 0),
- end: addDays(new Date(), 1).setHours(0, 0, 0, 0)
- });
+ start: addDays(new Date(), -13),
+ end: addDays(new Date(), 1)
+ }).then((res) => (res.length === 0 ? [{ date: new Date(), total: 0 }] : res));
diff --git a/client/src/pages/api/app/data/totalUsage.ts b/client/src/pages/api/app/data/totalUsage.ts
index 97e68965c..b43cdda1c 100644
--- a/client/src/pages/api/app/data/totalUsage.ts
+++ b/client/src/pages/api/app/data/totalUsage.ts
@@ -3,23 +3,6 @@ import { jsonRes } from '@/service/response';
import { connectToDatabase, Bill } from '@/service/mongo';
import { authUser } from '@/service/utils/auth';
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;
-};
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
@@ -57,7 +40,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
]);
jsonRes(res, {
- data: fillMissingDates(start, end, result)
+ data: result
});
} catch (err) {
jsonRes(res, {
diff --git a/client/src/pages/api/openapi/plugin/vector.ts b/client/src/pages/api/openapi/plugin/vector.ts
index 29b592f08..bdcc7eee2 100644
--- a/client/src/pages/api/openapi/plugin/vector.ts
+++ b/client/src/pages/api/openapi/plugin/vector.ts
@@ -42,6 +42,12 @@ export async function getVector({
}: { userId?: string } & Props) {
userId && (await authBalanceByUid(userId));
+ for (let i = 0; i < input.length; i++) {
+ if (!input[i]) {
+ return Promise.reject('向量生成模块输入内容为空');
+ }
+ }
+
// 获取 chatAPI
const chatAPI = getOpenAIApi();
diff --git a/client/src/pages/app/detail/components/Charts/TotalUsage.tsx b/client/src/pages/app/detail/components/Charts/TotalUsage.tsx
index 8e6bb2ddc..05ce09b55 100644
--- a/client/src/pages/app/detail/components/Charts/TotalUsage.tsx
+++ b/client/src/pages/app/detail/components/Charts/TotalUsage.tsx
@@ -120,7 +120,7 @@ const TokenUsage = ({ appId }: { appId: string }) => {
show: false,
left: 5,
right: 5,
- top: 5,
+ top: 0,
bottom: 5
},
tooltip: {
@@ -173,6 +173,10 @@ const TokenUsage = ({ appId }: { appId: string }) => {
if (!Dom.current || myChart?.current?.getOption()) return;
myChart.current = echarts.init(Dom.current);
myChart.current && myChart.current.setOption(option);
+
+ setTimeout(() => {
+ myChart.current?.resize();
+ }, 500);
}, []);
// data changed, update
@@ -188,7 +192,7 @@ const TokenUsage = ({ appId }: { appId: string }) => {
}, [screenWidth]);
return (
-
+
);
diff --git a/client/src/pages/app/detail/components/InfoModal.tsx b/client/src/pages/app/detail/components/InfoModal.tsx
index 1840682b6..845c67a9d 100644
--- a/client/src/pages/app/detail/components/InfoModal.tsx
+++ b/client/src/pages/app/detail/components/InfoModal.tsx
@@ -146,12 +146,12 @@ const InfoModal = ({
>
-
+
应用介绍
-
+ {/*
该介绍主要用于记忆和在应用市场展示
-
+ */}
-
+
近 14 日消费
-
-
-
-
+
+
diff --git a/client/src/pages/number/components/BillTable.tsx b/client/src/pages/number/components/BillTable.tsx
index 68765876f..88b29c4cb 100644
--- a/client/src/pages/number/components/BillTable.tsx
+++ b/client/src/pages/number/components/BillTable.tsx
@@ -42,8 +42,8 @@ const BillTable = () => {
api: getUserBills,
pageSize: isPc ? 20 : 10,
params: {
- dateStart: new Date(dateRange.from || new Date()).setHours(0, 0, 0, 0),
- dateEnd: new Date(dateRange.to || new Date()).setHours(23, 59, 59, 999)
+ dateStart: dateRange.from || new Date(),
+ dateEnd: addDays(dateRange.to || new Date(), 1)
}
});