Skip to content

Commit 79a0931

Browse files
committed
执行结果
1 parent 8f6f6e2 commit 79a0931

10 files changed

Lines changed: 111 additions & 75 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
6464
editorRef.current = editorIns;
6565
didMount && didMount(editorIns);
6666

67+
const { colorPrimary } = window._AppThemePack;
68+
const colors = {
69+
'editor.lineHighlightBackground': colorPrimary + '14', // 当前行背景色
70+
'editor.selectionBackground': colorPrimary + '20', // 选中文本的背景色
71+
// 'editorLineNumber.foreground': colorPrimary, // 行号颜色
72+
'editorLineNumber.activeForeground': colorPrimary, // 当前行号颜色
73+
// 'editorCursor.foreground': colorPrimary, // 光标颜色
74+
};
6775
monaco.editor.defineTheme(ThemeType.Light, {
6876
base: 'vs',
6977
inherit: true,
7078
rules: [{ background: '#15161a' }] as any,
7179
colors: {
80+
...colors,
7281
'editor.foreground': '#000000',
7382
'editor.background': '#fff', //背景色
7483
},
@@ -79,7 +88,6 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
7988
inherit: true,
8089
rules: [{ background: '#15161a' }] as any,
8190
colors: {
82-
// 相关颜色属性配置
8391
'editor.foreground': '#ffffff',
8492
'editor.background': '#0A0B0C', //背景色
8593
},
@@ -89,7 +97,6 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
8997
inherit: true,
9098
rules: [{ background: '#15161a' }] as any,
9199
colors: {
92-
// 相关颜色属性配置
93100
'editor.foreground': '#ffffff',
94101
'editor.background': '#1c2128', //背景色
95102
},
@@ -100,6 +107,7 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
100107
inherit: true,
101108
rules: [{ background: '#15161a' }] as any,
102109
colors: {
110+
...colors,
103111
'editor.foreground': '#000000',
104112
'editor.background': '#f8f9fa', //背景色
105113
},
@@ -253,6 +261,7 @@ export const appendMonacoValue = (editor: any, text: any, range: IRangeType = 'e
253261
case 'front':
254262
newRange = new monaco.Range(1, 1, 1, 1);
255263
editor.revealLine(1);
264+
editor.setPosition({ lineNumber: 1, column: 1 });
256265
break;
257266
// 格式化选中区域的sql
258267
case 'select': {
@@ -270,7 +279,7 @@ export const appendMonacoValue = (editor: any, text: any, range: IRangeType = 'e
270279
// 在末尾添加内容
271280
case 'end':
272281
newRange = new monaco.Range(lastLine, lastLineLength, lastLine, lastLineLength);
273-
newText = `${text}`;
282+
newText = `\n${text}`;
274283
break;
275284
default:
276285
break;
@@ -287,6 +296,7 @@ export const appendMonacoValue = (editor: any, text: any, range: IRangeType = 'e
287296
if (range === 'end') {
288297
setTimeout(() => {
289298
editor.revealLine(lastLine + 1);
299+
editor.setPosition({ lineNumber: lastLine + 1, column: 1 });
290300
}, 0);
291301
}
292302
};

chat2db-client/src/components/SearchResult/TableBox/index.less

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
@import '../../../styles/var.less';
22

33
.tableBox {
4-
position: absolute;
5-
top: 0;
6-
left: 0;
7-
right: 0;
8-
bottom: 0;
4+
height: calc(100% - 26px);
95
overflow: auto;
106
display: flex;
117
flex-direction: column;
@@ -120,25 +116,6 @@
120116
flex: 1;
121117
}
122118

123-
.statusBar {
124-
height: 26px;
125-
box-sizing: border-box;
126-
position: sticky;
127-
bottom: 0;
128-
z-index: 30;
129-
padding: 4px 8px;
130-
font-size: 12px;
131-
display: flex;
132-
justify-content: start;
133-
align-items: center;
134-
border-top: 1px solid var(--color-border-secondary);
135-
background-color: var(--color-bg-subtle);
136-
137-
& > span {
138-
margin-right: 16px;
139-
}
140-
}
141-
142119
.tableItem {
143120
width: calc(100% + 8px);
144121
height: 100%;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ export default function TableBox(props: ITableProps) {
742742
{...pipeline.getProps()}
743743
/>
744744
)}
745-
{bottomStatus}
745+
{/* {bottomStatus} */}
746746
</>
747747
);
748748
}

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,41 @@
5757
font-size: 12px;
5858
}
5959

60-
.outputPrefixIcon{
60+
.outputPrefixIcon {
6161
margin-right: 4px;
6262
}
6363

64-
.stateIndicator{
64+
.stateIndicator {
6565
width: 70%;
6666
margin: 0 auto;
6767
}
68+
69+
.successResult {
70+
height: 100%;
71+
.successResultContent {
72+
height: calc(100% - 26px);
73+
}
74+
75+
.updateCount {
76+
height: 100%;
77+
display: flex;
78+
justify-content: center;
79+
align-items: center;
80+
}
81+
}
82+
83+
.statusBar {
84+
height: 26px;
85+
box-sizing: border-box;
86+
padding: 4px 8px;
87+
font-size: 12px;
88+
display: flex;
89+
justify-content: start;
90+
align-items: center;
91+
border-top: 1px solid var(--color-border-secondary);
92+
background-color: var(--color-bg-subtle);
93+
94+
& > span {
95+
margin-right: 16px;
96+
}
97+
}

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

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,48 @@ export default memo<IProps>((props) => {
2929
// setCurrentTab(uuid);
3030
}, []);
3131

32-
const renderTable = (queryResultData) => {
33-
if (queryResultData.success) {
32+
const renderResult = (queryResultData) => {
33+
function renderSuccessResult() {
34+
const needTable = queryResultData?.headerList?.length > 1;
3435
return (
35-
<TableBox
36-
key={queryResultData.uuid}
37-
outerQueryResultData={queryResultData}
38-
executeSqlParams={props.executeSqlParams}
39-
/>
40-
);
41-
} else {
42-
return (
43-
<StateIndicator
44-
className={styles.stateIndicator}
45-
key={queryResultData.uuid}
46-
state="error"
47-
text={queryResultData.message}
48-
/>
36+
<div className={styles.successResult}>
37+
<div className={styles.successResultContent}>
38+
{needTable ? (
39+
<TableBox
40+
key={queryResultData.uuid}
41+
outerQueryResultData={queryResultData}
42+
executeSqlParams={props.executeSqlParams}
43+
/>
44+
) : (
45+
<div className={styles.updateCount}>{i18n('common.text.affectedRows', queryResultData.updateCount)}</div>
46+
)}
47+
</div>
48+
<div className={styles.statusBar}>
49+
<span>{`【${i18n('common.text.result')}${queryResultData.description}.`}</span>
50+
<span>{`【${i18n('common.text.timeConsuming')}${queryResultData.duration}ms.`}</span>
51+
{queryResultData?.dataList?.length && (
52+
<span>{`【${i18n('common.text.searchRow')}${queryResultData?.dataList?.length} ${i18n(
53+
'common.text.row',
54+
)}.`}</span>
55+
)}
56+
</div>
57+
</div>
4958
);
5059
}
60+
return (
61+
<>
62+
{queryResultData.success ? (
63+
renderSuccessResult()
64+
) : (
65+
<StateIndicator
66+
className={styles.stateIndicator}
67+
key={queryResultData.uuid}
68+
state="error"
69+
text={queryResultData.message}
70+
/>
71+
)}
72+
</>
73+
);
5174
};
5275

5376
const tabsList = useMemo(() => {
@@ -63,7 +86,7 @@ export default memo<IProps>((props) => {
6386
popover: queryResultData.originalSql,
6487
label: queryResultData.originalSql,
6588
key: queryResultData.uuid!,
66-
children: renderTable(queryResultData),
89+
children: renderResult(queryResultData),
6790
};
6891
});
6992
}, [resultDataList]);

chat2db-client/src/components/StateIndicator/index.less

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
display: flex;
66
justify-content: center;
77
align-items: center;
8-
position: absolute;
9-
left: 0;
10-
right: 0;
11-
top: 0;
12-
bottom: 0;
138
}
149

1510
.empty {

chat2db-client/src/constants/monacoEditor.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ import { IEditorOptions } from '@/components/Console/MonacoEditor';
22

33
export const editorDefaultOptions: IEditorOptions = {
44
fontFamily: `"Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace`,
5-
scrollBeyondLastLine: false,
6-
automaticLayout: true,
7-
dragAndDrop: false,
8-
fontSize: 12,
9-
tabSize: 2,
10-
lineHeight: 18,
11-
theme: 'vscode',
12-
roundedSelection: false,
13-
readOnly: false,
5+
scrollBeyondLastLine: false, // 滚动超过最后一行
6+
automaticLayout: true, // 自动布局
7+
dragAndDrop: false, // 拖拽
8+
fontSize: 12, // 字体大小
9+
tabSize: 2, // tab大小
10+
lineHeight: 18, // 行高
11+
theme: 'vscode', // 主题
12+
roundedSelection: false, // 圆角选择
13+
readOnly: false, // 只读
1414
folding: false, // 不显示折叠
15-
insertSpaces: true,
16-
autoClosingQuotes: 'always',
17-
detectIndentation: false,
18-
wordWrap: 'on',
19-
fixedOverflowWidgets: true,
20-
renderLineHighlight: 'none',
21-
codeLens: false,
22-
scrollbar: {
23-
alwaysConsumeMouseWheel: false,
15+
insertSpaces: true, // 插入空格
16+
autoClosingQuotes: 'always', // 自动闭合引号
17+
detectIndentation: false, // 检测缩进
18+
wordWrap: 'on', // 自动换行
19+
fixedOverflowWidgets: true, // 固定溢出小部件
20+
// renderLineHighlight: 'none', // 渲染行高亮
21+
codeLens: false, // 代码镜头
22+
scrollbar: { // 滚动条
23+
alwaysConsumeMouseWheel: false, // 总是消耗鼠标滚轮
2424
},
25-
padding: {
25+
padding: {
2626
top: 2,
2727
bottom: 2,
2828
},
29-
minimap: {
30-
enabled: false,
29+
minimap: { // 缩略图
30+
enabled: false, // 启用
3131
},
3232
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ export default {
8989
'common.text.errorMessage': 'Error Message',
9090
'common.button.cancelRequest': 'Cancel Request',
9191
'common.button.executionError': 'Execution Error',
92-
92+
'common.text.affectedRows': 'Affected rows: {1}',
9393
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ export default {
8787
'common.text.errorMessage': '错误信息',
8888
'common.button.cancelRequest': '取消请求',
8989
'common.button.executionError': '执行错误',
90-
90+
'common.text.affectedRows': '受影响行:{1}',
9191
};

chat2db-client/src/typings/database.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface IManageResultData {
2525
fuzzyTotal: string;
2626
hasNextPage: boolean;
2727
sqlType: 'SELECT' | 'UNKNOWN';
28+
updateCount?: number; // 如果是修改的话。后端会返回修改的条数
2829
canEdit?: boolean; // 返回的数据是否可以编辑
2930
tableName?: string; // 如果可以编辑的话。后端会返回表名称。修改需要给后端传递表名
3031
}

0 commit comments

Comments
 (0)