This commit is contained in:
liaoxuezhi 2019-08-05 11:55:53 +08:00
commit 52a0e26a31
16 changed files with 102 additions and 30 deletions

View File

@ -11,6 +11,8 @@
- `extractValue` 默认为 `false`, `joinValues`设置为`false`时生效, 开启后将选中的选项 value 的值封装为数组,作为当前表单项的值。 - `extractValue` 默认为 `false`, `joinValues`设置为`false`时生效, 开启后将选中的选项 value 的值封装为数组,作为当前表单项的值。
- `delimiter` 默认为 `,` - `delimiter` 默认为 `,`
- `columnsCount` 默认为 `1` 可以配置成一行显示多个。 - `columnsCount` 默认为 `1` 可以配置成一行显示多个。
- `checkAll` 默认为 `false` 开启后支持全选
- `defaultCheckAll` 是否默认全选,默认为`false`
- **还有更多通用配置请参考** [FormItem](./FormItem.md) - **还有更多通用配置请参考** [FormItem](./FormItem.md)
```schema:height="330" scope="form" ```schema:height="330" scope="form"

View File

@ -4,6 +4,8 @@
- `type` 请设置成 `color` - `type` 请设置成 `color`
- `format` 请选择 `hex`、`hls`、`rgb`或者`rgba`。默认为 `hex` - `format` 请选择 `hex`、`hls`、`rgb`或者`rgba`。默认为 `hex`
- `presetColors` 选择器底部的默认颜色
- 默认为`['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']`,数组内为空则不显示默认颜色
- `clearable` 是否显示清除按钮。 - `clearable` 是否显示清除按钮。
```schema:height="400" scope="form-item" ```schema:height="400" scope="form-item"

View File

