Skip to content

Commit 38d089f

Browse files
author
fanjin.fjy
committed
feat: optimize workspace
1 parent 7dfdb1d commit 38d089f

8 files changed

Lines changed: 71 additions & 30 deletions

File tree

chat2db-client/.umirc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { formatDate } from './src/utils/date';
22
import { defineConfig } from 'umi';
3+
import { getLang } from '@/utils/localStorage';
34
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
45
console.log(process.env.UMI_ENV);
56

@@ -34,7 +35,7 @@ export default defineConfig({
3435
proxy: {
3536
'/api': {
3637
target: 'http://127.0.0.1:10821',
37-
changeOrigin: true,
38+
changeOrigin: true
3839
},
3940
},
4041
headScripts: ['if (window.myAPI) { window.myAPI.startServerForSpawn() }'],

chat2db-client/src/components/Console/ChatInput/index.less

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
margin-right: 14px;
1313
}
1414

15-
.suffixBlock{
15+
.suffixBlock {
16+
display: flex;
17+
align-items: center;
18+
}
19+
20+
.tableSelectBlock {
21+
margin-right: 8px;
22+
cursor: pointer;
23+
padding: 4px;
24+
border-radius: 4px 12px;
25+
26+
&:hover {
27+
background-color: var(--color-bg-elevated);
28+
}
1629

1730
}
1831

19-
.remainBlock{
32+
.remainBlock {
2033
border-radius: 16px;
2134
background-color: var(--color-bg-elevated);
2235
padding: 4px 12px;
36+
2337
}

chat2db-client/src/components/Console/ChatInput/index.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React, { ChangeEvent, useEffect, useState } from 'react';
22
import styles from './index.less';
33
import AIImg from '@/assets/img/ai.svg';
4-
import { Input } from 'antd';
4+
import { Checkbox, Dropdown, Input, Popover } from 'antd';
55
import i18n from '@/i18n/';
6+
import Iconfont from '@/components/Iconfont';
67

78
interface IProps {
89
value?: string;
910
result?: string;
11+
tables?: string[];
12+
selectedTables?: string[];
1013
onPressEnter: (value: string) => void;
14+
onSelectTables: (tables: (string | number | boolean)[]) => void;
1115
}
1216

1317
function ChatInput(props: IProps) {
@@ -17,13 +21,33 @@ function ChatInput(props: IProps) {
1721
}
1822
};
1923

24+
const renderSelectTable = () => {
25+
const { tables, selectedTables, onSelectTables } = props;
26+
return tables && tables.length ? (
27+
<div>
28+
<Checkbox.Group
29+
options={tables || []}
30+
value={selectedTables}
31+
onChange={(v) => {
32+
onSelectTables && onSelectTables(v);
33+
}}
34+
/>
35+
</div>
36+
) : (
37+
<div>暂无表</div>
38+
);
39+
};
40+
2041
const renderSuffix = () => {
2142
const remainCnt = 10;
2243
return (
2344
<div className={styles.suffixBlock}>
24-
<div className={styles.remainBlock}>
25-
{i18n('chat.input.remain', remainCnt)}
45+
<div className={styles.tableSelectBlock}>
46+
<Popover content={renderSelectTable()} placement="bottom">
47+
<Iconfont code="&#xe618;" />
48+
</Popover>
2649
</div>
50+
<div className={styles.remainBlock}>{i18n('chat.input.remain', remainCnt)}</div>
2751
</div>
2852
);
2953
};

chat2db-client/src/components/Console/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interface IProps {
5656
};
5757
editorOptions: IEditorOptions;
5858
// onSQLContentChange: (v: string) => void;
59-
onExecuteSQL: (result: any, sql: string) => void;
59+
onExecuteSQL: (result: any, sql?: string) => void;
6060
workspaceModel: IWorkspaceModelType;
6161
dispatch: any;
6262
}
@@ -83,8 +83,14 @@ function Console(props: IProps) {
8383
}, [appendValue]);
8484

8585
const onPressChatInput = (value: string) => {
86+
const { dataSourceId, databaseName, schemaName } = executeParams;
8687
const params = formatParams({
8788
message: value,
89+
dataSourceId,
90+
databaseName,
91+
schemaName,
92+
//TODO:
93+
promptType: IPromptType.NL_2_SQL,
8894
});
8995

9096
// setIsLoading(true);
@@ -95,6 +101,7 @@ function Console(props: IProps) {
95101
if (isEOF) {
96102
closeEventSource();
97103
setIsLoading(false);
104+
console.log('chatResult', chatResult.current);
98105
return;
99106
}
100107
chatResult.current += JSON.parse(message).content;
@@ -127,7 +134,7 @@ function Console(props: IProps) {
127134
sql: sqlContent,
128135
...executeParams,
129136
};
130-
// props.onExecuteSQL?.(undefined);
137+
props.onExecuteSQL?.(undefined);
131138
sqlServer.executeSql(p).then((res) => {
132139
props.onExecuteSQL?.(res, sqlContent!);
133140
// console.log(res)

chat2db-client/src/layouts/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ function AppContainer() {
5959
const [initEnd, setInitEnd] = useState(false);
6060
const [appTheme, setAppTheme] = useTheme();
6161

62+
useEffect(() => {
63+
let date = new Date('2030-12-30 12:30:00').toUTCString();
64+
document.cookie = `CHAT2DB.LOCALE=${getLang()};Expires=${date}`;
65+
}, []);
66+
6267
useEffect(() => {
6368
InjectThemeVar(token as any, appTheme.backgroundColor, appTheme.primaryColor);
6469
}, [token]);

chat2db-client/src/service/base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ request.interceptors.request.use((url, options) => {
8787
if (localStorage.getItem('DBHUB')) {
8888
myOptions.headers.DBHUB = localStorage.getItem('DBHUB');
8989
}
90-
myOptions.headers.lang = getLang() || 'en-us';
9190
return {
9291
options: myOptions,
9392
};

chat2db-client/src/utils/eventSource.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { EventSourcePolyfill } from 'event-source-polyfill';
22

3-
const connectToEventSource = (params: {
4-
url: string;
5-
uid: string;
6-
onMessage: Function;
7-
onError: Function;
8-
}) => {
3+
const connectToEventSource = (params: { url: string; uid: string; onMessage: Function; onError: Function }) => {
94
const { url, uid, onMessage, onError } = params;
105

116
if (!url || !onMessage || !onError) {
@@ -17,13 +12,12 @@ const connectToEventSource = (params: {
1712
headers: {
1813
uid,
1914
DBHUB,
20-
}
21-
}
22-
const eventSource = new EventSourcePolyfill(`${window._BaseURL}${url}`, {
23-
p
24-
});
15+
},
16+
};
17+
const eventSource = new EventSourcePolyfill(`${window._BaseURL}${url}`, p);
2518

2619
eventSource.onmessage = (event) => {
20+
console.log('onmessage', event);
2721
onMessage(event.data);
2822
};
2923

chat2db-client/src/utils/localStorage.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ThemeType, PrimaryColorType, LangType } from '@/constants';
22
import { ICurWorkspaceParams } from '@/models/workspace';
33

44
export function getLang(): LangType {
5-
return localStorage.getItem('lang') as LangType;
5+
return (localStorage.getItem('lang') as LangType) || 'en-us';
66
}
77

88
export function setLang(lang: LangType) {
@@ -18,10 +18,7 @@ export function setTheme(theme: ThemeType) {
1818
}
1919

2020
export function getPrimaryColor(): PrimaryColorType {
21-
return (
22-
(localStorage.getItem('primary-color') as PrimaryColorType) ||
23-
PrimaryColorType.Polar_Blue
24-
);
21+
return (localStorage.getItem('primary-color') as PrimaryColorType) || PrimaryColorType.Polar_Blue;
2522
}
2623

2724
export function setPrimaryColor(primaryColor: PrimaryColorType) {
@@ -36,15 +33,15 @@ export function getCurrentWorkspaceDatabase(): ICurWorkspaceParams {
3633
const curWorkspaceParams = localStorage.getItem('current-workspace-database');
3734

3835
if (curWorkspaceParams) {
39-
return JSON.parse(curWorkspaceParams)
36+
return JSON.parse(curWorkspaceParams);
4037
}
4138
return {} as ICurWorkspaceParams;
42-
}
39+
}
4340

4441
export function getCurConnection() {
45-
const curConnection = localStorage.getItem('cur-connection')
42+
const curConnection = localStorage.getItem('cur-connection');
4643
if (curConnection) {
47-
return JSON.parse(curConnection)
44+
return JSON.parse(curConnection);
4845
}
49-
return undefined
46+
return undefined;
5047
}

0 commit comments

Comments
 (0)