Skip to content

Commit

Permalink
feat(amis-editor): inputNumber unitOptions支持key-value形式,修复value是numbe…
Browse files Browse the repository at this point in the history
…r时错误相加问题,新增配置面板编辑时组件实时更新 (baidu#8437)

* feat: unitOptions支持key-value形式,修复value是number时错误相加问题,新增配置面板编辑时组件实时更新

* feat: unitOptions支持key-value形式,修复value是number时错误相加问题,新增配置面板编辑时组件实时更新

* fix snap

* fix snap
  • Loading branch information
Hsirius authored Oct 20, 2023
1 parent c6d52cb commit aabc616
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
26 changes: 20 additions & 6 deletions packages/amis-editor/src/plugin/Form/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,36 @@ export class NumberControlPlugin extends BasePlugin {
label: '单位选项',
mode: 'normal',
name: 'unitOptions',
flat: true,
items: [
{
placeholder: '单位选项',
placeholder: 'label',
type: i18nEnabled ? 'input-text-i18n' : 'input-text',
name: 'text'
name: 'label'
},
{
placeholder: 'value',
type: i18nEnabled ? 'input-text-i18n' : 'input-text',
name: 'value'
}
],
draggable: false,
multiple: true,
pipeIn: (value: any) => {
if (!isObject(value)) {
return Array.isArray(value) ? value : [];
if (Array.isArray(value)) {
return value.every(item => typeof item === 'string')
? value.map((item: any) => ({
label: item,
value: item
}))
: value;
}
return [];
}
const res = value.map((item: any) => item.value);
return res;
return value.map((item: any) => ({
label: item.value,
value: item.value
}));
},
pipeOut: (value: any[]) => {
if (!value.length) {
Expand Down
5 changes: 3 additions & 2 deletions packages/amis/src/renderers/Form/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export default class NumberControl extends React.Component<
}

if (inputValue !== null && unitOptions && this.state.unit) {
inputValue = inputValue + this.state.unit;
inputValue = inputValue + String(this.state.unit);
}
return inputValue === null ? resetValue ?? null : inputValue;
}
Expand Down Expand Up @@ -551,7 +551,8 @@ export default class NumberControl extends React.Component<
}

@FormItem({
type: 'input-number'
type: 'input-number',
detectProps: ['unitOptions']
})
export class NumberControlRenderer extends NumberControl {
static defaultProps: Partial<FormControlProps> = {
Expand Down

0 comments on commit aabc616

Please sign in to comment.