@ -134,6 +134,7 @@
&-content { &-content {
min-height: 0.01%; min-height: 0.01%;
overflow-x: auto; overflow-x: auto;
transform: translateZ(0);
} }
&-table { &-table {

View File

@ -27,6 +27,7 @@ export interface ColorProps {
classPrefix: string; classPrefix: string;
classnames: ClassNamesFn; classnames: ClassNamesFn;
onChange: (value: any) => void; onChange: (value: any) => void;
presetColors?: string[];
} }
export interface ColorControlState { export interface ColorControlState {
@ -178,6 +179,7 @@ export class ColorControl extends React.PureComponent<ColorProps, ColorControlSt
clearable, clearable,
placement, placement,
classnames: cx, classnames: cx,
presetColors
} = this.props; } = this.props;
const isOpened = this.state.isOpened; const isOpened = this.state.isOpened;
@ -236,6 +238,7 @@ export class ColorControl extends React.PureComponent<ColorProps, ColorControlSt
<SketchPicker <SketchPicker
disableAlpha={!!~['rgb', 'hex'].indexOf(format as string)} disableAlpha={!!~['rgb', 'hex'].indexOf(format as string)}
color={value} color={value}
presetColors={presetColors}
onChangeComplete={this.handleChange} onChangeComplete={this.handleChange}
/> />
</PopOver> </PopOver>

View File

@ -43,7 +43,14 @@ export class Radios extends React.Component<RadioProps, any> {
}; };
toggleOption(option: Option) { toggleOption(option: Option) {
const {value, onChange, joinValues, extractValue, valueField, clearable, delimiter, options} = this.props; const {
value,
onChange,
valueField,
clearable,
delimiter,
options
} = this.props;
let valueArray = value2array(value, { let valueArray = value2array(value, {
multiple: false, multiple: false,
@ -61,14 +68,6 @@ export class Radios extends React.Component<RadioProps, any> {
let newValue = valueArray[0]; let newValue = valueArray[0];
if (newValue && (joinValues || extractValue)) {
newValue = newValue[valueField || 'value'];
}
// if (joinValues && newValue) {
// newValue = newValue[valueField || 'value'];
// }
onChange && onChange(newValue); onChange && onChange(newValue);
} }

View File

@ -44,6 +44,7 @@ export interface OptionProps {
delimiter?: string; delimiter?: string;
clearable?: boolean; clearable?: boolean;
placeholder?: string; placeholder?: string;
autoFill?: {[propName:string]: any}
} }
export type OptionValue = string | number | null | undefined | Option; export type OptionValue = string | number | null | undefined | Option;
@ -482,17 +483,12 @@ export class Select extends React.Component<SelectProps, SelectState> {
if ( if (
inputValue && inputValue &&
creatable && creatable &&
(!filtedOptions.length || !find(options, (item) => item[labelField || 'label'] == inputValue)
(isOpen &&
loadOptions &&
!matchSorter(options, inputValue, {
keys: [labelField || 'label', valueField || 'value'],
}).length))
) { ) {
filtedOptions.push({ filtedOptions.unshift({
[labelField]: inputValue, [labelField]: inputValue,
[valueField]: inputValue, [valueField]: inputValue,
isNew: true, isNew: true
}); });
} }

View File

@ -55,7 +55,7 @@ const defaultSchema = {
<% } %> <% } %>
<% } else if (data.hasOwnProperty('html')) { %> <% } else if (data.hasOwnProperty('html')) { %>
<%= data.html %> <%= data.html %>
<% } else if (data.hasOwnproperty('item')) { %> <% } else if (data.hasOwnProperty('item')) { %>
<%= data.item %> <%= data.item %>
<% } else { %> <% } else { %>
<%= '未找到渲染数据' %> <%= '未找到渲染数据' %>

View File

@ -2,12 +2,14 @@ import React from 'react';
import cx from 'classnames'; import cx from 'classnames';
import { import {
OptionsControl, OptionsControl,
OptionsControlProps OptionsControlProps,
Option
} from './Options'; } from './Options';
import { import {
Button Button
} from '../../types'; } from '../../types';
import { getLevelFromClassName } from '../../utils/helper'; import { getLevelFromClassName, autobind, isEmpty} from '../../utils/helper';
import { dataMapping } from '../../utils/tpl-builtin';
export interface ButtonGroupProps extends OptionsControlProps { export interface ButtonGroupProps extends OptionsControlProps {
buttons?: Array<Button>; buttons?: Array<Button>;
@ -26,6 +28,20 @@ export default class ButtonGroupControl extends React.Component<ButtonGroupProps
vertical: false vertical: false
} }
@autobind
handleToggle(option: Option) {
const {
onToggle,
multiple,
autoFill,
onBulkChange
} = this.props;
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, option as Option);
sendTo && onBulkChange(sendTo);
onToggle(option)
}
render(props = this.props) { render(props = this.props) {
const { const {
render, render,
@ -38,7 +54,6 @@ export default class ButtonGroupControl extends React.Component<ButtonGroupProps
placeholder, placeholder,
btnClassName, btnClassName,
btnActiveClassName, btnActiveClassName,
onToggle,
selectedOptions, selectedOptions,
buttons, buttons,
size, size,
@ -69,7 +84,7 @@ export default class ButtonGroupControl extends React.Component<ButtonGroupProps
className: cx(option.className, btnClassName), className: cx(option.className, btnClassName),
disabled: option.disabled || disabled, disabled: option.disabled || disabled,
onClick: (e:React.UIEvent<any>) => { onClick: (e:React.UIEvent<any>) => {
onToggle(option); this.handleToggle(option);
e.preventDefault(); // 禁止 onAction 触发 e.preventDefault(); // 禁止 onAction 触发
} }
}); });

View File

@ -7,7 +7,6 @@ import {
import cx from 'classnames'; import cx from 'classnames';
import Checkbox from '../../components/Checkbox'; import Checkbox from '../../components/Checkbox';
import chunk = require('lodash/chunk'); import chunk = require('lodash/chunk');
import { autobind } from '../../utils/helper';
export interface CheckboxesProps extends OptionsControlProps { export interface CheckboxesProps extends OptionsControlProps {
placeholder?: any; placeholder?: any;

View File

@ -11,6 +11,7 @@ export interface ColorProps extends FormControlProps {
format?: string; format?: string;
timeConstrainst?: object; timeConstrainst?: object;
closeOnSelect?:boolean; closeOnSelect?:boolean;
presetColors?: string[];
}; };
export interface ColorControlState { export interface ColorControlState {

View File

@ -294,6 +294,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
files.splice(idx, 1, newFile); files.splice(idx, 1, newFile);
this.current = null; this.current = null;
this.setState({ this.setState({
error: error ? error : null,
files: files files: files
}, this.tick); }, this.tick);
})); }));

View File

@ -6,7 +6,8 @@ import {
} from './Options'; } from './Options';
import { Item } from 'react-bootstrap/lib/Breadcrumb'; import { Item } from 'react-bootstrap/lib/Breadcrumb';
import { Schema } from '../../types'; import { Schema } from '../../types';
import { createObject } from '../../utils/helper'; import { createObject, isEmpty } from '../../utils/helper';
import {dataMapping} from '../../utils/tpl-builtin';
export interface ListProps extends OptionsControlProps { export interface ListProps extends OptionsControlProps {
imageClassName: string; imageClassName: string;
@ -38,7 +39,17 @@ export default class ListControl extends React.Component<ListProps, any> {
return; return;
} }
this.props.onToggle(option); const {
onToggle,
multiple,
autoFill,
onBulkChange
} = this.props;
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, option as Option);
sendTo && onBulkChange(sendTo);
onToggle(option);
} }
render() { render() {

View File

@ -6,7 +6,8 @@ import Checkbox from '../../components/Checkbox';
import PopOver from '../../components/PopOver'; import PopOver from '../../components/PopOver';
import {RootCloseWrapper} from 'react-overlays'; import {RootCloseWrapper} from 'react-overlays';
import {closeIcon, rightArrowIcon} from '../../components/icons'; import {closeIcon, rightArrowIcon} from '../../components/icons';
import {autobind, flattenTree} from '../../utils/helper' import {autobind, flattenTree, isEmpty} from '../../utils/helper';
import {dataMapping} from '../../utils/tpl-builtin';
import { import {
OptionsControl, OptionsControl,
@ -102,10 +103,16 @@ export default class NestedSelectControl extends React.Component<NestedSelectPro
onChange, onChange,
joinValues, joinValues,
extractValue, extractValue,
valueField valueField,
autoFill,
onBulkChange
} = this.props; } = this.props;
e.stopPropagation(); e.stopPropagation();
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, option);
sendTo && onBulkChange(sendTo);
onChange(joinValues ? option[valueField || 'value'] : extractValue ? option[valueField || 'value'] : option); onChange(joinValues ? option[valueField || 'value'] : extractValue ? option[valueField || 'value'] : option);
!multiple && this.close(); !multiple && this.close();
} }

