@@ -9,13 +9,13 @@ import { Editor } from '@monaco-editor/react';
9
9
10
10
interface ApiPageProps {
11
11
12
- list ( params :any , sort ?:any , filter ?:any ) : Promise < any > ;
12
+ list ( params : any , sort ?: any , filter ?: any ) : Promise < any > ;
13
13
14
- save ( params :any ) : Promise < any > ;
14
+ save ( params : any ) : Promise < any > ;
15
15
16
- del ( params :any ) : Promise < any > ;
16
+ del ( params : any ) : Promise < any > ;
17
17
18
- test ( params :any ) : Promise < any > ;
18
+ test ( params : any ) : Promise < any > ;
19
19
}
20
20
21
21
export const ApiPage : React . FC < ApiPageProps > = ( props ) => {
@@ -32,10 +32,10 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
32
32
try {
33
33
//@ts -ignore
34
34
const script = editorRef . current ?. getValue ( ) ;
35
- await props . save ( {
35
+ await props . save ( {
36
36
...fields ,
37
37
script : script
38
- } ) ;
38
+ } ) ;
39
39
hide ( ) ;
40
40
message . success ( '保存成功' ) ;
41
41
handleModalOpen ( false ) ;
@@ -53,8 +53,10 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
53
53
54
54
const handleTest = async ( fields : any ) => {
55
55
const hide = message . loading ( '正在测试' ) ;
56
- try {
57
- const res = await props . test ( { ...fields } ) ;
56
+ try {
57
+ const res = await props . test ( {
58
+ ...fields ,
59
+ } ) ;
58
60
const json = JSON . stringify ( res ) ;
59
61
api [ "success" ] ( {
60
62
"message" : json ,
@@ -148,8 +150,6 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
148
150
for ( let key in record ) {
149
151
form . setFieldValue ( key , record [ key ] )
150
152
}
151
- // @ts -ignore
152
- editorRef . current ?. setValue ( record . script ) ;
153
153
handleModalOpen ( true ) ;
154
154
} }
155
155
>
@@ -158,7 +158,7 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
158
158
< a
159
159
key = "test"
160
160
onClick = { ( ) => {
161
- // eslint-disable-next-line guard-for-in
161
+ // eslint-disable-next-line guard-for-in
162
162
handleTest ( record ) ;
163
163
} }
164
164
>
@@ -183,23 +183,48 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
183
183
] ;
184
184
185
185
186
- function handleEditorDidMount ( editor :any , monaco :any ) {
186
+ function handleEditorDidMount ( editor : any , monaco : any ) {
187
187
editorRef . current = editor ;
188
188
189
189
//@ts -ignore
190
190
monaco . languages . registerCompletionItemProvider ( 'javascript' , {
191
- triggerCharacters : [ '$' ] ,
192
- provideCompletionItems : function ( model :any , position :any ) {
193
- return {
194
- suggestions : [
195
- {
196
- label : '$jdbc.queryForList' ,
197
- kind : monaco . languages . CompletionItemKind . Text ,
198
- insertText : '$jdbc.queryForList({sql},{params})' ,
199
- }
200
- ]
201
- } ;
202
- }
191
+ triggerCharacters : [ '$' ] ,
192
+ provideCompletionItems : function ( model : any , position : any ) {
193
+ return {
194
+ suggestions : [
195
+ {
196
+ label : '$jdbc.queryForList' ,
197
+ kind : monaco . languages . CompletionItemKind . Function ,
198
+ insertText : '$jdbc.queryForList(sql,params)' ,
199
+ } ,
200
+ {
201
+ label : '$jdbc.queryForPage' ,
202
+ kind : monaco . languages . CompletionItemKind . Function ,
203
+ insertText : '$jdbc.queryForPage(sql,countSQL,pageRequest,params)' ,
204
+ } ,
205
+ {
206
+ label : '$request.getParameter' ,
207
+ kind : monaco . languages . CompletionItemKind . Function ,
208
+ insertText : '$request.getParameter(key,defaultValue)' ,
209
+ } ,
210
+ {
211
+ label : '$request.pageRequest' ,
212
+ kind : monaco . languages . CompletionItemKind . Function ,
213
+ insertText : '$request.pageRequest(current,pageSize)' ,
214
+ } ,
215
+ {
216
+ label : '$jpa.listQuery' ,
217
+ kind : monaco . languages . CompletionItemKind . Function ,
218
+ insertText : '$jpa.listQuery(entityClass,hsql,params)' ,
219
+ } ,
220
+ {
221
+ label : '$jpa.pageQuery' ,
222
+ kind : monaco . languages . CompletionItemKind . Function ,
223
+ insertText : '$jpa.pageQuery(entityClass,hsql,countHsql,pageRequest,params)' ,
224
+ }
225
+ ]
226
+ } ;
227
+ }
203
228
204
229
} ) ;
205
230
}
@@ -273,7 +298,12 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
273
298
key = "test"
274
299
onClick = { ( ) => {
275
300
const fields = form . getFieldsValue ( ) ;
276
- handleTest ( fields ) ;
301
+ //@ts -ignore
302
+ const script = editorRef . current ?. getValue ( ) ;
303
+ handleTest ( {
304
+ ...fields ,
305
+ script
306
+ } ) ;
277
307
} }
278
308
>
279
309
测试
@@ -344,27 +374,18 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
344
374
name = "url" />
345
375
</ ProForm . Group >
346
376
347
- { /* <ProFormTextArea
377
+ < ProForm . Item
348
378
label = "接口脚本(Groovy脚本)"
349
379
help = { < a onClick = { ( ) => setReadmeVisible ( true ) } > 脚本手册</ a > }
350
- fieldProps={{
351
- rows: 12,
352
- }}
353
- rules={[
354
- {
355
- required: true,
356
- message: "请输入接口脚本",
357
- },
358
- ]}
359
- placeholder="请输入接口脚本"
360
- name="script" /> */ }
361
-
362
- < Editor
363
- height = "30vh"
364
- theme = "vs-dark"
365
- defaultLanguage = "javascript"
366
- onMount = { handleEditorDidMount }
367
- />
380
+ >
381
+ < Editor
382
+ height = "30vh"
383
+ theme = "vs-dark"
384
+ defaultLanguage = "javascript"
385
+ defaultValue = { form . getFieldValue ( "script" ) }
386
+ onMount = { handleEditorDidMount }
387
+ />
388
+ </ ProForm . Item >
368
389
369
390
< ProFormSelect
370
391
placeholder = "请输入接口状态"
@@ -412,7 +433,7 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
412
433
setReadmeVisible ( false ) ;
413
434
} }
414
435
>
415
- < Docs />
436
+ < Docs />
416
437
</ Drawer >
417
438
418
439
</ div >
0 commit comments