Skip to content

Commit c61bfab

Browse files
committed
feat: 模型未配置,添加禁用功能, 修复对话记录滚动问题
1 parent 129a792 commit c61bfab

File tree

9 files changed

+223
-77
lines changed

9 files changed

+223
-77
lines changed

ui/src/components/sidebar/index.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Modal } from '@c-x/ui';
66
import { useMemo, useState } from 'react';
77
import Qrcode from '@/assets/images/qrcode.png';
88
import Version from './version';
9+
import { useCommonContext } from '@/hooks/context';
910

1011
const ADMIN_MENUS = [
1112
{
@@ -14,48 +15,55 @@ const ADMIN_MENUS = [
1415
pathname: 'dashboard',
1516
icon: 'icon-yibiaopan',
1617
show: true,
18+
disabled: false,
1719
},
1820
{
1921
label: '对话记录',
2022
value: '/chat',
2123
pathname: 'chat',
2224
icon: 'icon-duihuajilu1',
2325
show: true,
26+
disabled: false,
2427
},
2528
{
2629
label: '补全记录',
2730
value: '/completion',
2831
pathname: 'completion',
2932
icon: 'icon-buquanjilu',
3033
show: true,
34+
disabled: false,
3135
},
3236
{
3337
label: '代码安全',
3438
value: '/code-security',
3539
pathname: 'code-security',
3640
icon: 'icon-daimaanquan1',
3741
show: true,
42+
disabled: false,
3843
},
3944
{
4045
label: '模型管理',
4146
value: '/model',
4247
pathname: 'model',
4348
icon: 'icon-moxingguanli',
4449
show: true,
50+
disabled: false,
4551
},
4652
{
4753
label: '成员管理',
4854
value: '/user-management',
4955
pathname: 'user-management',
5056
icon: 'icon-yonghuguanli1',
5157
show: true,
58+
disabled: false,
5259
},
5360
{
5461
label: '管理员',
5562
value: '/admin',
5663
pathname: 'admin',
5764
icon: 'icon-guanliyuan1',
5865
show: true,
66+
disabled: false,
5967
},
6068
];
6169

@@ -66,20 +74,23 @@ const USER_MENUS = [
6674
pathname: '/user/dashboard',
6775
icon: 'icon-yibiaopan',
6876
show: true,
77+
disabled: false,
6978
},
7079
{
7180
label: '对话记录',
7281
value: '/user/chat',
7382
pathname: '/user/chat',
7483
icon: 'icon-duihuajilu1',
7584
show: true,
85+
disabled: false,
7686
},
7787
{
7888
label: '补全记录',
7989
value: '/user/completion',
8090
pathname: '/user/completion',
8191
icon: 'icon-buquanjilu',
8292
show: true,
93+
disabled: false,
8394
},
8495
// {
8596
// label: '设置',
@@ -111,12 +122,15 @@ const Sidebar = () => {
111122
const { pathname } = useLocation();
112123
const theme = useTheme();
113124
const [showQrcode, setShowQrcode] = useState(false);
125+
const { isConfigModel } = useCommonContext();
114126
const menus = useMemo(() => {
115127
if (pathname.startsWith('/user/')) {
116128
return USER_MENUS;
117129
}
118-
return ADMIN_MENUS;
119-
}, [pathname]);
130+
return isConfigModel
131+
? ADMIN_MENUS.map((item) => ({ ...item, disabled: false }))
132+
: ADMIN_MENUS.map((item) => ({ ...item, disabled: true }));
133+
}, [pathname, isConfigModel]);
120134

121135
return (
122136
<Stack
@@ -178,9 +192,15 @@ const Sidebar = () => {
178192
zIndex: isActive ? 2 : 1,
179193
color: isActive ? '#FFFFFF' : 'text.primary',
180194
}}
195+
onClick={(e) => {
196+
if (it.disabled) {
197+
e.preventDefault();
198+
}
199+
}}
181200
>
182201
<Button
183202
variant={isActive ? 'contained' : 'text'}
203+
disabled={it.pathname === 'model' ? false : it.disabled}
184204
sx={{
185205
width: '100%',
186206
height: 50,

ui/src/context/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createContext } from 'react';
2-
import { DomainUser, DomainAdminUser } from '@/api/types';
2+
import { DomainUser, DomainAdminUser, DomainModel } from '@/api/types';
33

44
export const AuthContext = createContext<
55
[
@@ -20,6 +20,13 @@ export const AuthContext = createContext<
2020
]);
2121

2222
export const CommonContext = createContext<{
23-
contactModalOpen: boolean;
24-
setContactModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
25-
}>({ contactModalOpen: false, setContactModalOpen: () => {} });
23+
coderModel: DomainModel[];
24+
llmModel: DomainModel[];
25+
isConfigModel: boolean;
26+
refreshModel: () => void;
27+
}>({
28+
coderModel: [],
29+
llmModel: [],
30+
isConfigModel: false,
31+
refreshModel: () => {},
32+
});

ui/src/main.tsx

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import '@/assets/styles/markdown.css';
99
import { ThemeProvider } from '@c-x/ui';
1010
import { getUserProfile } from '@/api/UserManage';
1111
import { getAdminProfile } from '@/api/Admin';
12+
import { getMyModelList } from '@/api/Model';
1213
import dayjs from 'dayjs';
1314
import duration from 'dayjs/plugin/duration';
1415
import relativeTime from 'dayjs/plugin/relativeTime';
15-
import { AuthContext } from './context';
16-
import { DomainUser, DomainAdminUser } from './api/types';
16+
import { AuthContext, CommonContext } from './context';
17+
import { DomainUser, DomainAdminUser, DomainModel } from './api/types';
1718
import { lightTheme } from './theme';
1819
import router from './router';
1920
import { getRedirectUrl } from './utils';
20-
import { Loading } from '@c-x/ui';
2121

