diff --git a/packages/amis-editor/src/plugin/CRUD.tsx b/packages/amis-editor/src/plugin/CRUD.tsx index c858fba53..23a22c8e4 100644 --- a/packages/amis-editor/src/plugin/CRUD.tsx +++ b/packages/amis-editor/src/plugin/CRUD.tsx @@ -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 = { create: { label: '新增', diff --git a/packages/amis-editor/src/plugin/Form/Form.tsx b/packages/amis-editor/src/plugin/Form/Form.tsx index 30d5792f2..7c6b2c2b5 100644 --- a/packages/amis-editor/src/plugin/Form/Form.tsx +++ b/packages/amis-editor/src/plugin/Form/Form.tsx @@ -10,10 +10,7 @@ import { import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {jsonToJsonSchema} from 'amis-editor-core'; import {EditorNodeType} from 'amis-editor-core'; -import { - RendererPluginAction, - RendererPluginEvent -} from 'amis-editor-core'; +import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core'; import {setVariable} from 'amis-core'; import {getEventControlConfig} from '../../renderer/event-control/helper'; @@ -540,7 +537,7 @@ export class FormPlugin extends BasePlugin { getSchemaTpl('api', { label: '保存接口', description: '用来保存表单数据', - sampleBuilder: (schema: any) => `{ + sampleBuilder: () => `{ "status": 0, "msg": "", @@ -582,10 +579,11 @@ export class FormPlugin extends BasePlugin { name: 'initApi', label: '初始化接口', description: '用来初始化表单数据', - sampleBuilder: (schema: any) => { + sampleBuilder: () => { const data = {}; + const schema = context?.schema; - if (Array.isArray(schema.body)) { + if (Array.isArray(schema?.body)) { schema.body.forEach((control: any) => { if ( control.name && diff --git a/packages/amis-editor/src/plugin/Form/InputTree.tsx b/packages/amis-editor/src/plugin/Form/InputTree.tsx index b431ebeb7..6da89ef42 100644 --- a/packages/amis-editor/src/plugin/Form/InputTree.tsx +++ b/packages/amis-editor/src/plugin/Form/InputTree.tsx @@ -279,7 +279,7 @@ export class TreeControlPlugin extends BasePlugin { name: 'options' }, getSchemaTpl('source', { - sampleBuilder: (schema: any) => + sampleBuilder: () => JSON.stringify( { status: 0, diff --git a/packages/amis-editor/src/plugin/Form/TreeSelect.tsx b/packages/amis-editor/src/plugin/Form/TreeSelect.tsx index cbf7291e2..170526be7 100644 --- a/packages/amis-editor/src/plugin/Form/TreeSelect.tsx +++ b/packages/amis-editor/src/plugin/Form/TreeSelect.tsx @@ -1,7 +1,4 @@ -import { - RendererPluginAction, - RendererPluginEvent -} from 'amis-editor-core'; +import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core'; import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {registerEditorPlugin} from 'amis-editor-core'; import {BaseEventContext, BasePlugin} from 'amis-editor-core'; @@ -280,7 +277,7 @@ export class TreeSelectControlPlugin extends BasePlugin { }, getSchemaTpl('source', { - sampleBuilder: (schema: any) => + sampleBuilder: () => JSON.stringify( { status: 0, diff --git a/packages/amis-editor/src/plugin/Page.tsx b/packages/amis-editor/src/plugin/Page.tsx index cd2e7177d..8a9441258 100644 --- a/packages/amis-editor/src/plugin/Page.tsx +++ b/packages/amis-editor/src/plugin/Page.tsx @@ -3,10 +3,7 @@ import {registerEditorPlugin} from 'amis-editor-core'; import {BaseEventContext, BasePlugin} from 'amis-editor-core'; import {getSchemaTpl} from 'amis-editor-core'; import {getEventControlConfig} from '../renderer/event-control/helper'; -import { - RendererPluginAction, - RendererPluginEvent -} from 'amis-editor-core'; +import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core'; import type {SchemaObject} from 'amis/lib/Schema'; export class PagePlugin extends BasePlugin { @@ -176,7 +173,7 @@ export class PagePlugin extends BasePlugin { getSchemaTpl('api', { label: '数据初始化接口', name: 'initApi', - sampleBuilder: (schema: any) => `{ + sampleBuilder: () => `{ "status": 0, "msg": "", diff --git a/packages/amis-editor/src/tpl/api.tsx b/packages/amis-editor/src/tpl/api.tsx index d3a7e45a7..3b93374df 100644 --- a/packages/amis-editor/src/tpl/api.tsx +++ b/packages/amis-editor/src/tpl/api.tsx @@ -17,7 +17,7 @@ setSchemaTpl('api', (patch: any = {}) => { label: '示例', title: '接口返回示例', tooltipClassName: 'ae-ApiSample-tooltip', - render: (data: any) => ( + children: (data: any) => ( { name: 'source', label: '获取选项接口', description: '可以通过接口获取动态选项,一次拉取全部。', - sampleBuilder: (schema: any) => + sampleBuilder: () => JSON.stringify( { status: 0, @@ -423,7 +423,7 @@ setSchemaTpl('apiControl', (patch: any = {}) => { label: '示例', title: '接口返回示例', tooltipClassName: 'ae-ApiSample-tooltip', - render: (data: any) => ( + children: (data: any) => ( { label: '示例', title: '接口返回示例', tooltipClassName: 'ae-ApiSample-tooltip', - render: (data: any) => ( + children: (data: any) => (