diff --git a/packages/amis-editor/src/plugin/SwitchContainer.tsx b/packages/amis-editor/src/plugin/SwitchContainer.tsx index 05dd08adc..1852a11f4 100644 --- a/packages/amis-editor/src/plugin/SwitchContainer.tsx +++ b/packages/amis-editor/src/plugin/SwitchContainer.tsx @@ -321,6 +321,7 @@ export class SwitchContainerPlugin extends LayoutBasePlugin { name: 'items', label: '状态列表', addTip: '新增组件状态', + minLength: 1, items: [ { type: 'input-text', @@ -356,6 +357,10 @@ export class SwitchContainerPlugin extends LayoutBasePlugin { title: '外观', className: 'p-none', body: getSchemaTpl('collapseGroup', [ + getSchemaTpl('theme:base', { + collapsed: false, + extra: [] + }), { title: '布局', body: [ @@ -460,7 +465,15 @@ export class SwitchContainerPlugin extends LayoutBasePlugin { getSchemaTpl('layout:stickyPosition') ] }, - ...getSchemaTpl('theme:common', {exclude: ['layout']}) + { + title: '自定义样式', + body: [ + { + type: 'theme-cssCode', + label: false + } + ] + } ]) }, { diff --git a/packages/amis-editor/src/renderer/ListItemControl.tsx b/packages/amis-editor/src/renderer/ListItemControl.tsx index 4754bf48c..26117f8bf 100644 --- a/packages/amis-editor/src/renderer/ListItemControl.tsx +++ b/packages/amis-editor/src/renderer/ListItemControl.tsx @@ -7,7 +7,7 @@ import {findDOMNode} from 'react-dom'; import cx from 'classnames'; import get from 'lodash/get'; import Sortable from 'sortablejs'; -import {FormItem, Button, Icon, render as amisRender} from 'amis'; +import {FormItem, Button, Icon, render as amisRender, toast} from 'amis'; import {autobind} from 'amis-editor-core'; import type {Option} from 'amis'; import {createObject, FormControlProps} from 'amis-core'; @@ -30,7 +30,6 @@ export type SourceType = 'custom' | 'api' | 'apicenter' | 'variable'; export interface OptionControlState { items: Array; - api: SchemaApi; labelField: string; valueField: string; } @@ -50,7 +49,6 @@ export default class ListItemControl extends React.Component< this.state = { items: this.transformOptions(props), - api: props.data.source, labelField: props.data.labelField || 'title', valueField: props.data.valueField }; @@ -173,6 +171,12 @@ export default class ListItemControl extends React.Component< */ handleDelete(index: number) { const items = this.state.items.concat(); + const minLength = this.props.minLength; + + if (minLength > 0 && items.length <= minLength) { + toast.warning(`列表项数目不能少于${minLength}`); + return; + } items.splice(index, 1); this.setState({items}, () => this.onChange()); diff --git a/packages/amis/src/renderers/SwitchContainer.tsx b/packages/amis/src/renderers/SwitchContainer.tsx index 62d8f598a..7aad5492c 100644 --- a/packages/amis/src/renderers/SwitchContainer.tsx +++ b/packages/amis/src/renderers/SwitchContainer.tsx @@ -80,7 +80,7 @@ export default class SwitchContainer extends React.Component< componentDidUpdate(preProps: SwitchContainerProps) { const items = this.props.items || []; - if (this.state.activeIndex >= 0 && !items[this.state.activeIndex]) { + if (this.state.activeIndex > 0 && !items[this.state.activeIndex]) { this.setState({ activeIndex: 0 });