Merge pull request #8317 from igrowp/fix-variable

fix: 数据配置外部接口添加防抖处理,避免输入内容错乱
This commit is contained in:
hsm-lv 2023-10-10 10:01:46 +08:00 committed by GitHub
commit ae13965365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import type {SchemaObject, SchemaCollection, SchemaApi} from 'amis';
import type {Api} from 'amis';
import type {FormControlProps} from 'amis-core';
import type {ActionSchema} from 'amis';
import debounce from 'lodash/debounce';
export type ApiObject = Api & {
messages?: Record<
@ -306,12 +307,9 @@ export default class APIControl extends React.Component<
);
}
@autobind
handleSimpleInputChange(e: React.ChangeEvent<HTMLInputElement>) {
const value = e.currentTarget.value;
handleSimpleInputChange = debounce((value: string) => {
this.handleSubmit(value, 'input');
}
}, 1000);
@autobind
handleSubmit(values: SchemaApi, action?: 'input' | 'picker-submit') {
@ -1036,7 +1034,9 @@ export default class APIControl extends React.Component<
type="text"
disabled={disabled}
placeholder="http://"
onChange={this.handleSimpleInputChange}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
this.handleSimpleInputChange(e.currentTarget.value)
}
/>
)}
{enablePickerMode ? this.renderPickerSchema() : null}

View File

@ -27,6 +27,7 @@ import type {Option} from 'amis';
import {createObject, FormControlProps} from 'amis-core';
import type {OptionValue} from 'amis-core';
import type {SchemaApi} from 'amis';
import debounce from 'lodash/debounce';
export type valueType = 'text' | 'boolean' | 'number';
@ -914,7 +915,7 @@ export default class OptionControl extends React.Component<
body: [
getSchemaTpl('sourceBindControl', {
label: false,
onChange: this.handleAPIChange
onChange: debounce(this.handleAPIChange, 1000)
})
].concat(this.getFuncFieldSchema())
})