Merge pull request #6613 from hsm-lv/chore-event

chore:简化resolveEventData调用
This commit is contained in:
hsm-lv 2023-04-14 10:31:47 +08:00 committed by GitHub
commit 0febbd5af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 320 additions and 347 deletions

View File

@ -483,8 +483,7 @@ export function registerOptionsControl(config: OptionsConfig) {
eventName, eventName,
resolveEventData( resolveEventData(
this.props, this.props,
{value: eventData, options, items: options}, // 为了保持名字统一 {value: eventData, options, items: options} // 为了保持名字统一
'value'
) )
); );
// 返回阻塞标识 // 返回阻塞标识

View File

@ -252,7 +252,11 @@ export const getRendererEventListeners = () => {
* @param data * @param data
* @param valueKey * @param valueKey
*/ */
export const resolveEventData = (props: any, data: any, valueKey?: string) => { export const resolveEventData = (
props: any,
data: any,
valueKey: string = 'value'
) => {
return createObject( return createObject(
props.data, props.data,
props.name && valueKey props.name && valueKey

View File

@ -190,7 +190,7 @@ export default class ChainedSelectControl extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: valueRes}, 'value') resolveEventData(this.props, {value: valueRes})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -244,7 +244,7 @@ export default class ChainedSelectControl extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: valueRes}, 'value') resolveEventData(this.props, {value: valueRes})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -83,7 +83,7 @@ export default class CheckboxControl extends React.Component<
const {dispatchEvent, onChange} = this.props; const {dispatchEvent, onChange} = this.props;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: eventData}, 'value') resolveEventData(this.props, {value: eventData})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -594,14 +594,10 @@ export default class ComboControl extends React.Component<ComboProps> {
// todo:这里的数据结构与表单项最终类型不一致需要区分是否多选、是否未input-kv or input-kvs // todo:这里的数据结构与表单项最终类型不一致需要区分是否多选、是否未input-kv or input-kvs
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'add', 'add',
resolveEventData( resolveEventData(this.props, {
this.props, value:
{ flat && joinValues ? value.join(delimiter || ',') : cloneDeep(value)
value: })
flat && joinValues ? value.join(delimiter || ',') : cloneDeep(value)
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -652,18 +648,12 @@ export default class ComboControl extends React.Component<ComboProps> {
// todo:这里的数据结构与表单项最终类型不一致需要区分是否多选、是否未input-kv or input-kvs // todo:这里的数据结构与表单项最终类型不一致需要区分是否多选、是否未input-kv or input-kvs
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'delete', 'delete',
resolveEventData( resolveEventData(this.props, {
this.props, key,
{ value:
key, flat && joinValues ? value.join(delimiter || ',') : cloneDeep(value),
value: item: value[key]
flat && joinValues })
? value.join(delimiter || ',')
: cloneDeep(value),
item: value[key]
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -143,7 +143,7 @@ export class DiffEditor extends React.Component<DiffEditorProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'focus', 'focus',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -162,7 +162,7 @@ export class DiffEditor extends React.Component<DiffEditorProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'blur', 'blur',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -259,7 +259,7 @@ export class DiffEditor extends React.Component<DiffEditorProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -191,7 +191,7 @@ export default class EditorControl extends React.Component<EditorProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'focus', 'focus',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -210,7 +210,7 @@ export default class EditorControl extends React.Component<EditorProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'blur', 'blur',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -225,7 +225,7 @@ export default class EditorControl extends React.Component<EditorProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: e}, 'value') resolveEventData(this.props, {value: e})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -431,7 +431,7 @@ export default class DateControl extends React.PureComponent<
@autobind @autobind
dispatchEvent(e: React.SyntheticEvent<HTMLElement>) { dispatchEvent(e: React.SyntheticEvent<HTMLElement>) {
const {dispatchEvent, value} = this.props; const {dispatchEvent, value} = this.props;
dispatchEvent(e, resolveEventData(this.props, {value}, 'value')); dispatchEvent(e, resolveEventData(this.props, {value}));
} }
// 动作 // 动作
@ -454,7 +454,7 @@ export default class DateControl extends React.PureComponent<
const {dispatchEvent} = this.props; const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent( const dispatcher = dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: nextValue}, 'value') resolveEventData(this.props, {value: nextValue})
); );
if (dispatcher?.prevented) { if (dispatcher?.prevented) {
return; return;

View File

@ -202,7 +202,7 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
dispatchEvent(eventName: string) { dispatchEvent(eventName: string) {
const {dispatchEvent, data, value} = this.props; const {dispatchEvent, data, value} = this.props;
dispatchEvent(eventName, resolveEventData(this.props, {value}, 'value')); dispatchEvent(eventName, resolveEventData(this.props, {value}));
} }
// 动作 // 动作
@ -225,7 +225,7 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
const {dispatchEvent, data} = this.props; const {dispatchEvent, data} = this.props;
const dispatcher = dispatchEvent( const dispatcher = dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: nextValue}, 'value') resolveEventData(this.props, {value: nextValue})
); );
if (dispatcher?.prevented) { if (dispatcher?.prevented) {
return; return;

View File

@ -168,7 +168,7 @@ export default class ExcelControl extends React.PureComponent<
const {dispatchEvent, data} = this.props; const {dispatchEvent, data} = this.props;
return await dispatchEvent( return await dispatchEvent(
eventName, eventName,
resolveEventData(this.props, {value: eventData}, 'value') resolveEventData(this.props, {value: eventData})
); );
} }

