Skip to content

Commit a40a37b

Browse files
authored
Merge pull request #101 from safe1ine/main
增加了成员登录记录 && 支持删除模型
2 parents 0ecf664 + ccf4edf commit a40a37b

File tree

11 files changed

+170
-36
lines changed

11 files changed

+170
-36
lines changed

ui/src/api/Model.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import request, { ContentType, RequestParams } from "./httpClient";
1414
import {
15+
DeleteDeleteModelParams,
1516
DomainAllModelResp,
1617
DomainCheckModelReq,
1718
DomainCreateModelReq,
@@ -111,6 +112,29 @@ export const postCreateModel = (
111112
...params,
112113
});
113114

115+
/**
116+
* @description 删除模型
117+
*
118+
* @tags Model
119+
* @name DeleteDeleteModel
120+
* @summary 删除模型
121+
* @request DELETE:/api/v1/model
122+
* @response `200` `WebResp` OK
123+
*/
124+
125+
export const deleteDeleteModel = (
126+
query: DeleteDeleteModelParams,
127+
params: RequestParams = {},
128+
) =>
129+
request<WebResp>({
130+
path: `/api/v1/model`,
131+
method: "DELETE",
132+
query: query,
133+
type: ContentType.Json,
134+
format: "json",
135+
...params,
136+
});
137+
114138
/**
115139
* @description 检查模型
116140
*

ui/src/api/types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ export interface DomainCreateModelReq {
210210
| "BaiZhiCloud"
211211
| "Hunyuan"
212212
| "BaiLian"
213-
| "Volcengine";
213+
| "Volcengine"
214+
| "Other";
214215
/** 模型显示名称 */
215216
show_name?: string;
216217
}
@@ -414,7 +415,8 @@ export interface DomainModelBasic {
414415
| "BaiZhiCloud"
415416
| "Hunyuan"
416417
| "BaiLian"
417-
| "Volcengine";
418+
| "Volcengine"
419+
| "Other";
418420
}
419421

