修复 api 示例无法显示问题

Change-Id: Idc55248ad7475e48749030350aed8c08cfe48b2c
This commit is contained in:
nwind 2022-08-01 15:44:46 +08:00
parent 177b417f99
commit 45e7a3b5bc
6 changed files with 14 additions and 50 deletions

View File

@ -85,34 +85,6 @@ export class CRUDPlugin extends BasePlugin {
} }
]; ];
sampleBuilder = (schema: any) => {
const data: any = {
items: [],
total: 0
};
if (Array.isArray(schema?.columns)) {
const item = {};
schema.columns.forEach((control: any) => {
if (control?.name) {
setVariable(item, control.name, 'sample');
}
});
data.items.push(item);
}
return JSON.stringify(
{
status: 0,
msg: '',
data: data
},
null,
2
);
};
btnSchemas = { btnSchemas = {
create: { create: {
label: '新增', label: '新增',

View File

@ -10,10 +10,7 @@ import {
import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {defaultValue, getSchemaTpl} from 'amis-editor-core';
import {jsonToJsonSchema} from 'amis-editor-core'; import {jsonToJsonSchema} from 'amis-editor-core';
import {EditorNodeType} from 'amis-editor-core'; import {EditorNodeType} from 'amis-editor-core';
import { import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
RendererPluginAction,
RendererPluginEvent
} from 'amis-editor-core';
import {setVariable} from 'amis-core'; import {setVariable} from 'amis-core';
import {getEventControlConfig} from '../../renderer/event-control/helper'; import {getEventControlConfig} from '../../renderer/event-control/helper';
@ -540,7 +537,7 @@ export class FormPlugin extends BasePlugin {
getSchemaTpl('api', { getSchemaTpl('api', {
label: '保存接口', label: '保存接口',
description: '用来保存表单数据', description: '用来保存表单数据',
sampleBuilder: (schema: any) => `{ sampleBuilder: () => `{
"status": 0, "status": 0,
"msg": "", "msg": "",
@ -582,10 +579,11 @@ export class FormPlugin extends BasePlugin {
name: 'initApi', name: 'initApi',
label: '初始化接口', label: '初始化接口',
description: '用来初始化表单数据', description: '用来初始化表单数据',
sampleBuilder: (schema: any) => { sampleBuilder: () => {
const data = {}; const data = {};
const schema = context?.schema;
if (Array.isArray(schema.body)) { if (Array.isArray(schema?.body)) {
schema.body.forEach((control: any) => { schema.body.forEach((control: any) => {
if ( if (
control.name && control.name &&

View File

@ -279,7 +279,7 @@ export class TreeControlPlugin extends BasePlugin {
name: 'options' name: 'options'
}, },
getSchemaTpl('source', { getSchemaTpl('source', {
sampleBuilder: (schema: any) => sampleBuilder: () =>
JSON.stringify( JSON.stringify(
{ {
status: 0, status: 0,

View File

@ -1,7 +1,4 @@
import { import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
RendererPluginAction,
RendererPluginEvent
} from 'amis-editor-core';
import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {defaultValue, getSchemaTpl} from 'amis-editor-core';
import {registerEditorPlugin} from 'amis-editor-core'; import {registerEditorPlugin} from 'amis-editor-core';
import {BaseEventContext, BasePlugin} from 'amis-editor-core'; import {BaseEventContext, BasePlugin} from 'amis-editor-core';
@ -280,7 +277,7 @@ export class TreeSelectControlPlugin extends BasePlugin {
}, },
getSchemaTpl('source', { getSchemaTpl('source', {
sampleBuilder: (schema: any) => sampleBuilder: () =>
JSON.stringify( JSON.stringify(
{ {
status: 0, status: 0,

View File

@ -3,10 +3,7 @@ import {registerEditorPlugin} from 'amis-editor-core';
import {BaseEventContext, BasePlugin} from 'amis-editor-core'; import {BaseEventContext, BasePlugin} from 'amis-editor-core';
import {getSchemaTpl} from 'amis-editor-core'; import {getSchemaTpl} from 'amis-editor-core';
import {getEventControlConfig} from '../renderer/event-control/helper'; import {getEventControlConfig} from '../renderer/event-control/helper';
import { import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
RendererPluginAction,
RendererPluginEvent
} from 'amis-editor-core';
import type {SchemaObject} from 'amis/lib/Schema'; import type {SchemaObject} from 'amis/lib/Schema';
export class PagePlugin extends BasePlugin { export class PagePlugin extends BasePlugin {
@ -176,7 +173,7 @@ export class PagePlugin extends BasePlugin {
getSchemaTpl('api', { getSchemaTpl('api', {
label: '数据初始化接口', label: '数据初始化接口',
name: 'initApi', name: 'initApi',
sampleBuilder: (schema: any) => `{ sampleBuilder: () => `{
"status": 0, "status": 0,
"msg": "", "msg": "",

View File

@ -17,7 +17,7 @@ setSchemaTpl('api', (patch: any = {}) => {
label: '示例', label: '示例',
title: '接口返回示例', title: '接口返回示例',
tooltipClassName: 'ae-ApiSample-tooltip', tooltipClassName: 'ae-ApiSample-tooltip',
render: (data: any) => ( children: (data: any) => (
<Html <Html
className="ae-ApiSample" className="ae-ApiSample"
inline={false} inline={false}
@ -314,7 +314,7 @@ setSchemaTpl('source', (patch: any = {}) => {
name: 'source', name: 'source',
label: '获取选项接口', label: '获取选项接口',
description: '可以通过接口获取动态选项,一次拉取全部。', description: '可以通过接口获取动态选项,一次拉取全部。',
sampleBuilder: (schema: any) => sampleBuilder: () =>
JSON.stringify( JSON.stringify(
{ {
status: 0, status: 0,
@ -423,7 +423,7 @@ setSchemaTpl('apiControl', (patch: any = {}) => {
label: '示例', label: '示例',
title: '接口返回示例', title: '接口返回示例',
tooltipClassName: 'ae-ApiSample-tooltip', tooltipClassName: 'ae-ApiSample-tooltip',
render: (data: any) => ( children: (data: any) => (
<Html <Html
className="ae-ApiSample" className="ae-ApiSample"
inline={false} inline={false}
@ -460,7 +460,7 @@ setSchemaTpl('actionApiControl', (patch: any = {}) => {
label: '示例', label: '示例',
title: '接口返回示例', title: '接口返回示例',
tooltipClassName: 'ae-ApiSample-tooltip', tooltipClassName: 'ae-ApiSample-tooltip',
render: (data: any) => ( children: (data: any) => (
<Html <Html
className="ae-ApiSample" className="ae-ApiSample"
inline={false} inline={false}