Merge pull request #328 from 2betop/master

combo & File &
This commit is contained in:
liaoxuezhi 2019-11-05 11:55:21 +08:00 committed by GitHub
commit 35033be7d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 131 additions and 97 deletions

View File

@ -587,7 +587,8 @@ export class DialogRenderer extends Dialog {
this.tryChildrenToHandle(
{
...action,
actionType: 'submit'
actionType: 'submit',
close: true
},
data,
action

View File

@ -5,13 +5,22 @@ import {Schema, Action, Api} from '../../types';
import {ComboStore, IComboStore} from '../../store/combo';
import {default as CTabs, Tab} from '../../components/Tabs';
import {guid, anyChanged, isObject, createObject, extendObject, autobind} from '../../utils/helper';
import {
guid,
anyChanged,
isObject,
createObject,
extendObject,
autobind,
isObjectShallowModified
} from '../../utils/helper';
import Sortable = require('sortablejs');
import {evalExpression, filter} from '../../utils/tpl';
import find = require('lodash/find');
import Select from '../../components/Select';
import {dataMapping} from '../../utils/tpl-builtin';
import {isEffectiveApi} from '../../utils/api';
import {Alert2} from '../../components';
export interface Condition {
test: string;
@ -291,6 +300,11 @@ export default class ComboControl extends React.Component<ComboProps> {
}
let value = this.getValueAsArray();
const newValue = flat ? values.flat : {...values};
if (!isObjectShallowModified(value[index], newValue)) {
return;
}
value[index] = flat ? values.flat : {...values};
@ -415,9 +429,9 @@ export default class ComboControl extends React.Component<ComboProps> {
return createObject(extendObject(data, {index, __index: index, ...data}), value);
}
pickCondition(value: any): Condition {
const conditions: Array<Condition> = this.props.conditions as Array<Condition>;
return (find(conditions, item => item.test && evalExpression(item.test, value)) || conditions[0]) as Condition;
pickCondition(value: any): Condition | null {
const conditions: Array<Condition> = this.props.conditions!;
return find(conditions, item => item.test && evalExpression(item.test, value)) as Condition | null;
}
handleComboTypeChange(index: number, selection: any) {
@ -541,22 +555,7 @@ export default class ComboControl extends React.Component<ComboProps> {
>
{value.map((value, index) => {
const data = this.formatValue(value, index);
let condition: Condition | null = null;
if (Array.isArray(conditions) && conditions.length) {
condition = this.pickCondition(data);
controls = condition.controls;
}
let finnalControls = flat
? [
{
...(controls && controls[0]),
name: 'flat'
}
]
: controls;
let condition: Condition | null | undefined = null;
let toolbar = undefined;
if (
finnalRemovable && // 表达式判断单条是否可删除
@ -575,6 +574,21 @@ export default class ComboControl extends React.Component<ComboProps> {
);
}
if (Array.isArray(conditions) && conditions.length) {
condition = this.pickCondition(data);
controls = condition ? condition.controls : undefined;
}
let finnalControls =
flat && controls
? [
{
...(controls && controls[0]),
name: 'flat'
}
]
: controls;
return (
<Tab
title={filter(tabsLabelTpl || '成员${index|plus}', data)}
@ -598,26 +612,32 @@ export default class ComboControl extends React.Component<ComboProps> {
</div>
) : null}
<div className={cx(`Combo-itemInner`)}>
{render(
`multiple/${index}`,
{
type: 'form',
controls: finnalControls,
wrapperComponent: 'div',
wrapWithPanel: false,
mode: subFormMode,
className: cx(`Combo-form`, formClassName)
},
{
index,
disabled,
data,
onChange: this.handleChange.bind(this, index),
onInit: this.handleFormInit.bind(this, index),
onAction: this.handleAction,
ref: (ref: any) => this.formRef(ref, index),
canAccessSuperData
}
{finnalControls ? (
render(
`multiple/${index}`,
{
type: 'form',
controls: finnalControls,
wrapperComponent: 'div',
wrapWithPanel: false,
mode: subFormMode,
className: cx(`Combo-form`, formClassName)
},
{
index,
disabled,
data,
onChange: this.handleChange.bind(this, index),
onInit: this.handleFormInit.bind(this, index),
onAction: this.handleAction,
ref: (ref: any) => this.formRef(ref, index),
canAccessSuperData
}
)
) : (
<Alert2 level="warning" className="m-b-none">
</Alert2>
)}
</div>
</Tab>
@ -719,17 +739,18 @@ export default class ComboControl extends React.Component<ComboProps> {
if (Array.isArray(conditions) && conditions.length) {
condition = this.pickCondition(data);
controls = condition.controls;
controls = condition ? condition.controls : undefined;
}
let finnalControls = flat
? [
{
...(controls && controls[0]),
name: 'flat'
}
]
: controls;
let finnalControls =
flat && controls
? [
{
...(controls && controls[0]),
name: 'flat'
}
]
: controls;
return (
<div
@ -750,26 +771,32 @@ export default class ComboControl extends React.Component<ComboProps> {
</div>
) : null}
<div className={cx(`Combo-itemInner`)}>
{render(
`multiple/${index}`,
{
type: 'form',
controls: finnalControls,
wrapperComponent: 'div',
wrapWithPanel: false,
mode: multiLine ? subFormMode : 'row',
className: cx(`Combo-form`, formClassName)
},
{
index,
disabled,
data,
onChange: this.handleChange.bind(this, index),
onInit: this.handleFormInit.bind(this, index),
onAction: this.handleAction,
ref: (ref: any) => this.formRef(ref, index),
canAccessSuperData
}
{finnalControls ? (
render(
`multiple/${index}`,
{
type: 'form',
controls: finnalControls,
wrapperComponent: 'div',
wrapWithPanel: false,
mode: multiLine ? subFormMode : 'row',
className: cx(`Combo-form`, formClassName)
},
{
index,
disabled,
data,
onChange: this.handleChange.bind(this, index),
onInit: this.handleFormInit.bind(this, index),
onAction: this.handleAction,
ref: (ref: any) => this.formRef(ref, index),
canAccessSuperData
}
)
) : (
<Alert2 level="warning" className="m-b-none">
</Alert2>
)}
</div>
{toolbar.length ? <div className={cx(`Combo-itemToolbar`)}>{toolbar}</div> : null}
@ -845,7 +872,7 @@ export default class ComboControl extends React.Component<ComboProps> {
if (Array.isArray(conditions) && conditions.length) {
condition = this.pickCondition(data);
controls = condition.controls;
controls = condition ? condition.controls : undefined;
}
return (
@ -872,24 +899,30 @@ export default class ComboControl extends React.Component<ComboProps> {
) : null}
<div className={cx(`Combo-itemInner`)}>
{render(
'single',
{
type: 'form',
controls,
wrapperComponent: 'div',
wrapWithPanel: false,
mode: multiLine ? 'normal' : 'row',
className: cx(`Combo-form`, formClassName)
},
{
disabled: disabled,
data: isObject(value) ? value : this.defaultValue,
onChange: this.handleSingleFormChange,
ref: (ref: any) => this.formRef(ref),
onInit: this.handleSingleFormInit,
canAccessSuperData
}
{controls ? (
render(
'single',
{
type: 'form',
controls,
wrapperComponent: 'div',
wrapWithPanel: false,
mode: multiLine ? 'normal' : 'row',
className: cx(`Combo-form`, formClassName)
},
{
disabled: disabled,
data: isObject(value) ? value : this.defaultValue,
onChange: this.handleSingleFormChange,
ref: (ref: any) => this.formRef(ref),
onInit: this.handleSingleFormInit,
canAccessSuperData
}
)
) : (
<Alert2 level="warning" className="m-b-none">
</Alert2>
)}
</div>
</div>

View File

@ -79,7 +79,7 @@ let preventEvent = (e: any) => e.stopPropagation();
function getNameFromUrl(url: string) {
if (/(?:\/|^)([^\/]+?)$/.test(url)) {
return RegExp.$1;
return decodeURIComponent(RegExp.$1);
}
return url;

View File

@ -245,7 +245,7 @@ export function isObjectShallowModified(
strictMode: boolean = true,
ignoreUndefined: boolean = false
) {
if (null == prev || null == next || typeof prev !== 'object' || typeof next !== 'object') {
if (null == prev || null == next || !isObject(prev) || !isObject(next)) {
return strictMode ? prev !== next : prev != next;
}

View File

@ -387,14 +387,14 @@ export const tokenize = (str: string, data: object, defaultFilter: string = '| h
return str;
}
return str
.replace(/(\\)?\$(?:([a-z0-9_\.]+|&)|{([^}{]+?)})/gi, (_, escape) =>
escape ? _.substring(1) : resolveVariableAndFilter(_, data, defaultFilter)
)
.replace(/\$\$/g, (_, index: number, source: string) => {
return str.replace(/(\\)?\$(?:([a-z0-9_\.]+|&|\$)|{([^}{]+?)})/gi, (_, escape, key1, key2, index, source) => {
if (!escape && key1 === '$') {
const prefix = source[index - 1];
return prefix === '=' ? encodeURIComponent(JSON.stringify(data)) : qsstringify(data);
});
}
return escape ? _.substring(1) : resolveVariableAndFilter(_, data, defaultFilter);
});
};
function resolveMapping(value: any, data: PlainObject) {