This commit is contained in:
金禅 2020-08-13 18:28:39 +08:00
parent ad51badaeb
commit 236b885cae
6 changed files with 616 additions and 319 deletions

File diff suppressed because it is too large Load Diff

View File

@ -64,44 +64,59 @@ const icons = [
];
interface IconSetterProps {
value: string;
type: string;
defaultValue: string;
placeholder: string;
hasClear: boolean;
onChange: (icon: string) => undefined;
onChange: (icon: string | object) => undefined;
icons: string[];
}
export default class IconSetter extends PureComponent<IconSetterProps, {}> {
static defaultProps = {
value: undefined,
type: 'string',
defaultValue: '',
hasClear: true,
icons: icons,
placeholder: '请点击选择 Icon',
onChange: (icon: string) => undefined,
onChange: (icon: string | object) => undefined,
};
state = {
firstLoad: true,
};
_onChange = (icon: string) => {
const { onChange, type } = this.props;
if (type === 'string') {
onChange(icon);
} else if (type === 'node') {
onChange({
componentName: 'Icon',
props: {
type: icon,
},
});
}
};
onInputChange = (icon: string) => {
const { onChange } = this.props;
onChange(icon);
this._onChange(icon);
};
onSelectIcon = (icon: string) => {
const { onChange } = this.props;
onChange(icon);
this._onChange(icon);
};
render() {
const { icons, value, defaultValue, onChange, placeholder, hasClear } = this.props;
const { icons, value, defaultValue, onChange, placeholder, hasClear, type } = this.props;
const { firstLoad } = this.state;
const _value = typeof value === 'object' ? value?.props?.type : value;
if (firstLoad && defaultValue && typeof value === 'undefined') onChange(defaultValue);
this.setState({
firstLoad: false,
});
const currentIcon = <Icon size="xs" type={value} />;
const currentIcon = <Icon size="xs" type={_value} />;
const clearIcon = hasClear && (
<Icon
size="xs"
@ -121,7 +136,7 @@ export default class IconSetter extends PureComponent<IconSetterProps, {}> {
placeholder={placeholder}
addonTextBefore={currentIcon}
onChange={this.onInputChange}
value={value}
value={_value}
defaultValue={defaultValue}
readOnly
addonTextAfter={clearIcon}

View File

@ -15,6 +15,10 @@ export const StringSetter = {
defaultProps: { placeholder: '请输入', style: { maxWidth: 180 } },
title: 'StringSetter',
recommend: true,
condition: (field: any) => {
const v = field.getValue();
return typeof v === 'string';
},
};
export const NumberSetter = NumberPicker;
export class BoolSetter extends Component {
@ -38,6 +42,10 @@ export const TextAreaSetter = {
defaultProps: { placeholder: '请输入', style: { maxWidth: 180 } },
title: 'TextAreaSetter',
recommend: true,
condition: (field: any) => {
const v = field.getValue();
return typeof v === 'string';
},
};
export const DateSetter = DatePicker;
export const DateYearSetter = DatePicker.YearPicker;

View File

@ -13,7 +13,7 @@
--popup-border-radius: @popup-border-radius;
--left-area-width: 48px;
--right-area-width: 280px;
--right-area-width: 300px;
--top-area-height: 48px;
--toolbar-height: 36px;
--dock-pane-width: 280px;

View File

@ -89,7 +89,7 @@ function propTypeToSetter(propType: PropType): SetterType {
value,
};
});
const componentName = dataSource.length > 4 ? 'SelectSetter' : 'RadioGroupSetter';
const componentName = dataSource.length >= 4 ? 'SelectSetter' : 'RadioGroupSetter';
return {
componentName,
props: { dataSource },

View File

@ -109,20 +109,29 @@ class Renderer extends Component<{ renderer: SimulatorRenderer }> {
viewProps._leaf = leaf;
viewProps._componentName = leaf?.componentName;
// 如果是容器 && 无children && 高宽为空 增加一个占位容器,方便拖动
if (leaf?.isContainer() && (children == null || (Array.isArray(children) && !children.length)) && (!viewProps.style || Object.keys(viewProps.style).length == 0)){
children = <div style={{
height:'66px',
backgroundColor:'#f0f0f0',
borderColor:'#a7b1bd',
border: '1px dotted',
color:'#a7b1bd',
textAlign:'center',
lineHeight:'66px'
}}>
</div>
if (
!viewProps.dataSource &&
leaf?.isContainer() &&
(children == null || (Array.isArray(children) && !children.length)) &&
(!viewProps.style || Object.keys(viewProps.style).length === 0)
) {
children = (
<div
style={{
height: '66px',
backgroundColor: '#f0f0f0',
borderColor: '#a7b1bd',
border: '1px dotted',
color: '#a7b1bd',
textAlign: 'center',
lineHeight: '66px',
}}
>
{viewProps.placeholder || '拖拽组件或模板到这里'}
</div>
);
}
// FIXME: 渲染仍有问题
if (viewProps._componentName === 'Menu') {
Object.assign(viewProps, {
_componentName: 'Menu',