Skip to content

Commit eac3fae

Browse files
committed
Create the console shortcut key
1 parent db84c29 commit eac3fae

10 files changed

Lines changed: 97 additions & 88 deletions

File tree

chat2db-client/src/blocks/SQLExecute/index.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ const SQLExecute = memo<IProps>((props) => {
9696

9797
setResultData(sqlResult);
9898
setTableLoading(false);
99-
100-
const createHistoryParams: ISaveBasicInfo = {
101-
...data,
102-
ddl: sql,
103-
name: `${new Date()}-${sql}`,
104-
};
105-
historyServer.createHistory(createHistoryParams);
10699
};
107100

108101
const stopExecuteSql = () => {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
136136
const value = getCurrentSelectContent();
137137
onExecute?.(value);
138138
});
139+
140+
// 注册快捷键command+shift+L新建console
141+
editorRef.current.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyL, () => {
142+
// onShortcutKeyCallback?.(new KeyboardEvent('keydown', { ctrlKey: true, shiftKey: true, keyCode: 76 }));
143+
});
139144
}
140145
}, [editorRef.current, isActive]);
141146

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function Console(props: IProps) {
171171
ddl: editorRef?.current?.getAllContent(),
172172
userId: getCookie('CHAT2DB.USER_ID'),
173173
});
174-
}, 10000);
174+
}, 3000);
175175
}
176176

177177
const tableListName = useMemo(() => {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export default memo<IProps>((props) => {
2525
setCurrentTab(queryResultDataList[0]?.uuid);
2626
}, [queryResultDataList]);
2727

28-
const onChange = useCallback((uuid: string | number) => {
29-
console.log('onChange', uuid);
28+
const onChange = useCallback(() => {
3029
// setCurrentTab(uuid);
3130
}, []);
3231

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

Lines changed: 46 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,78 @@ import React, { memo, Fragment } from 'react';
22
import i18n from '@/i18n';
33
import styles from './index.less';
44
import classnames from 'classnames';
5-
import { OSnow } from '@/utils'
5+
import { osNow } from '@/utils';
66

77
interface IProps {
88
className?: string;
9+
slot: any;
910
}
1011

1112
const keyboardKey = (function () {
12-
if (OSnow().isMac) {
13+
if (osNow().isMac) {
1314
return {
14-
command: 'Cmd'
15-
}
15+
command: 'Cmd',
16+
Shift: 'Shift',
17+
};
1618
}
1719
return {
18-
command: 'Ctrl'
19-
}
20-
}())
20+
command: 'Ctrl',
21+
Shift: 'Shift',
22+
};
23+
})();
2124

2225
const shortcutsList = [
2326
{
2427
title: i18n('common.text.textToSQL'),
25-
keys: [
26-
'Enter'
27-
]
28+
keys: ['Enter'],
2829
},
2930
{
3031
title: i18n('common.text.optimizeSQL'),
31-
keys: [
32-
i18n('common.text.editorRightClick')
33-
]
32+
keys: [i18n('common.text.editorRightClick')],
3433
},
3534
{
3635
title: i18n('common.text.executeSelectedSQL'),
37-
keys: [
38-
keyboardKey.command,
39-
'Enter'
40-
]
36+
keys: [keyboardKey.command, 'Enter'],
4137
},
4238
{
4339
title: i18n('common.text.saveConsole'),
44-
keys: [
45-
keyboardKey.command,
46-
'S'
47-
]
40+
keys: [keyboardKey.command, 'S'],
4841
},
4942
{
5043
title: i18n('common.text.refreshPage'),
51-
keys: [
52-
keyboardKey.command,
53-
'R'
54-
]
44+
keys: [keyboardKey.command, 'R'],
45+
},
46+
{
47+
title: i18n('common.button.createConsole'),
48+
keys: [keyboardKey.command, keyboardKey.Shift, 'L'],
5549
},
56-
// {
57-
// title: i18n('common.button.createConsole'),
58-
// keys: [
59-
// keyboardKey.command,
60-
// 'T'
61-
// ]
62-
// },
63-
]
50+
];
6451

65-
export default memo<IProps>(function ShortcutKey(props) {
66-
const { className } = props;
67-
return <div className={classnames(styles.box, className)}>
68-
<div className={styles.letterpress}>
69-
Chat2DB
70-
</div>
71-
<div className={styles.shortcuts}>
72-
{
73-
shortcutsList.map((t, i) => {
74-
return <div key={i} className={styles.shortcutsItem}>
75-
<div className={styles.title}>
76-
{t.title}
77-
</div>
78-
<div className={styles.plusSignBox}>
79-
{t.keys.map((item, i) => {
80-
return <Fragment key={i}>
81-
<span>
82-
{item}
83-
</span>
84-
{
85-
i + 1 < t.keys.length &&
86-
<span className={styles.plusSign}>
87-
+
88-
</span>
89-
}
90-
</Fragment>
91-
})}
52+
export default memo<IProps>((props) => {
53+
const { className, slot } = props;
54+
return (
55+
<div className={classnames(styles.box, className)}>
56+
<div className={styles.letterpress}>Chat2DB</div>
57+
<div className={styles.shortcuts}>
58+
{shortcutsList.map((t, i) => {
59+
return (
60+
<div key={i} className={styles.shortcutsItem}>
61+
<div className={styles.title}>{t.title}</div>
62+
<div className={styles.plusSignBox}>
63+
{t.keys.map((item, index) => {
64+
return (
65+
<Fragment key={index}>
66+
<span>{item}</span>
67+
{index + 1 < t.keys.length && <span className={styles.plusSign}>+</span>}
68+
</Fragment>
69+
);
70+
})}
71+
</div>
9272
</div>
93-
</div>
94-
})
95-
}
73+
);
74+
})}
75+
</div>
76+
<div className={styles.slot}>{slot()}</div>
9677
</div>
97-
</div>
98-
})
78+
);
79+
});

