Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 级联选择器增加选中项标题事件动作变量 #11325

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/amis-editor/src/plugin/Form/NestedSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class NestedSelectControlPlugin extends BasePlugin {
eventLabel: '值变化',
description: '选中值变化时触发',
dataSchema: (manager: EditorManager) => {
const {value} = resolveOptionEventDataSchame(manager);
const {value, selectedItems} = resolveOptionEventDataSchame(manager);

return [
{
Expand All @@ -141,7 +141,8 @@ export class NestedSelectControlPlugin extends BasePlugin {
type: 'object',
title: '数据',
properties: {
value
value,
selectedItems
}
}
}
Expand All @@ -154,7 +155,7 @@ export class NestedSelectControlPlugin extends BasePlugin {
eventLabel: '获取焦点',
description: '输入框获取焦点时触发',
dataSchema: (manager: EditorManager) => {
const {value} = resolveOptionEventDataSchame(manager);
const {value, selectedItems} = resolveOptionEventDataSchame(manager);

return [
{
Expand All @@ -164,7 +165,8 @@ export class NestedSelectControlPlugin extends BasePlugin {
type: 'object',
title: '数据',
properties: {
value
value,
selectedItems
}
}
}
Expand All @@ -177,7 +179,7 @@ export class NestedSelectControlPlugin extends BasePlugin {
eventLabel: '失去焦点',
description: '输入框失去焦点时触发',
dataSchema: (manager: EditorManager) => {
const {value} = resolveOptionEventDataSchame(manager);
const {value, selectedItems} = resolveOptionEventDataSchame(manager);

return [
{
Expand All @@ -187,7 +189,8 @@ export class NestedSelectControlPlugin extends BasePlugin {
type: 'object',
title: '数据',
properties: {
value
value,
selectedItems
}
}
}
Expand Down
32 changes: 12 additions & 20 deletions packages/amis/src/renderers/Form/NestedSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,18 @@ export default class NestedSelectControl extends React.Component<

@autobind
async dispatchEvent(eventName: string, eventData: any = {}) {
const {dispatchEvent} = this.props;
const {dispatchEvent, options, multiple, value, selectedOptions} =
this.props;

const rendererEvent = await dispatchEvent(
eventName,
resolveEventData(this.props, eventData)
resolveEventData(this.props, {
options,
items: options, // 为了保持名字统一
value,
selectedItems: multiple ? selectedOptions : selectedOptions[0],
...eventData
})
);
// 返回阻塞标识
return !!rendererEvent?.prevented;
Expand Down Expand Up @@ -210,29 +218,13 @@ export default class NestedSelectControl extends React.Component<
}

async removeItem(index: number, e?: React.MouseEvent<HTMLElement>) {
let {
onChange,
selectedOptions,
joinValues,
valueField,
extractValue,
delimiter,
value
} = this.props;
let {onChange, selectedOptions} = this.props;

e && e.stopPropagation();

selectedOptions.splice(index, 1);

if (joinValues) {
value = (selectedOptions as Options)
.map(item => item[valueField || 'value'])
.join(delimiter || ',');
} else if (extractValue) {
value = (selectedOptions as Options).map(
item => item[valueField || 'value']
);
}
const value = this.getValue();

const isPrevented = await this.dispatchEvent('change', {
value
Expand Down
Loading