View File

@ -17,6 +17,8 @@ import findIndex = require('lodash/findIndex');
import Html from '../../components/Html'; import Html from '../../components/Html';
import { filter } from '../../utils/tpl'; import { filter } from '../../utils/tpl';
import { closeIcon } from '../../components/icons'; import { closeIcon } from '../../components/icons';
import {isEmpty} from '../../utils/helper';
import {dataMapping} from '../../utils/tpl-builtin';
export interface PickerProps extends OptionsControlProps { export interface PickerProps extends OptionsControlProps {
modalMode: 'dialog' | 'drawer'; modalMode: 'dialog' | 'drawer';
@ -127,7 +129,9 @@ export default class PickerControl extends React.PureComponent<PickerProps, any>
multiple, multiple,
options, options,
setOptions, setOptions,
onChange onChange,
autoFill,
onBulkChange
} = this.props; } = this.props;
let value: any = items; let value: any = items;
@ -148,6 +152,8 @@ export default class PickerControl extends React.PureComponent<PickerProps, any>
}); });
additionalOptions.length && setOptions(options.concat(additionalOptions)); additionalOptions.length && setOptions(options.concat(additionalOptions));
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, value as Option);
sendTo && onBulkChange(sendTo);
onChange(value); onChange(value);
} }

View File

@ -10,6 +10,8 @@ import {
OptionsControlProps, OptionsControlProps,
Option Option
} from './Options'; } from './Options';
import {autobind, isEmpty} from '../../utils/helper';
import {dataMapping} from '../../utils/tpl-builtin';
export interface RadiosProps extends OptionsControlProps { export interface RadiosProps extends OptionsControlProps {
placeholder?: any; placeholder?: any;
@ -21,6 +23,27 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
columnsCount: 1 columnsCount: 1
} }
@autobind
handleChange(option: Option) {
const {
joinValues,
extractValue,
valueField,
onChange,
autoFill,
onBulkChange
} = this.props;
const sendTo = autoFill && !isEmpty(autoFill) && dataMapping(autoFill, option);
sendTo && onBulkChange && onBulkChange(sendTo);
if (option && (joinValues || extractValue)) {
option = option[valueField || 'value'];
}
onChange && onChange(option);
}
render() { render() {
const { const {
className, className,
@ -46,7 +69,7 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
className={cx(`${ns}RadiosControl`, className)} className={cx(`${ns}RadiosControl`, className)}
value={(typeof value === 'undefined' || value === null) ? '' : value} value={(typeof value === 'undefined' || value === null) ? '' : value}
disabled={disabled} disabled={disabled}
onChange={onChange} onChange={this.handleChange}
joinValues={joinValues} joinValues={joinValues}
extractValue={extractValue} extractValue={extractValue}
delimiter={delimiter} delimiter={delimiter}

View File

@ -10,6 +10,8 @@ import find = require('lodash/find');
import debouce = require('lodash/debounce'); import debouce = require('lodash/debounce');
import {Api} from '../../types'; import {Api} from '../../types';
import {isEffectiveApi} from '../../utils/api'; import {isEffectiveApi} from '../../utils/api';
import {isEmpty} from '../../utils/helper';
import {dataMapping} from '../../utils/tpl-builtin';
export interface SelectProps extends OptionsControlProps { export interface SelectProps extends OptionsControlProps {
autoComplete?: Api; autoComplete?: Api;
@ -55,7 +57,9 @@ export default class SelectControl extends React.Component<SelectProps, any> {
type, type,
onChange, onChange,
setOptions, setOptions,
options options,
autoFill,
onBulkChange
} = this.props; } = this.props;
let newValue: string | Option | Array<Option> | void = value; let newValue: string | Option | Array<Option> | void = value;
@ -83,6 +87,8 @@ export default class SelectControl extends React.Component<SelectProps, any> {
// 不设置没法回显 // 不设置没法回显
additonalOptions.length && setOptions(options.concat(additonalOptions)); additonalOptions.length && setOptions(options.concat(additonalOptions));
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, value as Option);
sendTo && onBulkChange(sendTo);
onChange(newValue); onChange(newValue);
} }