mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
Merge pull request #8663 from zhangtao07/master
优化状态容器配置 & listSelect自定义label value适配
This commit is contained in:
commit
3e1e8a6189
@ -304,7 +304,7 @@ export interface RendererInfo extends RendererScaffoldInfo {
|
|||||||
sharedContext?: Record<string, any>;
|
sharedContext?: Record<string, any>;
|
||||||
dialogTitle?: string; //弹窗标题用于弹窗大纲的展示
|
dialogTitle?: string; //弹窗标题用于弹窗大纲的展示
|
||||||
dialogType?: string; //区分确认对话框类型
|
dialogType?: string; //区分确认对话框类型
|
||||||
subEditorVariable?: Array<{label: string; children: any}>; // 传递给子编辑器的组件自定义变量,如listSelect的选项名称和值
|
getSubEditorVariable: (schema?: any) => Array<{label: string; children: any}>; // 传递给子编辑器的组件自定义变量,如listSelect的选项名称和值
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BasicRendererInfo = Omit<
|
export type BasicRendererInfo = Omit<
|
||||||
@ -1051,7 +1051,7 @@ export abstract class BasePlugin implements PluginInterface {
|
|||||||
isListComponent: plugin.isListComponent,
|
isListComponent: plugin.isListComponent,
|
||||||
rendererName: plugin.rendererName,
|
rendererName: plugin.rendererName,
|
||||||
memberImmutable: plugin.memberImmutable,
|
memberImmutable: plugin.memberImmutable,
|
||||||
subEditorVariable: plugin.subEditorVariable
|
getSubEditorVariable: plugin.getSubEditorVariable
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1224,7 +1224,10 @@ export async function resolveVariablesFromScope(node: any, manager: any) {
|
|||||||
// 子编辑器内读取的host节点自定义变量,非数据域方式,如listSelect的选项值
|
// 子编辑器内读取的host节点自定义变量,非数据域方式,如listSelect的选项值
|
||||||
let hostNodeVaraibles = [];
|
let hostNodeVaraibles = [];
|
||||||
if (manager?.store?.isSubEditor) {
|
if (manager?.store?.isSubEditor) {
|
||||||
hostNodeVaraibles = manager.config?.hostNode?.info?.subEditorVariable || [];
|
hostNodeVaraibles =
|
||||||
|
manager.config?.hostNode?.info?.getSubEditorVariable?.(
|
||||||
|
manager.config?.hostNode.schema
|
||||||
|
) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const variables: VariableItem[] =
|
const variables: VariableItem[] =
|
||||||
|
@ -109,21 +109,26 @@ export class ListControlPlugin extends BasePlugin {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
subEditorVariable: Array<{label: string; children: any}> = [
|
getSubEditorVariable(schema: any): Array<{label: string; children: any}> {
|
||||||
{
|
let labelField = schema?.labelField || 'label';
|
||||||
label: '当前选项',
|
let valueField = schema?.valueField || 'value';
|
||||||
children: [
|
|
||||||
{
|
return [
|
||||||
label: '选项名称',
|
{
|
||||||
value: 'label'
|
label: '当前选项',
|
||||||
},
|
children: [
|
||||||
{
|
{
|
||||||
label: '选项值',
|
label: '选项名称',
|
||||||
value: 'value'
|
value: labelField
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
}
|
label: '选项值',
|
||||||
];
|
value: valueField
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
panelBodyCreator = (context: BaseEventContext) => {
|
panelBodyCreator = (context: BaseEventContext) => {
|
||||||
return formItemControl(
|
return formItemControl(
|
||||||
@ -201,7 +206,7 @@ export class ListControlPlugin extends BasePlugin {
|
|||||||
body: [
|
body: [
|
||||||
{
|
{
|
||||||
type: 'tpl',
|
type: 'tpl',
|
||||||
tpl: `\${${this.getDisplayField(value)}}`,
|
tpl: `\${${this.getDisplayField(data)}}`,
|
||||||
wrapperComponent: '',
|
wrapperComponent: '',
|
||||||
inline: true
|
inline: true
|
||||||
}
|
}
|
||||||
@ -275,16 +280,7 @@ export class ListControlPlugin extends BasePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDisplayField(data: any) {
|
getDisplayField(data: any) {
|
||||||
if (
|
return data?.labelField ?? 'label';
|
||||||
data.source ||
|
|
||||||
(data.map &&
|
|
||||||
Array.isArray(data.map) &&
|
|
||||||
data.map[0] &&
|
|
||||||
Object.keys(data.map[0]).length > 1)
|
|
||||||
) {
|
|
||||||
return data.labelField ?? 'label';
|
|
||||||
}
|
|
||||||
return 'label';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
editDetail(id: string, field: string) {
|
editDetail(id: string, field: string) {
|
||||||
|
@ -321,6 +321,7 @@ export class SwitchContainerPlugin extends LayoutBasePlugin {
|
|||||||
name: 'items',
|
name: 'items',
|
||||||
label: '状态列表',
|
label: '状态列表',
|
||||||
addTip: '新增组件状态',
|
addTip: '新增组件状态',
|
||||||
|
minLength: 1,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
@ -356,6 +357,10 @@ export class SwitchContainerPlugin extends LayoutBasePlugin {
|
|||||||
title: '外观',
|
title: '外观',
|
||||||
className: 'p-none',
|
className: 'p-none',
|
||||||
body: getSchemaTpl('collapseGroup', [
|
body: getSchemaTpl('collapseGroup', [
|
||||||
|
getSchemaTpl('theme:base', {
|
||||||
|
collapsed: false,
|
||||||
|
extra: []
|
||||||
|
}),
|
||||||
{
|
{
|
||||||
title: '布局',
|
title: '布局',
|
||||||
body: [
|
body: [
|
||||||
@ -460,7 +465,15 @@ export class SwitchContainerPlugin extends LayoutBasePlugin {
|
|||||||
getSchemaTpl('layout:stickyPosition')
|
getSchemaTpl('layout:stickyPosition')
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
...getSchemaTpl('theme:common', {exclude: ['layout']})
|
{
|
||||||
|
title: '自定义样式',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'theme-cssCode',
|
||||||
|
label: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ import {findDOMNode} from 'react-dom';
|
|||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import Sortable from 'sortablejs';
|
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 {autobind} from 'amis-editor-core';
|
||||||
import type {Option} from 'amis';
|
import type {Option} from 'amis';
|
||||||
import {createObject, FormControlProps} from 'amis-core';
|
import {createObject, FormControlProps} from 'amis-core';
|
||||||
@ -30,7 +30,6 @@ export type SourceType = 'custom' | 'api' | 'apicenter' | 'variable';
|
|||||||
|
|
||||||
export interface OptionControlState {
|
export interface OptionControlState {
|
||||||
items: Array<PlainObject>;
|
items: Array<PlainObject>;
|
||||||
api: SchemaApi;
|
|
||||||
labelField: string;
|
labelField: string;
|
||||||
valueField: string;
|
valueField: string;
|
||||||
}
|
}
|
||||||
@ -50,7 +49,6 @@ export default class ListItemControl extends React.Component<
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
items: this.transformOptions(props),
|
items: this.transformOptions(props),
|
||||||
api: props.data.source,
|
|
||||||
labelField: props.data.labelField || 'title',
|
labelField: props.data.labelField || 'title',
|
||||||
valueField: props.data.valueField
|
valueField: props.data.valueField
|
||||||
};
|
};
|
||||||
@ -173,6 +171,12 @@ export default class ListItemControl extends React.Component<
|
|||||||
*/
|
*/
|
||||||
handleDelete(index: number) {
|
handleDelete(index: number) {
|
||||||
const items = this.state.items.concat();
|
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);
|
items.splice(index, 1);
|
||||||
this.setState({items}, () => this.onChange());
|
this.setState({items}, () => this.onChange());
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import React from 'react';
|
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 {Schema} from 'amis-core';
|
||||||
import {resolveVariable, resolveVariableAndFilter} from 'amis-core';
|
import {resolveVariable, resolveVariableAndFilter} from 'amis-core';
|
||||||
import {createObject, getPropValue, isObject} from 'amis-core';
|
import {createObject, getPropValue, isObject} from 'amis-core';
|
||||||
@ -96,7 +103,11 @@ export default class Each extends React.Component<EachProps> {
|
|||||||
indexKeyName,
|
indexKeyName,
|
||||||
placeholder,
|
placeholder,
|
||||||
classnames: cx,
|
classnames: cx,
|
||||||
translate: __
|
translate: __,
|
||||||
|
env,
|
||||||
|
id,
|
||||||
|
wrapperCustomStyle,
|
||||||
|
themeCss
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const value = getPropValue(this.props, props =>
|
const value = getPropValue(this.props, props =>
|
||||||
@ -124,7 +135,14 @@ export default class Each extends React.Component<EachProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx('Each', className)} style={buildStyle(style, data)}>
|
<div
|
||||||
|
className={cx(
|
||||||
|
'Each',
|
||||||
|
className,
|
||||||
|
setThemeClassName('baseControlClassName', id, themeCss)
|
||||||
|
)}
|
||||||
|
style={buildStyle(style, data)}
|
||||||
|
>
|
||||||
{Array.isArray(arr) && arr.length && items ? (
|
{Array.isArray(arr) && arr.length && items ? (
|
||||||
arr.map((item: any, index: number) => (
|
arr.map((item: any, index: number) => (
|
||||||
<EachItem
|
<EachItem
|
||||||
@ -144,6 +162,20 @@ export default class Each extends React.Component<EachProps> {
|
|||||||
{render('placeholder', __(placeholder))}
|
{render('placeholder', __(placeholder))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<CustomStyle
|
||||||
|
config={{
|
||||||
|
wrapperCustomStyle,
|
||||||
|
id,
|
||||||
|
themeCss,
|
||||||
|
classNames: [
|
||||||
|
{
|
||||||
|
key: 'baseControlClassName'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
env={env}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ export default class SwitchContainer extends React.Component<
|
|||||||
|
|
||||||
componentDidUpdate(preProps: SwitchContainerProps) {
|
componentDidUpdate(preProps: SwitchContainerProps) {
|
||||||
const items = this.props.items || [];
|
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({
|
this.setState({
|
||||||
activeIndex: 0
|
activeIndex: 0
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user