From 8a3ccc736ebdc35bd669237aafcec68738691ad1 Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Mon, 6 Nov 2023 20:04:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=AE=B9=E5=99=A8=E7=BB=84=E4=BB=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-editor/src/plugin/SwitchContainer.tsx | 15 ++++++++++++++- .../amis-editor/src/renderer/ListItemControl.tsx | 10 +++++++--- packages/amis/src/renderers/SwitchContainer.tsx | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) 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 }); From 2c140f6e8fd9f945dbb545a7396f258a4a3e37e4 Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Wed, 8 Nov 2023 20:27:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20listSelect=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E9=80=82=E9=85=8D=E8=87=AA=E5=AE=9A=E4=B9=89label=20v?= =?UTF-8?q?alue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor-core/src/plugin.ts | 4 +- packages/amis-editor-core/src/util.ts | 5 +- .../src/plugin/Form/ListSelect.tsx | 48 +++++++++---------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/packages/amis-editor-core/src/plugin.ts b/packages/amis-editor-core/src/plugin.ts index 30174d640..0bd032484 100644 --- a/packages/amis-editor-core/src/plugin.ts +++ b/packages/amis-editor-core/src/plugin.ts @@ -304,7 +304,7 @@ export interface RendererInfo extends RendererScaffoldInfo { sharedContext?: Record; dialogTitle?: string; //弹窗标题用于弹窗大纲的展示 dialogType?: string; //区分确认对话框类型 - subEditorVariable?: Array<{label: string; children: any}>; // 传递给子编辑器的组件自定义变量,如listSelect的选项名称和值 + getSubEditorVariable: (schema?: any) => Array<{label: string; children: any}>; // 传递给子编辑器的组件自定义变量,如listSelect的选项名称和值 } export type BasicRendererInfo = Omit< @@ -1051,7 +1051,7 @@ export abstract class BasePlugin implements PluginInterface { isListComponent: plugin.isListComponent, rendererName: plugin.rendererName, memberImmutable: plugin.memberImmutable, - subEditorVariable: plugin.subEditorVariable + getSubEditorVariable: plugin.getSubEditorVariable }; } } diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index ba099172a..cceedf751 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -1224,7 +1224,10 @@ export async function resolveVariablesFromScope(node: any, manager: any) { // 子编辑器内读取的host节点自定义变量,非数据域方式,如listSelect的选项值 let hostNodeVaraibles = []; if (manager?.store?.isSubEditor) { - hostNodeVaraibles = manager.config?.hostNode?.info?.subEditorVariable || []; + hostNodeVaraibles = + manager.config?.hostNode?.info?.getSubEditorVariable?.( + manager.config?.hostNode.schema + ) || []; } const variables: VariableItem[] = diff --git a/packages/amis-editor/src/plugin/Form/ListSelect.tsx b/packages/amis-editor/src/plugin/Form/ListSelect.tsx index c6574400a..e97724ca8 100644 --- a/packages/amis-editor/src/plugin/Form/ListSelect.tsx +++ b/packages/amis-editor/src/plugin/Form/ListSelect.tsx @@ -109,21 +109,26 @@ export class ListControlPlugin extends BasePlugin { } ]; - subEditorVariable: Array<{label: string; children: any}> = [ - { - label: '当前选项', - children: [ - { - label: '选项名称', - value: 'label' - }, - { - label: '选项值', - value: 'value' - } - ] - } - ]; + getSubEditorVariable(schema: any): Array<{label: string; children: any}> { + let labelField = schema?.labelField || 'label'; + let valueField = schema?.valueField || 'value'; + + return [ + { + label: '当前选项', + children: [ + { + label: '选项名称', + value: labelField + }, + { + label: '选项值', + value: valueField + } + ] + } + ]; + } panelBodyCreator = (context: BaseEventContext) => { return formItemControl( @@ -201,7 +206,7 @@ export class ListControlPlugin extends BasePlugin { body: [ { type: 'tpl', - tpl: `\${${this.getDisplayField(value)}}`, + tpl: `\${${this.getDisplayField(data)}}`, wrapperComponent: '', inline: true } @@ -275,16 +280,7 @@ export class ListControlPlugin extends BasePlugin { } getDisplayField(data: any) { - if ( - data.source || - (data.map && - Array.isArray(data.map) && - data.map[0] && - Object.keys(data.map[0]).length > 1) - ) { - return data.labelField ?? 'label'; - } - return 'label'; + return data?.labelField ?? 'label'; } editDetail(id: string, field: string) { From 91a8e81ad935d3da06866e6aef719d4261616071 Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Wed, 8 Nov 2023 20:52:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Deach=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A4=96=E5=B1=82=E5=A4=96=E8=A7=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Each.tsx | 38 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/amis/src/renderers/Each.tsx b/packages/amis/src/renderers/Each.tsx index a5234d45a..f66f0792f 100644 --- a/packages/amis/src/renderers/Each.tsx +++ b/packages/amis/src/renderers/Each.tsx @@ -1,5 +1,12 @@ import React from 'react'; -import {Renderer, RendererProps, buildStyle, isPureVariable} from 'amis-core'; +import { + CustomStyle, + Renderer, + RendererProps, + buildStyle, + isPureVariable, + setThemeClassName +} from 'amis-core'; import {Schema} from 'amis-core'; import {resolveVariable, resolveVariableAndFilter} from 'amis-core'; import {createObject, getPropValue, isObject} from 'amis-core'; @@ -96,7 +103,11 @@ export default class Each extends React.Component { indexKeyName, placeholder, classnames: cx, - translate: __ + translate: __, + env, + id, + wrapperCustomStyle, + themeCss } = this.props; const value = getPropValue(this.props, props => @@ -124,7 +135,14 @@ export default class Each extends React.Component { } return ( -
+
{Array.isArray(arr) && arr.length && items ? ( arr.map((item: any, index: number) => ( { {render('placeholder', __(placeholder))}
)} + +
); }