View File

@ -287,7 +287,7 @@ export default class NumberControl extends React.Component<
async dispatchEvent(eventName: string) { async dispatchEvent(eventName: string) {
const {dispatchEvent, value} = this.props; const {dispatchEvent, value} = this.props;
dispatchEvent(eventName, resolveEventData(this.props, {value}, 'value')); dispatchEvent(eventName, resolveEventData(this.props, {value}));
} }
async handleChange(inputValue: any) { async handleChange(inputValue: any) {
@ -296,7 +296,7 @@ export default class NumberControl extends React.Component<
const resultValue = clearValueOnEmpty && value === '' ? undefined : value; const resultValue = clearValueOnEmpty && value === '' ? undefined : value;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: resultValue}, 'value') resolveEventData(this.props, {value: resultValue})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -392,13 +392,9 @@ export class Input extends React.Component<RangeItemProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'blur', 'blur',
resolveEventData( resolveEventData(this.props, {
this.props, value
{ })
value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -417,13 +413,9 @@ export class Input extends React.Component<RangeItemProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'focus', 'focus',
resolveEventData( resolveEventData(this.props, {
this.props, value
{ })
value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -582,13 +574,9 @@ export default class RangeControl extends React.PureComponent<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value: result
{ })
value: result
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -111,7 +111,7 @@ export default class RatingControl extends React.Component<RatingProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -230,7 +230,7 @@ export interface TableState {
} }
export type FormTableRendererEvent = export type FormTableRendererEvent =
'add' | 'add'
| 'addConfirm' | 'addConfirm'
| 'addSuccess' | 'addSuccess'
| 'addFail' | 'addFail'
@ -315,8 +315,8 @@ export default class FormTable extends React.Component<TableProps, TableState> {
// 如果static为true 或 disabled为true // 如果static为true 或 disabled为true
// 则删掉正在新增 或 编辑的那一行 // 则删掉正在新增 或 编辑的那一行
if ( if (
props.$schema.disabled !== nextProps.$schema.disabled props.$schema.disabled !== nextProps.$schema.disabled ||
|| props.$schema.static !== nextProps.$schema.static props.$schema.static !== nextProps.$schema.static
) { ) {
const items = this.state.items.filter(item => !item.__isPlaceholder); const items = this.state.items.filter(item => !item.__isPlaceholder);
toUpdate = { toUpdate = {
@ -532,10 +532,7 @@ export default class FormTable extends React.Component<TableProps, TableState> {
} else { } else {
return this.addItem(items.length - 1, false); return this.addItem(items.length - 1, false);
} }
} else if ( } else if (actionType === 'remove' || actionType === 'delete') {
actionType === 'remove' ||
actionType === 'delete'
) {
if (!valueField) { if (!valueField) {
return env.alert(__('Table.valueField')); return env.alert(__('Table.valueField'));
} else if (!action.payload) { } else if (!action.payload) {
@ -556,11 +553,14 @@ export default class FormTable extends React.Component<TableProps, TableState> {
} }
}); });
this.setState({ this.setState(
{
items items
}, () => { },
onChange?.(items); () => {
}); onChange?.(items);
}
);
return; return;
} }
@ -692,14 +692,10 @@ export default class FormTable extends React.Component<TableProps, TableState> {
const {items} = this.state; const {items} = this.state;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
eventName, eventName,
resolveEventData( resolveEventData(this.props, {
this.props, value: [...items],
{ ...eventData
value: [...items], })
...eventData
},
'value'
)
); );
return !!rendererEvent?.prevented; return !!rendererEvent?.prevented;
@ -747,7 +743,10 @@ export default class FormTable extends React.Component<TableProps, TableState> {
}; };
const isNew = !!item.__isPlaceholder; const isNew = !!item.__isPlaceholder;
const confirmEventName = isNew ? 'addConfirm' : 'editConfirm'; const confirmEventName = isNew ? 'addConfirm' : 'editConfirm';
let isPrevented = await this.dispatchEvent(confirmEventName, {index: this.state.editIndex, item}); let isPrevented = await this.dispatchEvent(confirmEventName, {
index: this.state.editIndex,
item
});
if (isPrevented) { if (isPrevented) {
return; return;
} }
@ -765,7 +764,11 @@ export default class FormTable extends React.Component<TableProps, TableState> {
if (remote && !remote.ok) { if (remote && !remote.ok) {
env.notify('error', apiMsg ?? (remote.msg || __('saveFailed'))); env.notify('error', apiMsg ?? (remote.msg || __('saveFailed')));
const failEventName = isNew ? 'addFail' : 'editFail'; const failEventName = isNew ? 'addFail' : 'editFail';
this.dispatchEvent(failEventName, {index: this.state.editIndex, item, error: remote}); this.dispatchEvent(failEventName, {
index: this.state.editIndex,
item,
error: remote
});
return; return;
} else if (remote && remote.ok) { } else if (remote && remote.ok) {
item = merge( item = merge(
@ -790,7 +793,10 @@ export default class FormTable extends React.Component<TableProps, TableState> {
return; return;
} }
const successEventName = isNew ? 'addSuccess' : 'editSuccess'; const successEventName = isNew ? 'addSuccess' : 'editSuccess';
this.dispatchEvent(successEventName, {index: this.state.editIndex, item}); this.dispatchEvent(successEventName, {
index: this.state.editIndex,
item
});
} }
); );
} }
@ -993,7 +999,10 @@ export default class FormTable extends React.Component<TableProps, TableState> {
} }
}; };
}); });
} else if (isStatic !== true && (props.addable || props.editable || isCreateMode)) { } else if (
isStatic !== true &&
(props.addable || props.editable || isCreateMode)
) {
columns = columns.map(column => { columns = columns.map(column => {
const quickEdit = const quickEdit =
!isCreateMode && column.hasOwnProperty('quickEditOnUpdate') !isCreateMode && column.hasOwnProperty('quickEditOnUpdate')
@ -1017,7 +1026,8 @@ export default class FormTable extends React.Component<TableProps, TableState> {
}; };
}); });
!isStatic && props.editable && !isStatic &&
props.editable &&
btns.push({ btns.push({
children: ({ children: ({
key, key,
@ -1068,79 +1078,84 @@ export default class FormTable extends React.Component<TableProps, TableState> {
) )
}); });
!isStatic && btns.push({ !isStatic &&
children: ({ btns.push({
key, children: ({
rowIndex, key,
offset rowIndex,
}: { offset
key: any; }: {
rowIndex: number; key: any;
offset: number; rowIndex: number;
}) => offset: number;
this.state.editIndex === rowIndex + offset ? ( }) =>
<Button this.state.editIndex === rowIndex + offset ? (
classPrefix={ns} <Button
size="sm" classPrefix={ns}
key={key} size="sm"
level="link" key={key}
tooltip={__('save')} level="link"
tooltipContainer={ tooltip={__('save')}
env && env.getModalContainer ? env.getModalContainer : undefined tooltipContainer={
} env && env.getModalContainer
onClick={this.confirmEdit} ? env.getModalContainer
> : undefined
{props.confirmBtnIcon ? ( }
typeof props.confirmBtnIcon === 'string' ? ( onClick={this.confirmEdit}
<Icon icon={props.confirmBtnIcon} className="icon" /> >
) : ( {props.confirmBtnIcon ? (
generateIcon(props.classnames, props.confirmBtnIcon) typeof props.confirmBtnIcon === 'string' ? (
) <Icon icon={props.confirmBtnIcon} className="icon" />
) : null} ) : (
{props.confirmBtnLabel ? ( generateIcon(props.classnames, props.confirmBtnIcon)
<span>{props.confirmBtnLabel}</span> )
) : null} ) : null}
</Button> {props.confirmBtnLabel ? (
) : null <span>{props.confirmBtnLabel}</span>
}); ) : null}
</Button>
) : null
});
!isStatic && btns.push({ !isStatic &&
children: ({ btns.push({
key, children: ({
rowIndex, key,
offset rowIndex,
}: { offset
key: any; }: {
rowIndex: number; key: any;
offset: number; rowIndex: number;
}) => offset: number;
this.state.editIndex === rowIndex + offset ? ( }) =>
<Button this.state.editIndex === rowIndex + offset ? (
classPrefix={ns} <Button
size="sm" classPrefix={ns}
key={key} size="sm"
level="link" key={key}
tooltip={__('cancel')} level="link"
tooltipContainer={ tooltip={__('cancel')}
env && env.getModalContainer ? env.getModalContainer : undefined tooltipContainer={
} env && env.getModalContainer
onClick={this.cancelEdit} ? env.getModalContainer
> : undefined
{props.cancelBtnIcon ? ( }
typeof props.cancelBtnIcon === 'string' ? ( onClick={this.cancelEdit}
<Icon icon={props.cancelBtnIcon} className="icon" /> >
) : ( {props.cancelBtnIcon ? (
generateIcon(props.classnames, props.cancelBtnIcon) typeof props.cancelBtnIcon === 'string' ? (
) <Icon icon={props.cancelBtnIcon} className="icon" />
) : null} ) : (
{props.cancelBtnLabel ? ( generateIcon(props.classnames, props.cancelBtnIcon)
<span>{props.cancelBtnLabel}</span> )
) : null} ) : null}
</Button> {props.cancelBtnLabel ? (
) : null <span>{props.cancelBtnLabel}</span>
}); ) : null}
} </Button>
else { ) : null
});
} else {
columns = columns.map(column => { columns = columns.map(column => {
const render = getRendererByName(column?.type); const render = getRendererByName(column?.type);
if (!!render?.isFormItem) { if (!!render?.isFormItem) {
@ -1150,7 +1165,7 @@ export default class FormTable extends React.Component<TableProps, TableState> {
...column, ...column,
isFormMode: true isFormMode: true
} }
} };
} }
return column; return column;
}); });
@ -1316,25 +1331,31 @@ export default class FormTable extends React.Component<TableProps, TableState> {
} }
}); });
const data = mergeWith({}, origin, diff, ( const data = mergeWith(
objValue: any, {},
srcValue: any, origin,
key: string, diff,
object: any, (
source: any, objValue: any,
stack: any srcValue: any,
) => { key: string,
// 只对第一层做处理如果不是combo并且是数组直接采用diff的值 object: any,
if ( source: any,
stack.size === 0 stack: any
&& comboNames.indexOf(key) === -1 ) => {
&& Array.isArray(objValue) // 只对第一层做处理如果不是combo并且是数组直接采用diff的值
&& Array.isArray(srcValue)) { if (
return srcValue; stack.size === 0 &&
comboNames.indexOf(key) === -1 &&
Array.isArray(objValue) &&
Array.isArray(srcValue)
) {
return srcValue;
}
// 直接return默认走的mergeWith自身的merge
return;
} }
// 直接return默认走的mergeWith自身的merge );
return;
});
items = spliceTree(items, indexes, 1, data); items = spliceTree(items, indexes, 1, data);
this.entries.set(data, this.entries.get(origin) || this.entityId++); this.entries.set(data, this.entries.get(origin) || this.entityId++);
@ -1482,7 +1503,9 @@ export default class FormTable extends React.Component<TableProps, TableState> {
label: __('Table.add'), label: __('Table.add'),
icon: 'fa fa-plus', icon: 'fa fa-plus',
disabled: footerAddBtnDisabled, disabled: footerAddBtnDisabled,
...(footerAddBtnDisabled ? {disabledTip: __('Table.addButtonDisabledTip')} : {}) ...(footerAddBtnDisabled
? {disabledTip: __('Table.addButtonDisabledTip')}
: {})
}; };
if (footerAddBtn !== undefined) { if (footerAddBtn !== undefined) {
@ -1530,16 +1553,17 @@ export default class FormTable extends React.Component<TableProps, TableState> {
// onPristineChange: this.handlePristineChange // onPristineChange: this.handlePristineChange
} }
)} )}
{(!isStatic && addable && {(!isStatic &&
addable &&
showFooterAddBtn !== false && showFooterAddBtn !== false &&
(!maxLength || maxLength > items.length)) || (!maxLength || maxLength > items.length)) ||
showPager ? ( showPager ? (
<div className={cx('InputTable-toolbar')}> <div className={cx('InputTable-toolbar')}>
{addable && showFooterAddBtn !== false ? ( {addable && showFooterAddBtn !== false
render('button', footerAddBtnSchema, { ? render('button', footerAddBtnSchema, {
onClick: () => this.addItem(this.state.items.length) onClick: () => this.addItem(this.state.items.length)
}) })
) : null} : null}
{showPager {showPager
? render( ? render(
@ -1571,12 +1595,19 @@ export class TableControlRenderer extends FormTable {
// 如果setValue动作传入了index更新指定索引的值 // 如果setValue动作传入了index更新指定索引的值
const items = [...this.state.items]; const items = [...this.state.items];
items.splice(index, 1, value); items.splice(index, 1, value);
this.setState({items}, () => {this.emitValue()}); this.setState({items}, () => {
this.emitValue();
});
} else { } else {
// 如果setValue动作没有传入index则直接替换组件数据 // 如果setValue动作没有传入index则直接替换组件数据
this.setState({ this.setState(
items: [...value] {
}, () => {this.emitValue()}); items: [...value]
},
() => {
this.emitValue();
}
);
} }
} }
@ -1635,7 +1666,8 @@ export class TableControlRenderer extends FormTable {
!valueField || !valueField ||
!find( !find(
items, items,
item => item[valueField as string] == toAdd[i - 1][valueField as string] item =>
item[valueField as string] == toAdd[i - 1][valueField as string]
) )
) { ) {
items.splice(pushIndex, 0, toAdd[i - 1]); items.splice(pushIndex, 0, toAdd[i - 1]);
@ -1683,7 +1715,10 @@ export class TableControlRenderer extends FormTable {
} }
// 删除api // 删除api
if (isEffectiveApi(deleteApi, createObject(ctx, {deletedItems}))) { if (isEffectiveApi(deleteApi, createObject(ctx, {deletedItems}))) {
const payload = await env.fetcher(deleteApi, createObject(ctx, {deletedItems})); const payload = await env.fetcher(
deleteApi,
createObject(ctx, {deletedItems})
);
if (payload && !payload.ok) { if (payload && !payload.ok) {
env.notify( env.notify(
'error', 'error',
@ -1693,26 +1728,35 @@ export class TableControlRenderer extends FormTable {
return; return;
} }
} }
this.setState({ this.setState(
items: rawItems {
}, () => { items: rawItems
onChange?.(rawItems); },
}); () => {
onChange?.(rawItems);
}
);
return; return;
} else if (actionType === 'clear') { } else if (actionType === 'clear') {
this.setState({ this.setState(
items: [] {
}, () => { items: []
onChange?.([]); },
}); () => {
onChange?.([]);
}
);
return; return;
} else if (actionType === 'reset') { } else if (actionType === 'reset') {
const newItems = Array.isArray(resetValue) ? resetValue : []; const newItems = Array.isArray(resetValue) ? resetValue : [];
this.setState({ this.setState(
items: newItems {
}, () => { items: newItems
onChange?.(newItems); },
}); () => {
onChange?.(newItems);
}
);
return; return;
} }
return super.doAction(action as ActionObject, ctx, ...rest); return super.doAction(action as ActionObject, ctx, ...rest);

View File

@ -148,15 +148,11 @@ export default class TagControl extends React.PureComponent<
const {dispatchEvent, options} = this.props; const {dispatchEvent, options} = this.props;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
eventName, eventName,
resolveEventData( resolveEventData(this.props, {
this.props, options,
{ items: options, // 为了保持名字统一
options, ...eventData
items: options, // 为了保持名字统一 })
...eventData
},
'value'
)
); );
// 返回阻塞标识 // 返回阻塞标识
return !!rendererEvent?.prevented; return !!rendererEvent?.prevented;

View File

@ -310,13 +310,9 @@ export default class TextControl extends React.PureComponent<
const {dispatchEvent, value} = this.props; const {dispatchEvent, value} = this.props;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'click', 'click',
resolveEventData( resolveEventData(this.props, {
this.props, value
{ })
value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -338,13 +334,9 @@ export default class TextControl extends React.PureComponent<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'focus', 'focus',
resolveEventData( resolveEventData(this.props, {
this.props, value
{ })
value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -370,13 +362,9 @@ export default class TextControl extends React.PureComponent<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'blur', 'blur',
resolveEventData( resolveEventData(this.props, {
this.props, value
{ })
value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -391,7 +379,7 @@ export default class TextControl extends React.PureComponent<
const {creatable, multiple, onChange, dispatchEvent} = this.props; const {creatable, multiple, onChange, dispatchEvent} = this.props;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -455,7 +443,7 @@ export default class TextControl extends React.PureComponent<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'enter', 'enter',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -571,7 +559,7 @@ export default class TextControl extends React.PureComponent<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -266,7 +266,7 @@ export default class TreeControl extends React.Component<TreeProps, TreeState> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -281,7 +281,7 @@ export default class MatrixCheckbox extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: value.concat()}, 'value') resolveEventData(this.props, {value: value.concat()})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -1,8 +1,19 @@
import React from 'react'; import React from 'react';
import {ResultBox, Spinner,Icon, PopUp, Checkbox, Cascader, SpinnerExtraProps} from 'amis-ui';
import { import {
Overlay, resolveEventData, ResultBox,
PopOver, Option, Options, Spinner,
Icon,
PopUp,
Checkbox,
Cascader,
SpinnerExtraProps
} from 'amis-ui';
import {
Overlay,
resolveEventData,
PopOver,
Option,
Options,
autobind, autobind,
flattenTree, flattenTree,
filterTree, filterTree,
@ -136,7 +147,7 @@ export default class NestedSelectControl extends React.Component<
const {dispatchEvent} = this.props; const {dispatchEvent} = this.props;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
eventName, eventName,
resolveEventData(this.props, eventData, 'value') resolveEventData(this.props, eventData)
); );
// 返回阻塞标识 // 返回阻塞标识
return !!rendererEvent?.prevented; return !!rendererEvent?.prevented;

View File

@ -288,11 +288,7 @@ export default class PickerControl extends React.PureComponent<
const option = multiple ? items : items[0]; const option = multiple ? items : items[0];
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {value, option, selectedItems: option})
this.props,
{value, option, selectedItems: option},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -73,16 +73,12 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value,
{ options,
value, items: options, // 为了保持名字统一
options, selectedItems: option
items: options, // 为了保持名字统一 })
selectedItems: option
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -274,18 +274,14 @@ export default class SelectControl extends React.Component<SelectProps, any> {
// 触发渲染器事件 // 触发渲染器事件
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
eventName, eventName,
resolveEventData( resolveEventData(this.props, {
this.props, options,
{ items: options, // 为了保持名字统一
options, value: ['onEdit', 'onDelete'].includes(event)
items: options, // 为了保持名字统一 ? eventData
value: ['onEdit', 'onDelete'].includes(event) : eventData && eventData.value,
? eventData selectedItems: multiple ? selectedOptions : selectedOptions[0]
: eventData && eventData.value, })
selectedItems: multiple ? selectedOptions : selectedOptions[0]
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;
@ -308,16 +304,12 @@ export default class SelectControl extends React.Component<SelectProps, any> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value: newValue,
{ options,
value: newValue, items: options, // 为了保持名字统一
options, selectedItems: value
items: options, // 为了保持名字统一 })
selectedItems: value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -73,7 +73,7 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
const {dispatchEvent, onChange} = this.props; const {dispatchEvent, onChange} = this.props;
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value: checked}, 'value') resolveEventData(this.props, {value: checked})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;
@ -83,11 +83,7 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
} }
getResult() { getResult() {
const { const {classnames: cx, onText, offText} = this.props;
classnames: cx,
onText,
offText,
} = this.props;
const on = isObject(onText) const on = isObject(onText)
? generateIcon(cx, onText.icon, 'Switch-icon') ? generateIcon(cx, onText.icon, 'Switch-icon')
: onText; : onText;
@ -98,11 +94,7 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
} }
renderBody(children: any) { renderBody(children: any) {
const { const {classnames: cx, option, optionAtLeft} = this.props;
classnames: cx,
option,
optionAtLeft
} = this.props;
const Option = <span className={cx('Switch-option')}>{option}</span>; const Option = <span className={cx('Switch-option')}>{option}</span>;
return ( return (
@ -115,11 +107,8 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
} }
renderStatic() { renderStatic() {
const { const {value, trueValue} = this.props;
value,
trueValue,
} = this.props;
const {on = '开', off = '关'} = this.getResult(); const {on = '开', off = '关'} = this.getResult();
const body = <span>{value === trueValue ? on : off}</span>; const body = <span>{value === trueValue ? on : off}</span>;
return this.renderBody(body); return this.renderBody(body);
@ -137,7 +126,7 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
trueValue, trueValue,
falseValue, falseValue,
onChange, onChange,
disabled, disabled
} = this.props; } = this.props;
const {on, off} = this.getResult(); const {on, off} = this.getResult();

View File

@ -218,15 +218,11 @@ export class BaseTabsTransferRenderer<
// 触发渲染器事件 // 触发渲染器事件
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value: newValue,
{ options,
value: newValue, items: options // 为了保持名字统一
options, })
items: options // 为了保持名字统一
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -47,7 +47,7 @@ export class TabsTransferPickerRenderer extends BaseTabsTransferRenderer<TabsTra
@autobind @autobind
dispatchEvent(name: string) { dispatchEvent(name: string) {
const {dispatchEvent, value} = this.props; const {dispatchEvent, value} = this.props;
dispatchEvent(name, resolveEventData(this.props, {value}, 'value')); dispatchEvent(name, resolveEventData(this.props, {value}));
} }
@autobind @autobind

View File

@ -109,7 +109,7 @@ export default class TextAreaControl extends React.Component<
handleChange(e: React.ChangeEvent<HTMLTextAreaElement>) { handleChange(e: React.ChangeEvent<HTMLTextAreaElement>) {
const {onChange, dispatchEvent} = this.props; const {onChange, dispatchEvent} = this.props;
dispatchEvent('change', resolveEventData(this.props, {value: e}, 'value')); dispatchEvent('change', resolveEventData(this.props, {value: e}));
onChange && onChange(e); onChange && onChange(e);
} }
@ -125,7 +125,7 @@ export default class TextAreaControl extends React.Component<
async () => { async () => {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'focus', 'focus',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -151,7 +151,7 @@ export default class TextAreaControl extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'blur', 'blur',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -277,15 +277,11 @@ export class BaseTransferRenderer<
// 触发渲染器事件 // 触发渲染器事件
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value: newValue,
{ options,
value: newValue, items: options // 为了保持名字统一
options, })
items: options // 为了保持名字统一
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -44,7 +44,7 @@ export class TransferPickerRenderer extends BaseTransferRenderer<TabsTransferPro
@autobind @autobind
dispatchEvent(name: string) { dispatchEvent(name: string) {
const {dispatchEvent, value} = this.props; const {dispatchEvent, value} = this.props;
dispatchEvent(name, resolveEventData(this.props, {value}, 'value')); dispatchEvent(name, resolveEventData(this.props, {value}));
} }
// 动作 // 动作

View File

@ -236,12 +236,12 @@ export default class TreeSelectControl extends React.Component<
handleFocus(e: any) { handleFocus(e: any) {
const {dispatchEvent, value} = this.props; const {dispatchEvent, value} = this.props;
dispatchEvent('focus', resolveEventData(this.props, {value}, 'value')); dispatchEvent('focus', resolveEventData(this.props, {value}));
} }
handleBlur(e: any) { handleBlur(e: any) {
const {dispatchEvent, value, data} = this.props; const {dispatchEvent, value, data} = this.props;
dispatchEvent('blur', resolveEventData(this.props, {value}, 'value')); dispatchEvent('blur', resolveEventData(this.props, {value}));
} }
handleKeyPress(e: React.KeyboardEvent) { handleKeyPress(e: React.KeyboardEvent) {
@ -486,7 +486,7 @@ export default class TreeSelectControl extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData(this.props, {value}, 'value') resolveEventData(this.props, {value})
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {

View File

@ -191,15 +191,11 @@ export default class UserSelectControl extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value: newValue,
{ options,
value: newValue, items: options // 为了保持名字统一
options, })
items: options // 为了保持名字统一
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;

View File

@ -119,13 +119,9 @@ export class SearchBoxRenderer extends React.Component<
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value
{ })
value
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
@ -171,7 +167,7 @@ export class SearchBoxRenderer extends React.Component<
const {dispatchEvent} = this.props; const {dispatchEvent} = this.props;
dispatchEvent( dispatchEvent(
name, name,
resolveEventData(this.props, {value: this.state.value}, 'value') resolveEventData(this.props, {value: this.state.value})
); );
} }

View File

@ -640,13 +640,9 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
const rendererEvent = await dispatchEvent( const rendererEvent = await dispatchEvent(
'change', 'change',
resolveEventData( resolveEventData(this.props, {
this.props, value: tab?.hash ? tab?.hash : key + 1
{ })
value: tab?.hash ? tab?.hash : key + 1
},
'value'
)
); );
if (rendererEvent?.prevented) { if (rendererEvent?.prevented) {
return; return;