chat2db-client/src/pages/login/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface IFormData {
1717
const Login: React.FC = () => {
1818
useEffect(() => {
1919
logoutClearSomeLocalStorage();
20+
// 清空dva中的数据
2021
}, []);
2122

2223
// const navigate = useNavigate();

chat2db-client/src/pages/main/workspace/components/WorkspaceLeft/index.less

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,3 @@
1616
.divider {
1717
margin: 0px 0px 10px;
1818
}
19-
20-
.createButton {
21-
width: 100%;
22-
display: flex;
23-
justify-content: center;
24-
align-items: center;
25-
i {
26-
margin-right: 10px;
27-
}
28-
}

chat2db-client/src/pages/main/workspace/components/WorkspaceRight/index.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@
4747
display: flex;
4848
align-items: center;
4949
}
50+
51+
.createButton {
52+
width: 100%;
53+
display: flex;
54+
justify-content: center;
55+
align-items: center;
56+
i {
57+
margin-right: 10px;
58+
}
59+
}

chat2db-client/src/pages/main/workspace/components/WorkspaceRight/index.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { memo, useEffect, useState, useMemo, Fragment, useRef } from 'react';
22
import { connect } from 'umi';
3+
import i18n from '@/i18n';
34
import styles from './index.less';
45
import classnames from 'classnames';
56
import { ConsoleOpenedStatus, ConsoleStatus, TreeNodeType, WorkspaceTabType, workspaceTabConfig } from '@/constants';
67
import historyService from '@/service/history';
78
import sqlService from '@/service/sql';
89
import TabsNew, { ITabItem } from '@/components/TabsNew';
10+
import Iconfont from '@/components/Iconfont';
911
import LoadingContent from '@/components/Loading/LoadingContent';
1012
import ShortcutKey from '@/components/ShortcutKey';
1113
import DatabaseTableEditor from '@/blocks/DatabaseTableEditor';
@@ -16,6 +18,7 @@ import { IAIState } from '@/models/ai';
1618
import { useUpdateEffect } from '@/hooks/useUpdateEffect';
1719
import { v4 as uuidV4 } from 'uuid';
1820
import { IWorkspaceTab } from '@/typings';
21+
import { Button } from 'antd';
1922
import {
2023
registerIntelliSenseField,
2124
registerIntelliSenseKeyword,
@@ -53,8 +56,23 @@ const WorkspaceRight = memo<IProps>((props: IProps) => {
5356
};
5457
});
5558
setWorkspaceTabList(newTabList || []);
59+
setActiveConsoleId(newTabList[0]?.id);
5660
}, [openConsoleList]);
5761

62+
// 注册快捷键command+shift+L新建console
63+
useEffect(() => {
64+
const handleKeyDown = (e: KeyboardEvent) => {
65+
console.log(e.metaKey, e.shiftKey, e.code === 'KeyL', e);
66+
if (e.metaKey && e.shiftKey && e.code === 'KeyL') {
67+
addConsole();
68+
}
69+
};
70+
window.addEventListener('keydown', handleKeyDown);
71+
return () => {
72+
window.removeEventListener('keydown', handleKeyDown);
73+
};
74+
}, [workspaceTabList]);
75+
5876
useEffect(() => {
5977
if (createConsoleIntro) {
6078
if (workspaceTabList.findIndex((t) => t.id === createConsoleIntro.id) === -1) {
@@ -428,6 +446,7 @@ const WorkspaceRight = memo<IProps>((props: IProps) => {
428446
uniqueData: newConsole,
429447
},
430448
];
449+
console.log(newList);
431450
setWorkspaceTabList(newList);
432451
setActiveConsoleId(res);
433452
});
@@ -444,10 +463,21 @@ const WorkspaceRight = memo<IProps>((props: IProps) => {
444463
});
445464
};
446465

466+
function renderCreateConsoleButton() {
467+
return (
468+
<div className={styles.createButtonBox}>
469+
<Button className={styles.createButton} type="primary" onClick={addConsole}>
470+
<Iconfont code="&#xe63a;" />
471+
{i18n('common.button.createConsole')}
472+
</Button>
473+
</div>
474+
);
475+
}
476+
447477
function renderEmpty() {
448478
return (
449479
<div className={styles.ears}>
450-
<ShortcutKey />
480+
<ShortcutKey slot={renderCreateConsoleButton} />
451481
</div>
452482
);
453483
}
@@ -555,7 +585,7 @@ const WorkspaceRight = memo<IProps>((props: IProps) => {
555585
activeKey={activeConsoleId}
556586
editableNameOnBlur={editableNameOnBlur}
557587
items={tabsList}
558-
lastTabCannotClosed
588+
// lastTabCannotClosed
559589
/>
560590
</div>
561591
</LoadingContent>

chat2db-client/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export function getApplicationMessage() {
200200
}
201201

202202
// os is mac or windows
203-
export function OSnow(): {
203+
export function osNow(): {
204204
isMac: boolean;
205205
isWin: boolean;
206206
} {

0 commit comments

Comments
 (0)