@@ -34,7 +34,7 @@ enum IPromptTypeText {
3434export type IAppendValue = {
3535 text : any ;
3636 range ?: IRangeType ;
37- }
37+ } ;
3838
3939interface IProps {
4040 /** 是否是活跃的console,用于快捷键 */
@@ -44,23 +44,34 @@ interface IProps {
4444 /** 是否开启AI输入 */
4545 hasAiChat : boolean ;
4646 /** 是否可以开启SQL转到自然语言的相关ai操作 */
47- hasAi2Lang : boolean ;
48- /** 运行或保存sql需要的父级参数 */
47+ hasAi2Lang ?: boolean ;
48+ hasSaveBtn ?: boolean ;
49+ value ?: string ;
50+ onChangeValue ?: Function ;
4951 executeParams : {
50- databaseName : string ;
51- dataSourceId : number ;
52- type : DatabaseTypeCode ;
53- consoleId : number ;
52+ databaseName ? : string ;
53+ dataSourceId ? : number ;
54+ type ? : DatabaseTypeCode ;
55+ consoleId ? : number ;
5456 schemaName ?: string ;
55- consoleName : string ;
57+ consoleName ? : string ;
5658 } ;
5759 onExecuteSQL : ( value : any ) => void ;
5860 workspaceModel : IWorkspaceModelType ;
5961 dispatch : any ;
6062}
6163
62- function Console ( props : IProps , ref : any ) {
63- const { hasAiChat = true , executeParams, appendValue, isActive, dispatch } = props ;
64+ function Console ( props : IProps ) {
65+ const {
66+ hasAiChat = true ,
67+ executeParams,
68+ appendValue,
69+ isActive,
70+ dispatch,
71+ hasSaveBtn = true ,
72+ value,
73+ onChangeValue,
74+ } = props ;
6475 const uid = useMemo ( ( ) => uuidv4 ( ) , [ ] ) ;
6576 const chatResult = useRef ( '' ) ;
6677 const editorRef = useRef < IExportRefFunction > ( ) ;
@@ -70,7 +81,7 @@ function Console(props: IProps, ref: any) {
7081 if ( appendValue ) {
7182 editorRef ?. current ?. setValue ( appendValue . text , appendValue . range ) ;
7283 }
73- } , [ appendValue ] )
84+ } , [ appendValue ] ) ;
7485
7586 const onPressChatInput = ( value : string ) => {
7687 const params = formatParams ( {
@@ -99,7 +110,7 @@ function Console(props: IProps, ref: any) {
99110 } ;
100111
101112 const closeEventSource = connectToEventSource ( {
102- url : `/api/ai/chat1 ?${ params } ` ,
113+ url : `/api/ai/chat ?${ params } ` ,
103114 uid,
104115 onMessage : handleMessage ,
105116 onError : handleError ,
@@ -133,41 +144,44 @@ function Console(props: IProps, ref: any) {
133144 } ;
134145
135146 const saveConsole = ( value ?: string ) => {
136- const a = editorRef . current ?. getAllContent ( )
147+ const a = editorRef . current ?. getAllContent ( ) ;
137148
138149 let p = {
139150 id : executeParams . consoleId ,
140- status : ConsoleStatus . RELEASE
151+ status : ConsoleStatus . RELEASE ,
141152 } ;
142153 historyServer . updateSavedConsole ( p ) . then ( ( res ) => {
143154 message . success ( '保存成功' ) ;
144155 dispatch ( {
145- type : 'workspace/fetchGetSavedConsole'
146- } )
156+ type : 'workspace/fetchGetSavedConsole' ,
157+ } ) ;
147158 // notification.open({
148159 // type: 'success',
149160 // message: '保存成功',
150161 // });
151162 } ) ;
152163 } ;
153164
154- const addAction = useMemo ( ( ) => ( [
155- {
156- id : 'explainSQL' ,
157- label : '解释SQL' ,
158- action : ( selectedText : string ) => handleAIRelativeOperation ( IPromptType . SQL_EXPLAIN , selectedText ) ,
159- } ,
160- {
161- id : 'optimizeSQL' ,
162- label : '优化SQL' ,
163- action : ( selectedText : string ) => handleAIRelativeOperation ( IPromptType . SQL_OPTIMIZER , selectedText ) ,
164- } ,
165- {
166- id : 'changeSQL' ,
167- label : 'SQL转化' ,
168- action : ( selectedText : string ) => handleAIRelativeOperation ( IPromptType . SQL_2_SQL , selectedText ) ,
169- } ,
170- ] ) , [ ] )
165+ const addAction = useMemo (
166+ ( ) => [
167+ {
168+ id : 'explainSQL' ,
169+ label : '解释SQL' ,
170+ action : ( selectedText : string ) => handleAIRelativeOperation ( IPromptType . SQL_EXPLAIN , selectedText ) ,
171+ } ,
172+ {
173+ id : 'optimizeSQL' ,
174+ label : '优化SQL' ,
175+ action : ( selectedText : string ) => handleAIRelativeOperation ( IPromptType . SQL_OPTIMIZER , selectedText ) ,
176+ } ,
177+ {
178+ id : 'changeSQL' ,
179+ label : 'SQL转化' ,
180+ action : ( selectedText : string ) => handleAIRelativeOperation ( IPromptType . SQL_2_SQL , selectedText ) ,
181+ } ,
182+ ] ,
183+ [ ] ,
184+ ) ;
171185
172186 const handleAIRelativeOperation = ( id : string , selectedText : string ) => {
173187 console . log ( 'handleAIRelativeOperation' , id , selectedText ) ;
@@ -191,12 +205,14 @@ function Console(props: IProps, ref: any) {
191205 < div className = { styles . console_options_wrapper } >
192206 < div className = { styles . console_options_left } >
193207 < Button type = "primary" className = { styles . run_button } onClick = { executeSQL } >
194- < Iconfont code = ' ' />
208+ < Iconfont code = " " />
195209 RUN
196210 </ Button >
197- < Button type = "default" className = { styles . save_button } onClick = { ( ) => { saveConsole ( ) } } >
198- SAVE
199- </ Button >
211+ { hasSaveBtn && (
212+ < Button type = "default" className = { styles . save_button } onClick = { ( ) => saveConsole ( ) } >
213+ SAVE
214+ </ Button >
215+ ) }
200216 </ div >
201217 < Button
202218 type = "text"
@@ -213,7 +229,7 @@ function Console(props: IProps, ref: any) {
213229}
214230
215231const dvaModel = connect ( ( { workspace } : { workspace : IWorkspaceModelType } ) => ( {
216- workspaceModel : workspace
217- } ) )
232+ workspaceModel : workspace ,
233+ } ) ) ;
218234
219235export default dvaModel ( Console ) ;
0 commit comments