fix: bill, app detail

This commit is contained in:
archer
2023-07-19 08:36:06 +08:00
parent 58cbf10c85
commit 7a76f54148
12 changed files with 64 additions and 42 deletions

View File

@@ -39,8 +39,12 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
const { kb_ids = [], userChatInput } = req.body as Props;
if (!userChatInput || !Array.isArray(kb_ids)) {
throw new Error('params is error');
if (!userChatInput) {
throw new Error('用户输入为空');
}
if (!Array.isArray(kb_ids) || kb_ids.length === 0) {
throw new Error('没有选择知识库');
}
const result = await kbSearch({

View File

@@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
_id: item._id,
shareId: item.shareId,
name: item.name,
tokens: item.tokens,
total: item.total,
maxContext: item.maxContext,
lastTime: item.lastTime
}))

View File

@@ -188,7 +188,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
// bill
finishTaskBill({
billId
billId,
shareId
});
} catch (err: any) {
delTaskBill(billId);

View File

@@ -51,17 +51,8 @@ const Settings = ({ appId }: { appId: string }) => {
}, [appDetail, setIsLoading, toast, router]);
// load app data
const { isLoading, refetch } = useQuery([appId], () => loadAppDetail(appId, true), {
onError(err: any) {
toast({
title: err?.message || '获取应用异常',
status: 'error'
});
router.replace('/app/list');
},
onSettled() {
router.prefetch(`/chat?appId=${appId}`);
}
const { refetch } = useQuery([appId], () => loadAppDetail(appId, true), {
enabled: false
});
return (
@@ -168,7 +159,7 @@ const Settings = ({ appId }: { appId: string }) => {
)}
<ConfirmChild />
<Loading loading={isLoading} fixed={false} />
<Loading fixed={false} />
</Flex>
);
};

View File

@@ -38,6 +38,7 @@ import { defaultShareChat } from '@/constants/model';
import type { ShareChatEditType } from '@/types/app';
import MyTooltip from '@/components/MyTooltip';
import { useRequest } from '@/hooks/useRequest';
import { formatPrice } from '@/utils/user';
const Share = ({ appId }: { appId: string }) => {
const { toast } = useToast();
@@ -82,12 +83,6 @@ const Share = ({ appId }: { appId: string }) => {
}
});
// format share used token
const formatTokens = (tokens: number) => {
if (tokens < 10000) return tokens;
return `${(tokens / 10000).toFixed(2)}`;
};
return (
<Box position={'relative'} pt={[0, 5, 8]} px={[5, 8]} minH={'50vh'}>
<Flex justifyContent={'space-between'}>
@@ -118,7 +113,7 @@ const Share = ({ appId }: { appId: string }) => {
<Tr>
<Th></Th>
<Th></Th>
<Th>tokens消</Th>
<Th></Th>
<Th>使</Th>
<Th></Th>
</Tr>
@@ -128,7 +123,7 @@ const Share = ({ appId }: { appId: string }) => {
<Tr key={item._id}>
<Td>{item.name}</Td>
<Td>{item.maxContext}</Td>
<Td>{formatTokens(item.tokens)}</Td>
<Td>{formatPrice(item.total)}</Td>
<Td>{item.lastTime ? formatTimeToChatTime(item.lastTime) : '未使用'}</Td>
<Td>
<Flex>

View File

@@ -4,6 +4,8 @@ import { Box, Flex, IconButton, useTheme } from '@chakra-ui/react';
import { useUserStore } from '@/store/user';
import dynamic from 'next/dynamic';
import { defaultApp } from '@/constants/model';
import { useToast } from '@/hooks/useToast';
import { useQuery } from '@tanstack/react-query';
import Tabs from '@/components/Tabs';
import SideTabs from '@/components/SideTabs';
@@ -28,8 +30,9 @@ enum TabEnum {
const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
const router = useRouter();
const theme = useTheme();
const { toast } = useToast();
const { appId } = router.query as { appId: string };
const { appDetail = defaultApp, clearAppModules } = useUserStore();
const { appDetail = defaultApp, loadAppDetail, clearAppModules } = useUserStore();
const setCurrentTab = useCallback(
(tab: `${TabEnum}`) => {
@@ -65,6 +68,19 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
};
}, []);
useQuery([appId], () => loadAppDetail(appId, true), {
onError(err: any) {
toast({
title: err?.message || '获取应用异常',
status: 'error'
});
router.replace('/app/list');
},
onSettled() {
router.prefetch(`/chat?appId=${appId}`);
}
});
return (
<PageContainer>
<Flex flexDirection={['column', 'row']} h={'100%'}>