420422
export interface DomainModelData {
@@ -581,7 +583,8 @@ export interface DomainUpdateModelReq {
581583
| "BaiZhiCloud"
582584
| "Hunyuan"
583585
| "BaiLian"
584-
| "Volcengine";
586+
| "Volcengine"
587+
| "Other";
585588
/** 模型显示名称 */
586589
show_name?: string;
587590
/** 状态 active:启用 inactive:禁用 */
@@ -621,6 +624,8 @@ export interface DomainUser {
621624
email?: string;
622625
/** 用户ID */
623626
id?: string;
627+
/** 是否删除 */
628+
is_deleted?: boolean;
624629
/** 最后活跃时间 */
625630
last_active_at?: number;
626631
/** 用户状态 active: 正常 locked: 锁定 inactive: 禁用 */
@@ -656,12 +661,16 @@ export interface DomainUserHeatmapResp {
656661
}
657662

658663
export interface DomainUserLoginHistory {
664+
/** 插件ID vscode */
665+
client_id?: string;
659666
/** 客户端版本 */
660667
client_version?: string;
661668
/** 登录时间 */
662669
created_at?: number;
663670
/** 设备信息 */
664671
device?: string;
672+
/** 主机名 */
673+
hostname?: string;
665674
/** IP信息 */
666675
ip_info?: DomainIPInfo;
667676
/** 用户信息 */
@@ -870,6 +879,11 @@ export interface GetUserStatDashboardParams {
870879
user_id?: string;
871880
}
872881

882+
export interface DeleteDeleteModelParams {
883+
/** 模型ID */
884+
id: string;
885+
}
886+
873887
export interface GetMyModelListParams {
874888
/** 模型类型 llm:对话模型 coder:代码模型 */
875889
model_type?: "llm" | "coder" | "embedding" | "audio" | "reranker";

ui/src/components/user/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ const User = ({
77
username = '',
88
email = '',
99
avatar = '',
10+
deleted = false,
1011
}: {
1112
id?: string;
1213
username?: string;
1314
email?: string;
1415
avatar?: string;
16+
deleted?: boolean;
1517
}) => {
1618
return (
1719
<Stack>
@@ -31,11 +33,24 @@ const User = ({
3133
src={avatar}
3234
sx={{ width: 20, height: 20, fontSize: 12 }}
3335
/>
34-
<Typography sx={{ pt: '2px' }}>{username}</Typography>
36+
<Typography sx={{
37+
pt: '2px',
38+
textDecoration: deleted ? 'line-through' : 'none',
39+
color: deleted ? 'text.disabled' : 'text.primary',
40+
whiteSpace: 'nowrap',
41+
overflow: 'hidden',
42+
textOverflow: 'ellipsis'
43+
}}>{username}</Typography>
3544
</Stack>
3645
</Link>
3746
{email && (
38-
<Typography color='text.auxiliary' sx={{ fontSize: 14 }}>
47+
<Typography sx={{
48+
fontSize: 14,
49+
color: deleted ? 'text.disabled' : 'text.auxiliary',
50+
whiteSpace: 'nowrap',
51+
overflow: 'hidden',
52+
textOverflow: 'ellipsis'
53+
}}>
3954
{email}
4055
</Typography>
4156
)}

ui/src/pages/admin/loginHistory.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ const LoginHistory = () => {
4040
title: '登录时间',
4141
dataIndex: 'created_at',
4242
render: (text) => {
43-
return dayjs.unix(text).format('YYYY-MM-DD HH:mm:ss');
43+
return (
44+
<Stack direction='column'>
45+
<Box>{dayjs.unix(text).format('YYYY-MM-DD')}</Box>
46+
<Box>{dayjs.unix(text).format('HH:mm:ss')}</Box>
47+
</Stack>
48+
)
4449
},
4550
},
4651
];
@@ -52,7 +57,7 @@ const LoginHistory = () => {
5257
alignItems='center'
5358
sx={{ mb: 2 }}
5459
>
55-
<Box sx={{ fontWeight: 700, lineHeight: '36px' }}>登录记录</Box>
60+
<Box sx={{ fontWeight: 700, lineHeight: '36px' }}>管理员登录记录</Box>
5661
</Stack>
5762
<Table
5863
columns={columns}

ui/src/pages/chat/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const Chat = () => {
5050
username={value.username!}
5151
email={value.email!}
5252
avatar={value.avatar_url!}
53+
deleted={value.is_deleted!}
5354
/>
5455
);
5556
},

ui/src/pages/completion/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const Completion = () => {
9595
username={value.username!}
9696
email={value.email!}
9797
avatar={value.avatar_url!}
98+
deleted={value.is_deleted!}
9899
/>
99100
);
100101
},

ui/src/pages/model/components/modelCard.tsx

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import Card from '@/components/card';
33
import { useRequest } from 'ahooks';
4-
import { getMyModelList, putUpdateModel } from '@/api/Model';
4+
import { deleteDeleteModel, getMyModelList, putUpdateModel } from '@/api/Model';
55
import { DomainModel, ConstsModelStatus, ConstsModelType } from '@/api/types';
66
import { Stack, Box, Button, Grid2 as Grid, ButtonBase } from '@mui/material';
77
import StyledLabel from '@/components/label';
@@ -48,6 +48,31 @@ const ModelItem = ({
4848
},
4949
});
5050
};
51+
52+
const onRemoveModel = () => {
53+
Modal.confirm({
54+
title: '删除模型',
55+
content: (
56+
<>
57+
确定要删除{' '}
58+
<Box component='span' sx={{ fontWeight: 700, color: 'text.primary' }}>
59+
{data.model_name}
60+
</Box>{' '}
61+
模型吗?
62+
</>
63+
),
64+
okText: '删除',
65+
okButtonProps: {
66+
color: 'error',
67+
},
68+
onOk: () => {
69+
deleteDeleteModel({ id: data.id! }).then(() => {
70+
message.success('删除成功');
71+
refresh();
72+
});
73+
},
74+
});
75+
};
5176

5277
const onActiveModel = () => {
5378
Modal.confirm({
@@ -169,6 +194,18 @@ const ModelItem = ({
169194
sx={{ button: { minWidth: 0 } }}
170195
gap={2}
171196
>
197+
{!data.is_active && (
198+
<ButtonBase
199+
disableRipple
200+
sx={{
201+
color: 'success.main',
202+
}}
203+
onClick={onActiveModel}
204+
>
205+
激活
206+
</ButtonBase>
207+
)}
208+
172209
{!data.is_internal && <ButtonBase
173210
disableRipple
174211
sx={{
@@ -178,32 +215,30 @@ const ModelItem = ({
178215
>
179216
编辑
180217
</ButtonBase>}
181-
{!data.is_active && (
218+
219+
{data.is_active && (
182220
<ButtonBase
183221
disableRipple
184222
sx={{
185-
color: 'success.main',
223+
color: 'error.main',
186224
}}
187-
onClick={onActiveModel}
225+
onClick={onInactiveModel}
188226
>
189-
激活
227+
停用
190228
</ButtonBase>
191229
)}
192230

193-
{data.is_active && (
231+
{data.is_internal === false && data.is_active === false && (
194232
<ButtonBase
195233
disableRipple
196234
sx={{
197235
color: 'error.main',
198236
}}
199-
onClick={onInactiveModel}
237+
onClick={onRemoveModel}
200238
>
201-
停用
239+
删除
202240
</ButtonBase>
203241
)}
204-
{/* <Button color='error' size='small'>
205-
删除
206-
</Button> */}
207242
</Stack>
208243
</Stack>
209244
</Card>

ui/src/pages/user-management/loginHistory.tsx

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,62 @@ const LoginHistory = () => {
2020
dataIndex: 'user',
2121
render: (user, record) => {
2222
return (
23-
<User
24-
username={record.user!.username!}
25-
id={record.user!.id!}
26-
email={record.user!.email!}
27-
avatar={record.user!.avatar_url!}
28-
/>
23+
<Box sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
24+
<User
25+
username={record.user!.username!}
26+
id={record.user!.id!}
27+
email={record.user!.email!}
28+
avatar={record.user!.avatar_url!}
29+
deleted={record.user!.is_deleted!}
30+
/>
31+
</Box>
2932
);
3033
},
3134
},
3235
{
3336
title: '设备',
3437
dataIndex: 'device',
38+
render: (ip, record) => {
39+
return (
40+
<Stack direction='column'>
41+
<Box sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
42+
{record?.device}
43+
</Box>
44+
<Box sx={{ color: 'text.secondary', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
45+
{record?.hostname}
46+
</Box>
47+
</Stack>
48+
);
49+
},
3550
},
3651
{
37-
title: '客户端版本',
38-
dataIndex: 'client_version',
52+
title: '客户端',
53+
dataIndex: 'client',
54+
render: (ip, record) => {
55+
return (
56+
<Stack direction='column'>
57+
<Box sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
58+
{record?.client_id}
59+
</Box>
60+
<Box sx={{ color: 'text.secondary', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
61+
{record?.client_version}
62+
</Box>
63+
</Stack>
64+
);
65+
},
3966
},
4067
{
41-
title: 'IP 地址',
68+
title: 'IP 地址',
4269
dataIndex: 'ip',
4370
render: (ip, record) => {
44-
let address = '';
45-
if (record?.ip_info) {
46-
address = `${record?.ip_info?.country}-${record?.ip_info?.city}`;
47-
}
4871
return (
49-
<Stack direction='row'>
50-
<Box>{ip}</Box>
51-
<Box sx={{ color: 'text.secondary' }}>{address}</Box>
72+
<Stack direction='column'>
73+
<Box sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
74+
{record?.ip_info?.ip}
75+
</Box>
76+
<Box sx={{ color: 'text.secondary', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
77+
{record?.ip_info?.country === '中国' ? ('' + record?.ip_info?.province + '-' + record?.ip_info?.city) : (record?.ip_info?.country || '未知')}
78+
</Box>
5279
</Stack>
5380
);
5481
},
@@ -57,7 +84,16 @@ const LoginHistory = () => {
5784
title: '登录时间',
5885
dataIndex: 'created_at',
5986
render: (text) => {
60-
return dayjs.unix(text).format('YYYY-MM-DD HH:mm:ss');
87+
return (
88+
<Stack direction='column'>
89+
<Box sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
90+
{dayjs.unix(text).format('YYYY-MM-DD')}
91+
</Box>
92+
<Box sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
93+
{dayjs.unix(text).format('HH:mm:ss')}
94+
</Box>
95+
</Stack>
96+
)
6197
},
6298
},
6399
];
@@ -69,7 +105,7 @@ const LoginHistory = () => {
69105
alignItems='center'
70106
sx={{ mb: 2 }}
71107
>
72-
<Box sx={{ fontWeight: 700 }}>登录历史</Box>
108+
<Box sx={{ fontWeight: 700 }}>成员登录记录</Box>
73109
</Stack>
74110
<Table
75111
height='calc(100% - 40px)'

0 commit comments

Comments
 (0)