2222
dayjs.locale('zh-cn');
2323
dayjs.extend(duration);
@@ -26,12 +26,56 @@ dayjs.extend(relativeTime);
2626
const App = () => {
2727
const [user, setUser] = useState<DomainUser | DomainAdminUser | null>(null);
2828
const [loading, setLoading] = useState(true);
29+
const [coderModel, setCoderModel] = useState<DomainModel[]>([]);
30+
const [llmModel, setLlmModel] = useState<DomainModel[]>([]);
31+
const [isConfigModel, setIsConfigModel] = useState(false);
2932

3033
const onGotoRedirect = (source: 'user' | 'admin') => {
3134
const redirectUrl = getRedirectUrl(source);
3235
window.location.href = redirectUrl.href;
3336
};
3437

38+
const getModelList = () => {
39+
return Promise.all([
40+
getMyModelList({
41+
model_type: 'coder',
42+
}),
43+
getMyModelList({
44+
model_type: 'llm',
45+
}),
46+
])
47+
.then((res) => {
48+
setCoderModel(res[0] || []);
49+
setLlmModel(res[1] || []);
50+
return res;
51+
})
52+
.then(handleModelConfig);
53+
};
54+
55+
const handleModelConfig = (res: [DomainModel[], DomainModel[]]) => {
56+
if ((res[0] || [])?.length == 0 || (res[1] || [])?.length == 0) {
57+
if (location.pathname !== '/model') {
58+
window.location.href = '/model';
59+
}
60+
setIsConfigModel(false);
61+
return false;
62+
} else {
63+
const isActive =
64+
res[0].every((item) => item.is_active) &&
65+
res[1].every((item) => item.is_active);
66+
if (isActive) {
67+
setIsConfigModel(true);
68+
return true;
69+
} else {
70+
if (location.pathname !== '/model') {
71+
window.location.href = '/model';
72+
}
73+
setIsConfigModel(false);
74+
return false;
75+
}
76+
}
77+
};
78+
3579
const getUser = () => {
3680
setLoading(true);
3781
if (location.pathname.startsWith('/user')) {
@@ -49,9 +93,13 @@ const App = () => {
4993
return getAdminProfile()
5094
.then((res) => {
5195
setUser(res);
52-
if (location.pathname.startsWith('/login')) {
53-
onGotoRedirect('admin');
54-
}
96+
getModelList().then((res) => {
97+
if (res) {
98+
if (location.pathname.startsWith('/login')) {
99+
onGotoRedirect('admin');
100+
}
101+
}
102+
});
55103
})
56104
.finally(() => {
57105
setLoading(false);
@@ -71,18 +119,27 @@ const App = () => {
71119

72120
return (
73121
<ThemeProvider theme={lightTheme}>
74-
<AuthContext.Provider
75-
value={[
76-
user,
77-
{
78-
loading,
79-
setUser,
80-
refreshUser: getUser,
81-
},
82-
]}
122+
<CommonContext.Provider
123+
value={{
124+
coderModel,
125+
llmModel,
126+
isConfigModel,
127+
refreshModel: getModelList,
128+
}}
83129
>
84-
<RouterProvider router={router} />
85-
</AuthContext.Provider>
130+
<AuthContext.Provider
131+
value={[
132+
user,
133+
{
134+
loading,
135+
setUser,
136+
refreshUser: getUser,
137+
},
138+
]}
139+
>
140+
<RouterProvider router={router} />
141+
</AuthContext.Provider>
142+
</CommonContext.Provider>
86143
</ThemeProvider>
87144
);
88145
};

ui/src/pages/chat/index.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ import { getListChatRecord } from '@/api/Billing';
44
import dayjs from 'dayjs';
55

66
import Card from '@/components/card';
7-
import { Autocomplete, Box, FormControl, InputLabel, MenuItem, Select, Stack, TextField } from '@mui/material';
7+
import {
8+
Autocomplete,
9+
Box,
10+
FormControl,
11+
InputLabel,
12+
MenuItem,
13+
Select,
14+
Stack,
15+
TextField,
16+
} from '@mui/material';
817
import StyledLabel from '@/components/label';
918

1019
import ChatDetailModal from './chatDetailModal';
@@ -180,7 +189,14 @@ const Chat = () => {
180189
label='工作模式'
181190
value={filterMode}
182191
onChange={(e) =>
183-
setfilterMode(e.target.value as 'code' | 'ask' | 'architect' | 'debug' | 'orchestrator')
192+
setfilterMode(
193+
e.target.value as
194+
| 'code'
195+
| 'ask'
196+
| 'architect'
197+
| 'debug'
198+
| 'orchestrator'
199+
)
184200
}
185201
>
186202
<MenuItem value=''>全部</MenuItem>
@@ -193,7 +209,7 @@ const Chat = () => {
193209
</FormControl>
194210
</Stack>
195211
<Table
196-
height='100%'
212+
height='calc(100% - 52px)'
197213
sx={{ mx: -2 }}
198214
PaginationProps={{
199215
sx: {

ui/src/pages/dashboard/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const Dashboard = () => {
8787
size='small'
8888
onChange={(e) => setTimeRange(e.target.value as TimeRange)}
8989
sx={{ fontSize: 14 }}
90+
disabled
9091
>
9192
<MenuItem value='24h'>最近 24 小时</MenuItem>
9293
<MenuItem value='90d'>最近 90 天</MenuItem>

0 commit comments

Comments
 (0)