add events definition

This commit is contained in:
kangwei 2020-03-16 18:19:42 +08:00
parent 59b9925665
commit 176a708f75
5 changed files with 42 additions and 58 deletions

View File

@ -23,7 +23,7 @@ export default class PropStash implements IPropParent {
}
const pending: Prop[] = [];
for (const prop of this.space) {
if (!prop.isUnset()) {
if (!prop.isUnset() && !prop.isVirtual()) {
this.space.delete(prop);
pending.push(prop);
}

View File

@ -225,6 +225,10 @@ export default class Prop implements IPropParent {
return this._type === 'unset';
}
isVirtual() {
return typeof this.key === 'string' && this.key.charAt(0) === '!';
}
// TODO: improve this logic
compare(other: Prop | null): number {
if (!other || other.isUnset()) {

View File

@ -21,7 +21,8 @@ const DEFINITION_EVENT_TYPE = {
};
export default class EventsSetter extends Component<{
field:SettingField
value: any[];
onChange: (eventList: any[]) => void;
}> {
state = {
showEventList: false,
@ -37,9 +38,6 @@ export default class EventsSetter extends Component<{
};
componentWillMount() {
// this.props.field.getValue()
console.log(this.props);
this.initEventBtns();
this.initEventList();
}

View File

@ -159,7 +159,7 @@ export interface FieldConfig extends FieldExtraProps {
export class SettingField implements SettingTarget {
readonly isSettingField = true;
readonly id = uniqueId('field');
readonly type: 'field' | 'virtual-field' | 'group';
readonly type: 'field' | 'group';
readonly isRequired: boolean = false;
readonly isGroup: boolean;
private _name: string | number;
@ -193,8 +193,6 @@ export class SettingField implements SettingTarget {
const c = typeof name === 'string' ? name.substr(0, 1) : '';
if (c === '#') {
this.type = 'group';
} else if (c === '!') {
this.type = 'virtual-field';
} else {
this.type = 'field';
}

View File

@ -310,55 +310,38 @@ registerMetadataTransducer(metadata => {
if (componentName === 'Page' || componentName === 'Component') {
isRoot = true;
// 平台配置的,一般只有根节点才会配置
eventsDefinition = [{
type: 'lifeCycleEvent',
title: '生命周期',
list: [
{
description: '初始化时',
name: 'constructor',
},
{
description: '装载后',
name: 'componentDidMount',
},
{
description: '更新时',
name: 'componentDidMount',
},
{
description: '卸载时',
name: 'componentWillUnmount',
},
]
}];
eventsDefinition = [
{
type: 'lifeCycleEvent',
title: '生命周期',
list: [
{
description: '初始化时',
name: 'constructor',
},
{
description: '装载后',
name: 'componentDidMount',
},
{
description: '更新时',
name: 'componentDidMount',
},
{
description: '卸载时',
name: 'componentWillUnmount',
},
],
},
];
} else {
eventsDefinition = [{
type: 'events',
title: '事件',
list: (events?.supportEvents || []).map((event: any) => {
return typeof event === 'string'
? {
name: event,
}
: event;
}),
// mock data
list:[
{
name:'onClick',
description:'点击回调'
},
{
name:'onChange',
description:'变更回调'
},
{
name:'onSubmit'
}
]
}];
eventsDefinition = [
{
type: 'events',
title: '事件',
list: (events?.supportEvents || []).map((event: any) => (typeof event === 'string' ? { name: event } : event)),
},
];
}
// 通用设置
const propsGroup = props || [];
@ -439,8 +422,9 @@ registerMetadataTransducer(metadata => {
return data;
},
setValue(field: SettingField, eventDataList: any[]) {
field.setPropValue('eventDataList', eventDataList);
}
console.info(eventDataList);
field.setPropValue('eventDataList', eventDataList);
},
},
],
});