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

View File

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

View File

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

View File

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

View File

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