|
1 | 1 | import React, { memo, useRef, useState, createContext, useEffect, useMemo } from 'react'; |
2 | | -import { Button } from 'antd'; |
| 2 | +import { Button, Modal, message } from 'antd'; |
3 | 3 | import styles from './index.less'; |
4 | 4 | import classnames from 'classnames'; |
5 | 5 | import IndexList, { IIndexListRef } from './IndexList'; |
6 | 6 | import ColumnList, { IColumnListRef } from './ColumnList'; |
7 | 7 | import BaseInfo, { IBaseInfoRef } from './BaseInfo'; |
8 | | -import sqlService, { IModifyTableSqlParams } from '@/service/sql'; |
| 8 | +import sqlService, { IModifyTableSqlParams, IExecuteSqlParams } from '@/service/sql'; |
| 9 | +import MonacoEditor from '@/components/Console/MonacoEditor'; |
9 | 10 | import { IEditTableInfo } from '@/typings'; |
10 | 11 | import i18n from '@/i18n'; |
11 | 12 | import lodash from 'lodash'; |
@@ -36,6 +37,7 @@ export default memo((props: IProps) => { |
36 | 37 | const { databaseName, dataSourceId, tableName, schemaName } = props; |
37 | 38 | const [tableDetails, setTableDetails] = useState<IEditTableInfo>({} as any); |
38 | 39 | const [oldTableDetails, setOldTableDetails] = useState<IEditTableInfo>({} as any); |
| 40 | + const [viewSqlModal, setViewSqlModal] = useState<string | false>(false); |
39 | 41 | const baseInfoRef = useRef<IBaseInfoRef>(null); |
40 | 42 | const columnListRef = useRef<IColumnListRef>(null); |
41 | 43 | const indexListRef = useRef<IIndexListRef>(null); |
@@ -114,14 +116,27 @@ export default memo((props: IProps) => { |
114 | 116 | params.tableName = tableName; |
115 | 117 | params.oldTable = oldTableDetails; |
116 | 118 | } |
117 | | - console.log(newTable); |
118 | | - console.log(params.oldTable); |
119 | 119 | sqlService.getModifyTableSql(params).then((res) => { |
120 | | - console.log(res); |
| 120 | + setViewSqlModal(res?.[0].sql); |
121 | 121 | }); |
122 | 122 | } |
123 | 123 | } |
124 | 124 |
|
| 125 | + const executeSql = () => { |
| 126 | + const executeSQLParams: IExecuteSqlParams = { |
| 127 | + sql: viewSqlModal || '', |
| 128 | + dataSourceId, |
| 129 | + databaseName, |
| 130 | + schemaName, |
| 131 | + }; |
| 132 | + |
| 133 | + // 获取当前SQL的查询结果 |
| 134 | + sqlService.executeSql(executeSQLParams).then((res) => { |
| 135 | + message.success('修改成功'); |
| 136 | + setViewSqlModal(false); |
| 137 | + }); |
| 138 | + }; |
| 139 | + |
125 | 140 | return ( |
126 | 141 | <Context.Provider |
127 | 142 | value={{ |
@@ -163,6 +178,27 @@ export default memo((props: IProps) => { |
163 | 178 | })} |
164 | 179 | </div> |
165 | 180 | </div> |
| 181 | + <Modal |
| 182 | + title="sql预览" |
| 183 | + open={!!viewSqlModal} |
| 184 | + onCancel={() => { |
| 185 | + setViewSqlModal(false); |
| 186 | + }} |
| 187 | + okText="执行" |
| 188 | + onOk={executeSql} |
| 189 | + width="60vw" |
| 190 | + maskClosable={false} |
| 191 | + > |
| 192 | + <div className={styles.monacoEditor}> |
| 193 | + <MonacoEditor |
| 194 | + id="view_sql" |
| 195 | + appendValue={{ |
| 196 | + text: viewSqlModal, |
| 197 | + range: 'reset', |
| 198 | + }} |
| 199 | + /> |
| 200 | + </div> |
| 201 | + </Modal> |
166 | 202 | </Context.Provider> |
167 | 203 | ); |
168 | 204 | }); |
0 commit comments