@@ -5,7 +5,6 @@ import connectToEventSource from '@/utils/eventSource';
55import { Button , Spin , message , Drawer , Modal } from 'antd' ;
66import ChatInput from './ChatInput' ;
77import Editor , { IEditorOptions , IExportRefFunction , IRangeType } from './MonacoEditor' ;
8- import { format } from 'sql-formatter' ;
98import historyServer from '@/service/history' ;
109import aiServer from '@/service/ai' ;
1110import { v4 as uuidv4 } from 'uuid' ;
@@ -14,7 +13,7 @@ import Iconfont from '../Iconfont';
1413import { IAiConfig , ITreeNode } from '@/typings' ;
1514import { IAIState } from '@/models/ai' ;
1615import Popularize from '@/components/Popularize' ;
17- import { handleLocalStorageSavedConsole , readLocalStorageSavedConsoleText } from '@/utils' ;
16+ import { handleLocalStorageSavedConsole , readLocalStorageSavedConsoleText , formatSql } from '@/utils' ;
1817import { chatErrorForKey , chatErrorToLogin } from '@/constants/chat' ;
1918import { AiSqlSourceType } from '@/typings/ai' ;
2019import i18n from '@/i18n' ;
@@ -162,7 +161,7 @@ function Console(props: IProps) {
162161 function timingAutoSave ( ) {
163162 timerRef . current = setInterval ( ( ) => {
164163 handleLocalStorageSavedConsole ( executeParams . consoleId ! , 'save' , editorRef ?. current ?. getAllContent ( ) ) ;
165- } , 5000 ) ;
164+ } , 500 ) ;
166165 }
167166
168167 const tableListName = useMemo ( ( ) => {
@@ -213,7 +212,7 @@ function Console(props: IProps) {
213212 }
214213 } , 3000 ) ;
215214 }
216- } catch ( e ) {
215+ } catch ( e ) {
217216 setIsLoading ( false ) ;
218217 }
219218
@@ -471,17 +470,11 @@ function Console(props: IProps) {
471470 < Button
472471 type = "text"
473472 onClick = { ( ) => {
474- let formatRes = '' ;
475- try {
476- const contextTmp = editorRef ?. current ?. getAllContent ( ) ;
477- formatRes = format ( contextTmp || '' ) ;
478- }
479- catch { }
480- if ( formatRes ) {
481- editorRef ?. current ?. setValue ( formatRes , 'cover' ) ;
482- } else {
483- message . error ( i18n ( 'common.tips.formatError' ) )
484- }
473+ // 格式化sql
474+ const sql = editorRef ?. current ?. getCurrentSelectContent ( ) || ''
475+ formatSql ( sql , executeParams . type ! ) . then ( ( res ) => {
476+ editorRef ?. current ?. setValue ( res , 'select' ) ;
477+ } ) ;
485478 } }
486479 >
487480 { i18n ( 'common.button.format' ) }
0 commit comments