Skip to content

Commit ea6176e

Browse files
committed
fix api test
1 parent 2774ded commit ea6176e

File tree

2 files changed

+70
-45
lines changed

2 files changed

+70
-45
lines changed

components-ui/src/page/Api/docs.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const Docs: React.FC = () => {
6868
var res = $jpa.listQuery(com.example.entity.NodeEntity.class,"from NodeEntity");
6969
// 查询有条件的数据
7070
var res = $jpa.listQuery(com.example.entity.NodeEntity.class,"from NodeEntity where name = ?",name);
71+
// 查询有条件的分页查询
72+
var res = $jpa.pageQuery(com.example.entity.NodeEntity.class,"from NodeEntity where name = ?",pageRequest,name);
73+
// 查询有条件的分页查询(自定义总数)
74+
var res = $jpa.pageQuery(com.example.entity.NodeEntity.class,"select n from NodeEntity n where name = ?","select count(n) from NodeEntity n where name = ?",pageRequest,name);
7175
`}
7276
</code>
7377
</pre>

components-ui/src/page/Api/index.tsx

+66-45
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { Editor } from '@monaco-editor/react';
99

1010
interface ApiPageProps {
1111

12-
list(params:any, sort?:any, filter?:any): Promise<any>;
12+
list(params: any, sort?: any, filter?: any): Promise<any>;
1313

14-
save(params:any): Promise<any>;
14+
save(params: any): Promise<any>;
1515

16-
del(params:any): Promise<any>;
16+
del(params: any): Promise<any>;
1717

18-
test(params:any): Promise<any>;
18+
test(params: any): Promise<any>;
1919
}
2020

2121
export const ApiPage: React.FC<ApiPageProps> = (props) => {
@@ -32,10 +32,10 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
3232
try {
3333
//@ts-ignore
3434
const script = editorRef.current?.getValue();
35-
await props.save({
35+
await props.save({
3636
...fields,
3737
script: script
38-
});
38+
});
3939
hide();
4040
message.success('保存成功');
4141
handleModalOpen(false);
@@ -53,8 +53,10 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
5353

5454
const handleTest = async (fields: any) => {
5555
const hide = message.loading('正在测试');
56-
try {
57-
const res = await props.test({ ...fields });
56+
try {
57+
const res = await props.test({
58+
...fields,
59+
});
5860
const json = JSON.stringify(res);
5961
api["success"]({
6062
"message": json,
@@ -148,8 +150,6 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
148150
for (let key in record) {
149151
form.setFieldValue(key, record[key])
150152
}
151-
// @ts-ignore
152-
editorRef.current?.setValue(record.script);
153153
handleModalOpen(true);
154154
}}
155155
>
@@ -158,7 +158,7 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
158158
<a
159159
key="test"
160160
onClick={() => {
161-
// eslint-disable-next-line guard-for-in
161+
// eslint-disable-next-line guard-for-in
162162
handleTest(record);
163163
}}
164164
>
@@ -183,23 +183,48 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
183183
];
184184

185185

186-
function handleEditorDidMount(editor:any, monaco:any) {
186+
function handleEditorDidMount(editor: any, monaco: any) {
187187
editorRef.current = editor;
188188

189189
//@ts-ignore
190190
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+
}
203228

204229
});
205230
}
@@ -273,7 +298,12 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
273298
key="test"
274299
onClick={() => {
275300
const fields = form.getFieldsValue();
276-
handleTest(fields);
301+
//@ts-ignore
302+
const script = editorRef.current?.getValue();
303+
handleTest({
304+
...fields,
305+
script
306+
});
277307
}}
278308
>
279309
测试
@@ -344,27 +374,18 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
344374
name="url" />
345375
</ProForm.Group>
346376

347-
{/* <ProFormTextArea
377+
<ProForm.Item
348378
label="接口脚本(Groovy脚本)"
349379
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>
368389

369390
<ProFormSelect
370391
placeholder="请输入接口状态"
@@ -412,7 +433,7 @@ export const ApiPage: React.FC<ApiPageProps> = (props) => {
412433
setReadmeVisible(false);
413434
}}
414435
>
415-
<Docs/>
436+
<Docs />
416437
</Drawer>
417438

418439
</div >

0 commit comments

Comments
 (0)