diff --git a/packages/amis-editor/src/plugin/CRUD.tsx b/packages/amis-editor/src/plugin/CRUD.tsx index 98f799f82..1ee50b729 100644 --- a/packages/amis-editor/src/plugin/CRUD.tsx +++ b/packages/amis-editor/src/plugin/CRUD.tsx @@ -188,7 +188,7 @@ export class CRUDPlugin extends BasePlugin { scaffoldForm: ScaffoldForm = { title: '增删改查快速开始-CRUD', body: [ - getSchemaTpl('apiControl', { + getSchemaTpl('api', { label: '接口地址', sampleBuilder: (schema: any) => JSON.stringify( diff --git a/packages/amis-editor/src/plugin/Form/Form.tsx b/packages/amis-editor/src/plugin/Form/Form.tsx index 4a699a522..7c6b2c2b5 100644 --- a/packages/amis-editor/src/plugin/Form/Form.tsx +++ b/packages/amis-editor/src/plugin/Form/Form.tsx @@ -138,7 +138,7 @@ export class FormPlugin extends BasePlugin { scaffoldForm: ScaffoldForm = { title: '快速创建表单', body: [ - getSchemaTpl('apiControl', { + getSchemaTpl('api', { label: '提交地址' }), { @@ -534,7 +534,7 @@ export class FormPlugin extends BasePlugin { : { title: '接口', body: [ - getSchemaTpl('apiControl', { + getSchemaTpl('api', { label: '保存接口', description: '用来保存表单数据', sampleBuilder: () => `{ @@ -563,7 +563,7 @@ export class FormPlugin extends BasePlugin { pipeOut: (value: any) => (value ? '' : undefined) }), - getSchemaTpl('apiControl', { + getSchemaTpl('api', { name: 'asyncApi', label: '异步检测接口', visibleOn: 'data.asyncApi != null', @@ -575,7 +575,7 @@ export class FormPlugin extends BasePlugin { type: 'divider' }, - getSchemaTpl('apiControl', { + getSchemaTpl('api', { name: 'initApi', label: '初始化接口', description: '用来初始化表单数据', @@ -657,7 +657,7 @@ export class FormPlugin extends BasePlugin { pipeOut: (value: any) => (value ? '' : undefined) }), - getSchemaTpl('apiControl', { + getSchemaTpl('api', { name: 'initAsyncApi', label: '异步检测接口', visibleOn: 'data.initAsyncApi != null', diff --git a/packages/amis-editor/src/plugin/Page.tsx b/packages/amis-editor/src/plugin/Page.tsx index 228f6bbd6..8a9441258 100644 --- a/packages/amis-editor/src/plugin/Page.tsx +++ b/packages/amis-editor/src/plugin/Page.tsx @@ -170,36 +170,21 @@ export class PagePlugin extends BasePlugin { { title: '接口', body: [ - getSchemaTpl('apiControl', { + getSchemaTpl('api', { label: '数据初始化接口', name: 'initApi', sampleBuilder: () => `{ - "status": 0, - "msg": "", - - data: { - // 示例数据 - "id": 1, - "a": "sample" - } - }` + "status": 0, + "msg": "", + + data: { + // 示例数据 + "id": 1, + "a": "sample" + } +}` }), - // getSchemaTpl('api', { - // label: '数据初始化接口', - // name: 'initApi', - // sampleBuilder: () => `{ - // "status": 0, - // "msg": "", - - // data: { - // // 示例数据 - // "id": 1, - // "a": "sample" - // } - // }` - // }), - getSchemaTpl('initFetch'), getSchemaTpl('switch', { diff --git a/packages/amis-editor/src/renderer/APIControl.tsx b/packages/amis-editor/src/renderer/APIControl.tsx index e334424f2..90cc9ac7e 100644 --- a/packages/amis-editor/src/renderer/APIControl.tsx +++ b/packages/amis-editor/src/renderer/APIControl.tsx @@ -237,43 +237,24 @@ export default class APIControl extends React.Component< onPickerClose?.(); } - @autobind renderHeader() { - const {render, label, labelRemark, useMobileUI, popOverContainer, env} = - this.props; - const classPrefix = env?.theme?.classPrefix; + const {render, actions, enablePickerMode} = this.props; - // const actionsDom = - // Array.isArray(actions) && actions.length > 0 - // ? actions.map((action, index) => { - // return render(`action/${index}`, action, { - // key: index, - // onAction: this.handleAction.bind(this, action) - // }); - // }) - // : null; + const actionsDom = + Array.isArray(actions) && actions.length > 0 + ? actions.map((action, index) => { + return render(`action/${index}`, action, { + key: index, + onAction: this.handleAction.bind(this, action) + }); + }) + : null; - return ( -
- + return actionsDom || enablePickerMode ? ( +
+ {enablePickerMode ? this.renderPickerSchema() : actionsDom}
- ); + ) : null; } renderPickerSchema() { @@ -972,7 +953,6 @@ export default class APIControl extends React.Component< } @FormItem({ - type: 'ae-apiControl', - renderLabel: false + type: 'ae-apiControl' }) export class APIControlRenderer extends APIControl {} diff --git a/packages/amis-editor/src/renderer/OptionControl.tsx b/packages/amis-editor/src/renderer/OptionControl.tsx index 589db8f9a..1f9caf56b 100644 --- a/packages/amis-editor/src/renderer/OptionControl.tsx +++ b/packages/amis-editor/src/renderer/OptionControl.tsx @@ -47,7 +47,7 @@ export interface OptionControlState { api: SchemaApi; labelField: string; valueField: string; - source: 'custom' | 'api' | 'apicenter'; + source: 'custom' | 'api' | 'form'; } export default class OptionControl extends React.Component< @@ -209,7 +209,7 @@ export default class OptionControl extends React.Component< data.value = defaultValue || undefined; } - if (source === 'api' || source === 'apicenter') { + if (source === 'api') { const {api, labelField, valueField} = this.state; data.source = api; data.labelField = labelField; @@ -296,7 +296,7 @@ export default class OptionControl extends React.Component< * 切换选项类型 */ @autobind - handleSourceChange(source: 'custom' | 'api' | 'apicenter') { + handleSourceChange(source: 'custom' | 'api' | 'form') { this.setState({source: source}, this.onChange); } @@ -396,15 +396,8 @@ export default class OptionControl extends React.Component< } renderHeader() { - const { - render, - label, - labelRemark, - useMobileUI, - env, - popOverContainer, - hasApiCenter - } = this.props; + const {render, label, labelRemark, useMobileUI, env, popOverContainer} = + this.props; const classPrefix = env?.theme?.classPrefix; const {source} = this.state; const optionSourceList = ( @@ -414,17 +407,16 @@ export default class OptionControl extends React.Component< value: 'custom' }, { - label: '外部接口', + label: '接口获取', value: 'api' - }, - ...(hasApiCenter ? [{label: 'API中心', value: 'apicenter'}] : []) + } // { // label: '表单实体', // value: 'form' // } ] as Array<{ label: string; - value: 'custom' | 'api' | 'apicenter'; + value: 'custom' | 'api' | 'form'; }> ).map(item => ({ ...item, @@ -706,7 +698,7 @@ export default class OptionControl extends React.Component< renderApiPanel() { const {render} = this.props; const {source, api, labelField, valueField} = this.state; - if (source === 'custom') { + if (source !== 'api') { return null; } @@ -719,7 +711,6 @@ export default class OptionControl extends React.Component< visibleOn: 'data.autoComplete !== false', value: api, onChange: this.handleAPIChange, - sourceType: source, footer: [ { label: tipedLabel(