From 45e7a3b5bcfbc0da67bc8bace9c6adb0d2abc925 Mon Sep 17 00:00:00 2001 From: nwind Date: Mon, 1 Aug 2022 15:44:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20api=20=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Idc55248ad7475e48749030350aed8c08cfe48b2c --- packages/amis-editor/src/plugin/CRUD.tsx | 28 ------------------- packages/amis-editor/src/plugin/Form/Form.tsx | 12 ++++---- .../amis-editor/src/plugin/Form/InputTree.tsx | 2 +- .../src/plugin/Form/TreeSelect.tsx | 7 ++--- packages/amis-editor/src/plugin/Page.tsx | 7 ++--- packages/amis-editor/src/tpl/api.tsx | 8 +++--- 6 files changed, 14 insertions(+), 50 deletions(-) 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) => (