balibabu
commited on
Commit
·
04d557b
1
Parent(s):
4086c42
feat: fixed the issue that some PDF documents could not be displayed on the chunk list page in small screens and logout (#105)
Browse files* feat: logout
* feat: fixed the issue that some PDF documents could not be displayed on the chunk list page in small screens
- web/src/hooks/userSettingHook.ts +10 -0
- web/src/layouts/components/user/index.tsx +16 -8
- web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less +4 -0
- web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx +30 -26
- web/src/pages/add-knowledge/components/knowledge-chunk/index.less +6 -3
- web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx +3 -2
- web/src/pages/chat/chat-container/index.tsx +1 -1
- web/src/pages/login/model.ts +13 -10
- web/src/services/userService.ts +5 -0
- web/src/utils/api.ts +1 -0
web/src/hooks/userSettingHook.ts
CHANGED
@@ -64,3 +64,13 @@ export const useSelectParserList = (): Array<{
|
|
64 |
|
65 |
return parserList;
|
66 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
return parserList;
|
66 |
};
|
67 |
+
|
68 |
+
export const useLogout = () => {
|
69 |
+
const dispatch = useDispatch();
|
70 |
+
|
71 |
+
const logout = useCallback((): number => {
|
72 |
+
return dispatch<any>({ type: 'loginModel/logout' });
|
73 |
+
}, [dispatch]);
|
74 |
+
|
75 |
+
return logout;
|
76 |
+
};
|
web/src/layouts/components/user/index.tsx
CHANGED
@@ -1,19 +1,27 @@
|
|
1 |
-
import {
|
|
|
|
|
|
|
|
|
2 |
import authorizationUtil from '@/utils/authorizationUtil';
|
3 |
import type { MenuProps } from 'antd';
|
4 |
import { Avatar, Button, Dropdown } from 'antd';
|
5 |
-
import React, { useMemo } from 'react';
|
6 |
import { useTranslation } from 'react-i18next';
|
7 |
import { history } from 'umi';
|
8 |
|
9 |
const App: React.FC = () => {
|
10 |
const { t } = useTranslation();
|
11 |
const userInfo = useSelectUserInfo();
|
|
|
12 |
|
13 |
-
const
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
const toSetting = () => {
|
19 |
history.push('/setting');
|
@@ -23,7 +31,7 @@ const App: React.FC = () => {
|
|
23 |
return [
|
24 |
{
|
25 |
key: '1',
|
26 |
-
onClick:
|
27 |
label: <Button type="text">{t('header.logout')}</Button>,
|
28 |
},
|
29 |
{
|
@@ -32,7 +40,7 @@ const App: React.FC = () => {
|
|
32 |
label: <Button type="text">{t('header.setting')}</Button>,
|
33 |
},
|
34 |
];
|
35 |
-
}, [t]);
|
36 |
|
37 |
useFetchUserInfo();
|
38 |
|
|
|
1 |
+
import {
|
2 |
+
useFetchUserInfo,
|
3 |
+
useLogout,
|
4 |
+
useSelectUserInfo,
|
5 |
+
} from '@/hooks/userSettingHook';
|
6 |
import authorizationUtil from '@/utils/authorizationUtil';
|
7 |
import type { MenuProps } from 'antd';
|
8 |
import { Avatar, Button, Dropdown } from 'antd';
|
9 |
+
import React, { useCallback, useMemo } from 'react';
|
10 |
import { useTranslation } from 'react-i18next';
|
11 |
import { history } from 'umi';
|
12 |
|
13 |
const App: React.FC = () => {
|
14 |
const { t } = useTranslation();
|
15 |
const userInfo = useSelectUserInfo();
|
16 |
+
const logout = useLogout();
|
17 |
|
18 |
+
const handleLogout = useCallback(async () => {
|
19 |
+
const retcode = await logout();
|
20 |
+
if (retcode === 0) {
|
21 |
+
authorizationUtil.removeAll();
|
22 |
+
history.push('/login');
|
23 |
+
}
|
24 |
+
}, [logout]);
|
25 |
|
26 |
const toSetting = () => {
|
27 |
history.push('/setting');
|
|
|
31 |
return [
|
32 |
{
|
33 |
key: '1',
|
34 |
+
onClick: handleLogout,
|
35 |
label: <Button type="text">{t('header.logout')}</Button>,
|
36 |
},
|
37 |
{
|
|
|
40 |
label: <Button type="text">{t('header.setting')}</Button>,
|
41 |
},
|
42 |
];
|
43 |
+
}, [t, handleLogout]);
|
44 |
|
45 |
useFetchUserInfo();
|
46 |
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less
CHANGED
@@ -12,6 +12,10 @@
|
|
12 |
.chunkText;
|
13 |
}
|
14 |
|
|
|
|
|
|
|
|
|
15 |
.cardSelected {
|
16 |
background-color: @selectedBackgroundColor;
|
17 |
}
|
|
|
12 |
.chunkText;
|
13 |
}
|
14 |
|
15 |
+
.chunkCard {
|
16 |
+
width: 100%;
|
17 |
+
}
|
18 |
+
|
19 |
.cardSelected {
|
20 |
background-color: @selectedBackgroundColor;
|
21 |
}
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import Image from '@/components/image';
|
2 |
import { IChunk } from '@/interfaces/database/knowledge';
|
3 |
import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd';
|
|
|
4 |
import { useState } from 'react';
|
|
|
5 |
import styles from './index.less';
|
6 |
|
7 |
interface IProps {
|
@@ -44,33 +46,35 @@ const ChunkCard = ({
|
|
44 |
};
|
45 |
|
46 |
return (
|
47 |
-
<
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
<Image id={item.img_id} className={styles.
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
</div>
|
74 |
);
|
75 |
};
|
76 |
|
|
|
1 |
import Image from '@/components/image';
|
2 |
import { IChunk } from '@/interfaces/database/knowledge';
|
3 |
import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd';
|
4 |
+
import classNames from 'classnames';
|
5 |
import { useState } from 'react';
|
6 |
+
|
7 |
import styles from './index.less';
|
8 |
|
9 |
interface IProps {
|
|
|
46 |
};
|
47 |
|
48 |
return (
|
49 |
+
<Card
|
50 |
+
className={classNames(styles.chunkCard, {
|
51 |
+
[styles.cardSelected]: selected,
|
52 |
+
})}
|
53 |
+
>
|
54 |
+
<Flex gap={'middle'} justify={'space-between'}>
|
55 |
+
<Checkbox onChange={handleCheck} checked={checked}></Checkbox>
|
56 |
+
{item.img_id && (
|
57 |
+
<Popover
|
58 |
+
placement="topRight"
|
59 |
+
content={
|
60 |
+
<Image id={item.img_id} className={styles.imagePreview}></Image>
|
61 |
+
}
|
62 |
+
>
|
63 |
+
<Image id={item.img_id} className={styles.image}></Image>
|
64 |
+
</Popover>
|
65 |
+
)}
|
66 |
|
67 |
+
<section
|
68 |
+
onDoubleClick={handleContentDoubleClick}
|
69 |
+
onClick={handleContentClick}
|
70 |
+
className={styles.content}
|
71 |
+
dangerouslySetInnerHTML={{ __html: item.content_with_weight }}
|
72 |
+
></section>
|
73 |
+
<div>
|
74 |
+
<Switch checked={enabled} onChange={onChange} />
|
75 |
+
</div>
|
76 |
+
</Flex>
|
77 |
+
</Card>
|
|
|
78 |
);
|
79 |
};
|
80 |
|
web/src/pages/add-knowledge/components/knowledge-chunk/index.less
CHANGED
@@ -12,6 +12,10 @@
|
|
12 |
justify-content: space-between;
|
13 |
}
|
14 |
|
|
|
|
|
|
|
|
|
15 |
.pageContent {
|
16 |
flex: 1;
|
17 |
width: 100%;
|
@@ -29,12 +33,11 @@
|
|
29 |
}
|
30 |
|
31 |
.chunkContainer {
|
32 |
-
height: calc(100vh -
|
33 |
-
overflow: auto;
|
34 |
-
width: 100%;
|
35 |
}
|
36 |
|
37 |
.pageFooter {
|
|
|
38 |
height: 32px;
|
39 |
}
|
40 |
}
|
|
|
12 |
justify-content: space-between;
|
13 |
}
|
14 |
|
15 |
+
.pagePdfWrapper {
|
16 |
+
width: 60%;
|
17 |
+
}
|
18 |
+
|
19 |
.pageContent {
|
20 |
flex: 1;
|
21 |
width: 100%;
|
|
|
33 |
}
|
34 |
|
35 |
.chunkContainer {
|
36 |
+
height: calc(100vh - 332px);
|
|
|
|
|
37 |
}
|
38 |
|
39 |
.pageFooter {
|
40 |
+
padding-top: 10px;
|
41 |
height: 32px;
|
42 |
}
|
43 |
}
|
web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx
CHANGED
@@ -38,6 +38,7 @@ const Chunk = () => {
|
|
38 |
const { removeChunk } = useDeleteChunkByIds();
|
39 |
const documentInfo = useSelectDocumentInfo();
|
40 |
const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();
|
|
|
41 |
|
42 |
const getChunkList = useCallback(() => {
|
43 |
const payload: PayloadType = {
|
@@ -164,7 +165,7 @@ const Chunk = () => {
|
|
164 |
></ChunkToolBar>
|
165 |
<Divider></Divider>
|
166 |
<Flex flex={1} gap={'middle'}>
|
167 |
-
<Flex
|
168 |
<div className={styles.pageContent}>
|
169 |
<Spin spinning={loading} className={styles.spin} size="large">
|
170 |
<Space
|
@@ -204,7 +205,7 @@ const Chunk = () => {
|
|
204 |
</div>
|
205 |
</Flex>
|
206 |
|
207 |
-
{
|
208 |
<section className={styles.documentPreview}>
|
209 |
<DocumentPreview
|
210 |
selectedChunkId={selectedChunkId}
|
|
|
38 |
const { removeChunk } = useDeleteChunkByIds();
|
39 |
const documentInfo = useSelectDocumentInfo();
|
40 |
const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();
|
41 |
+
const isPdf = documentInfo.type === 'pdf';
|
42 |
|
43 |
const getChunkList = useCallback(() => {
|
44 |
const payload: PayloadType = {
|
|
|
165 |
></ChunkToolBar>
|
166 |
<Divider></Divider>
|
167 |
<Flex flex={1} gap={'middle'}>
|
168 |
+
<Flex vertical className={isPdf ? styles.pagePdfWrapper : ''}>
|
169 |
<div className={styles.pageContent}>
|
170 |
<Spin spinning={loading} className={styles.spin} size="large">
|
171 |
<Space
|
|
|
205 |
</div>
|
206 |
</Flex>
|
207 |
|
208 |
+
{isPdf && (
|
209 |
<section className={styles.documentPreview}>
|
210 |
<DocumentPreview
|
211 |
selectedChunkId={selectedChunkId}
|
web/src/pages/chat/chat-container/index.tsx
CHANGED
@@ -177,7 +177,7 @@ const MessageItem = ({
|
|
177 |
<Flex vertical gap={8} flex={1}>
|
178 |
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
179 |
<div className={styles.messageText}>
|
180 |
-
{item.content ? (
|
181 |
<Markdown
|
182 |
rehypePlugins={[rehypeWrapReference]}
|
183 |
components={
|
|
|
177 |
<Flex vertical gap={8} flex={1}>
|
178 |
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
179 |
<div className={styles.messageText}>
|
180 |
+
{item.content !== '' ? (
|
181 |
<Markdown
|
182 |
rehypePlugins={[rehypeWrapReference]}
|
183 |
components={
|
web/src/pages/login/model.ts
CHANGED
@@ -25,18 +25,13 @@ const model: DvaModel<LoginModelState> = {
|
|
25 |
};
|
26 |
},
|
27 |
},
|
28 |
-
subscriptions: {
|
29 |
-
setup({ dispatch, history }) {
|
30 |
-
history.listen((location) => {});
|
31 |
-
},
|
32 |
-
},
|
33 |
effects: {
|
34 |
-
*login({ payload = {} }, { call
|
35 |
const { data, response } = yield call(userService.login, payload);
|
36 |
const { retcode, data: res } = data;
|
37 |
const authorization = response.headers.get(Authorization);
|
38 |
if (retcode === 0) {
|
39 |
-
message.success('
|
40 |
const token = res.access_token;
|
41 |
const userInfo = {
|
42 |
avatar: res.avatar,
|
@@ -51,15 +46,23 @@ const model: DvaModel<LoginModelState> = {
|
|
51 |
}
|
52 |
return retcode;
|
53 |
},
|
54 |
-
*register({ payload = {} }, { call
|
55 |
-
const { data
|
56 |
console.log();
|
57 |
-
const { retcode
|
58 |
if (retcode === 0) {
|
59 |
message.success('注册成功!');
|
60 |
}
|
61 |
return retcode;
|
62 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
},
|
64 |
};
|
65 |
export default model;
|
|
|
25 |
};
|
26 |
},
|
27 |
},
|
|
|
|
|
|
|
|
|
|
|
28 |
effects: {
|
29 |
+
*login({ payload = {} }, { call }) {
|
30 |
const { data, response } = yield call(userService.login, payload);
|
31 |
const { retcode, data: res } = data;
|
32 |
const authorization = response.headers.get(Authorization);
|
33 |
if (retcode === 0) {
|
34 |
+
message.success('logged!');
|
35 |
const token = res.access_token;
|
36 |
const userInfo = {
|
37 |
avatar: res.avatar,
|
|
|
46 |
}
|
47 |
return retcode;
|
48 |
},
|
49 |
+
*register({ payload = {} }, { call }) {
|
50 |
+
const { data } = yield call(userService.register, payload);
|
51 |
console.log();
|
52 |
+
const { retcode } = data;
|
53 |
if (retcode === 0) {
|
54 |
message.success('注册成功!');
|
55 |
}
|
56 |
return retcode;
|
57 |
},
|
58 |
+
*logout({ payload = {} }, { call }) {
|
59 |
+
const { data } = yield call(userService.logout, payload);
|
60 |
+
const { retcode } = data;
|
61 |
+
if (retcode === 0) {
|
62 |
+
message.success('logout');
|
63 |
+
}
|
64 |
+
return retcode;
|
65 |
+
},
|
66 |
},
|
67 |
};
|
68 |
export default model;
|
web/src/services/userService.ts
CHANGED
@@ -4,6 +4,7 @@ import request from '@/utils/request';
|
|
4 |
|
5 |
const {
|
6 |
login,
|
|
|
7 |
register,
|
8 |
setting,
|
9 |
user_info,
|
@@ -20,6 +21,10 @@ const methods = {
|
|
20 |
url: login,
|
21 |
method: 'post',
|
22 |
},
|
|
|
|
|
|
|
|
|
23 |
register: {
|
24 |
url: register,
|
25 |
method: 'post',
|
|
|
4 |
|
5 |
const {
|
6 |
login,
|
7 |
+
logout,
|
8 |
register,
|
9 |
setting,
|
10 |
user_info,
|
|
|
21 |
url: login,
|
22 |
method: 'post',
|
23 |
},
|
24 |
+
logout: {
|
25 |
+
url: logout,
|
26 |
+
method: 'get',
|
27 |
+
},
|
28 |
register: {
|
29 |
url: register,
|
30 |
method: 'post',
|
web/src/utils/api.ts
CHANGED
@@ -5,6 +5,7 @@ export { api_host };
|
|
5 |
export default {
|
6 |
// 用户
|
7 |
login: `${api_host}/user/login`,
|
|
|
8 |
register: `${api_host}/user/register`,
|
9 |
setting: `${api_host}/user/setting`,
|
10 |
user_info: `${api_host}/user/info`,
|
|
|
5 |
export default {
|
6 |
// 用户
|
7 |
login: `${api_host}/user/login`,
|
8 |
+
logout: `${api_host}/user/logout`,
|
9 |
register: `${api_host}/user/register`,
|
10 |
setting: `${api_host}/user/setting`,
|
11 |
user_info: `${api_host}/user/info`,
|