Skip to content

Commit 32019c8

Browse files
committed
feat: 快捷键页面
1 parent fdd0532 commit 32019c8

10 files changed

Lines changed: 166 additions & 12 deletions

File tree

chat2db-client/.umirc.prod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { defineConfig } from 'umi';
22
import { extractYarnConfig } from './src/utils/webpack';
33
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
4-
const UMI_PublicPath = process.env.UMI_PublicPath || './static/front/';
54
const yarn_config = extractYarnConfig(process.argv);
5+
const publicPath = yarn_config.public_path || './static/front/';
66

77
const chainWebpack = (config: any, { webpack }: any) => {
88
config.plugin('monaco-editor').use(MonacoWebpackPlugin, [
@@ -13,7 +13,7 @@ const chainWebpack = (config: any, { webpack }: any) => {
1313
};
1414

1515
export default defineConfig({
16-
publicPath: UMI_PublicPath,
16+
publicPath: publicPath,
1717
chainWebpack,
1818
define: {
1919
'process.env.UMI_ENV': process.env.UMI_ENV,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@import '../../styles/var.less';
2+
3+
.box {
4+
display: flex;
5+
flex-direction: column;
6+
justify-content: center;
7+
align-items: center;
8+
9+
.letterpress{
10+
display: flex;
11+
justify-content: center;
12+
align-items: center;
13+
font-size: 80px;
14+
font-weight: 900;
15+
color: var(--color-text);
16+
opacity: 0.15;
17+
overflow: hidden;
18+
margin-bottom: 30px;
19+
}
20+
21+
.shortcutsItem{
22+
display: flex;
23+
justify-content: center;
24+
font-size: 14px;
25+
margin: 10px 0px;
26+
color: var(--color-text-tertiary);
27+
28+
.title{
29+
margin-right: 10px;
30+
}
31+
}
32+
33+
.plusSign{
34+
margin: 0px 4px;
35+
}
36+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React, { memo, Fragment } from 'react';
2+
import i18n from '@/i18n';
3+
import styles from './index.less';
4+
import classnames from 'classnames';
5+
import { OSnow } from '@/utils'
6+
7+
interface IProps {
8+
className?: string;
9+
}
10+
11+
const keyboardKey = (function () {
12+
if (OSnow().isMac) {
13+
return {
14+
command: 'Cmd'
15+
}
16+
}
17+
return {
18+
command: 'Ctrl'
19+
}
20+
}())
21+
22+
const shortcutsList = [
23+
{
24+
title: i18n('common.text.saveConsole'),
25+
keys: [
26+
keyboardKey.command,
27+
'S'
28+
]
29+
},
30+
{
31+
title: i18n('common.text.refreshPage'),
32+
keys: [
33+
keyboardKey.command,
34+
'R'
35+
]
36+
},
37+
{
38+
title: i18n('common.button.createConsole'),
39+
keys: [
40+
keyboardKey.command,
41+
'T'
42+
]
43+
},
44+
{
45+
title: i18n('common.text.executeSelectedSQL'),
46+
keys: [
47+
keyboardKey.command,
48+
'Enter'
49+
]
50+
},
51+
]
52+
53+
export default memo<IProps>(function ShortcutKey(props) {
54+
const { className } = props;
55+
return <div className={classnames(styles.box, className)}>
56+
<div className={styles.letterpress}>
57+
Chat2DB
58+
</div>
59+
<div className={styles.shortcuts}>
60+
{
61+
shortcutsList.map((t, i) => {
62+
return <div key={i} className={styles.shortcutsItem}>
63+
<div className={styles.title}>
64+
{t.title}
65+
</div>
66+
<div>
67+
{t.keys.map((item, i) => {
68+
return <Fragment key={i}>
69+
<span>
70+
{item}
71+
</span>
72+
{
73+
i + 1 < t.keys.length &&
74+
<span className={styles.plusSign}>
75+
+
76+
</span>
77+
}
78+
</Fragment>
79+
})}
80+
</div>
81+
</div>
82+
})
83+
}
84+
</div>
85+
</div>
86+
})

chat2db-client/src/constants/common.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ export enum ConsoleOpenedStatus {
2525
export enum ConsoleStatus {
2626
DRAFT = 'DRAFT',
2727
RELEASE = 'RELEASE',
28-
}
28+
}
29+
30+
export enum OSType {
31+
WIN = 'Win',
32+
MAC = 'Mac',
33+
RESTS = 'rests',
34+
}

chat2db-client/src/i18n/en-us/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@ export default {
6868
'common.button.copyErrorTips':
6969
'(The interface information and detailed parameters will be copied here. If there are sensitive parameters, please parse JSON first and then send them)',
7070
'common.tips.formatError': 'Formatting failed, please check whether the sql is correct',
71+
'common.text.executeSelectedSQL': 'Execute selected SQL',
72+
'common.text.refreshPage': 'Refresh page',
73+
'common.text.saveConsole': 'Save console',
7174
};

chat2db-client/src/i18n/zh-cn/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ export default {
6666
'common.button.copyError': '复制错误报告',
6767
'common.button.copyErrorTips': '(这里会复制接口信息以及详细参数,如有敏感参数,请先解析JSON处理后在发送)',
6868
'common.tips.formatError': '格式化失败,请看sql是否正确',
69+
'common.text.executeSelectedSQL': '执行选中SQL',
70+
'common.text.refreshPage': '刷新页面',
71+
'common.text.saveConsole': '保存控制台',
6972
};

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ const WorkspaceLeft = memo<IProps>(function (props) {
8282
addConsole();
8383
}
8484

85+
useEffect(() => {
86+
document.addEventListener('keydown', (e) => {
87+
console.log(e.metaKey, e.key === 't')
88+
if ((e.ctrlKey || e.metaKey) && e.key === 't') {
89+
e.preventDefault();
90+
addConsole();
91+
}
92+
}, false)
93+
}, [])
94+
8595
return (
8696
<div className={classnames(styles.box, className)}>
8797
<RenderSaveBox></RenderSaveBox>

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@
4646
display: flex;
4747
justify-content: center;
4848
align-items: center;
49-
font-size: 120px;
50-
font-weight: 900;
51-
color: var(--color-text);
52-
opacity: 0.15;
53-
overflow: hidden;
5449
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IConsole, ICreateConsole } from '@/typings';
77
import historyService from '@/service/history';
88
import Tabs, { IOption } from '@/components/Tabs';
99
import LoadingContent from '@/components/Loading/LoadingContent';
10+
import ShortcutKey from '@/components/ShortcutKey';
1011
import WorkspaceRightItem from '../WorkspaceRightItem';
1112
import { IWorkspaceModelState, IWorkspaceModelType } from '@/models/workspace';
1213
import { IAIState } from '@/models/ai';
@@ -188,8 +189,8 @@ const WorkspaceRight = memo<IProps>(function (props) {
188189
// }
189190
};
190191

191-
function render() {
192-
return <div className={styles.ears}>Chat2DB</div>;
192+
function renderEmpty() {
193+
return <div className={styles.ears}><ShortcutKey /></div>;
193194
}
194195

195196
function editableNameOnBlur(t: IOption) {
@@ -221,7 +222,7 @@ const WorkspaceRight = memo<IProps>(function (props) {
221222

222223
return (
223224
<div className={classnames(styles.box, className)}>
224-
<LoadingContent data={openConsoleList} handleEmpty empty={render()}>
225+
<LoadingContent data={openConsoleList} handleEmpty empty={renderEmpty()}>
225226
<div className={styles.tabBox}>
226227
<Tabs
227228
className={styles.tabs}

chat2db-client/src/utils/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ThemeType } from '@/constants';
1+
import { ThemeType, OSType } from '@/constants';
22
import { ITreeNode } from '@/typings';
33
import clipboardCopy from 'copy-to-clipboard';
44
import lodash from 'lodash';
@@ -216,3 +216,17 @@ export function getApplicationMessage() {
216216
}
217217
}
218218

219+
// os is mac or windows
220+
export function OSnow(): {
221+
isMac: boolean;
222+
isWin: boolean;
223+
} {
224+
const agent = navigator.userAgent.toLowerCase();
225+
const isMac = /macintosh|mac os x/i.test(navigator.userAgent);
226+
const isWin = agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0 || agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0
227+
return {
228+
isMac,
229+
isWin
230+
}
231+
}
232+

0 commit comments

Comments
 (0)