mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 12:38:53 +08:00
Merge 1.1.x & CRUD 的 source 用法优化 (#2188)
* jssdk 产出带版本 * jssdk 产出带版本 * feat:当表单disable时隐藏QuickEdit (#2175) Co-authored-by: qinhaoyan <qinhaoyan@baidu.com> * chore: 更新版本号 * 优化 Static 下的 quickEdit 处理逻辑 * 修复弹框关闭逻辑 * tabs schema 中 activeKey 优先级降低 (#2186) * 同步1.2版本的时间范围选择改动 (#2183) * crud 的 source 用法优化 #2108 Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> Co-authored-by: qinhaoyan <qinhaoyan@baidu.com> Co-authored-by: 吴多益 <wuduoyi@baidu.com> Co-authored-by: RickCole <rickcole21@outlook.com> Co-authored-by: xuzhendong666 <810792608@Outlook.com>
This commit is contained in:
parent
63466f47d2
commit
9ee369a5b7
@ -119,6 +119,7 @@ module.exports = function (ret, pack, settings, opt) {
|
|||||||
if (file) {
|
if (file) {
|
||||||
file.skiped = true;
|
file.skiped = true;
|
||||||
let contents = file.getContent();
|
let contents = file.getContent();
|
||||||
|
|
||||||
|
|
||||||
if (/_map\.js$/.test(file.subpath)) {
|
if (/_map\.js$/.test(file.subpath)) {
|
||||||
contents = `(function() {
|
contents = `(function() {
|
||||||
|
@ -262,7 +262,12 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
|||||||
|
|
||||||
const renderer = this.renderer as RendererConfig;
|
const renderer = this.renderer as RendererConfig;
|
||||||
schema = filterSchema(schema, renderer, rest);
|
schema = filterSchema(schema, renderer, rest);
|
||||||
const {data: defaultData, value: defaultValue, ...restSchema} = schema;
|
const {
|
||||||
|
data: defaultData,
|
||||||
|
value: defaultValue,
|
||||||
|
activeKey: defaultActiveKey,
|
||||||
|
...restSchema
|
||||||
|
} = schema;
|
||||||
const Component = renderer.component;
|
const Component = renderer.component;
|
||||||
|
|
||||||
// 原来表单项的 visible: false 和 hidden: true 表单项的值和验证是有效的
|
// 原来表单项的 visible: false 和 hidden: true 表单项的值和验证是有效的
|
||||||
@ -287,6 +292,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
|||||||
{...exprProps}
|
{...exprProps}
|
||||||
defaultData={defaultData}
|
defaultData={defaultData}
|
||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
|
defaultActiveKey={defaultActiveKey}
|
||||||
$path={$path}
|
$path={$path}
|
||||||
$schema={schema}
|
$schema={schema}
|
||||||
ref={this.refFn}
|
ref={this.refFn}
|
||||||
|
@ -59,6 +59,7 @@ import {ActionSchema} from './Action';
|
|||||||
import {CardsSchema} from './Cards';
|
import {CardsSchema} from './Cards';
|
||||||
import {ListSchema} from './List';
|
import {ListSchema} from './List';
|
||||||
import {TableSchema} from './Table';
|
import {TableSchema} from './Table';
|
||||||
|
import {isPureVariable, resolveVariableAndFilter} from '../utils/tpl-builtin';
|
||||||
|
|
||||||
export type CRUDBultinToolbarType =
|
export type CRUDBultinToolbarType =
|
||||||
| 'columns-toggler'
|
| 'columns-toggler'
|
||||||
@ -529,6 +530,17 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
dataInvalid = true;
|
dataInvalid = true;
|
||||||
|
} else if (!props.api && isPureVariable(props.source)) {
|
||||||
|
const prev = resolveVariableAndFilter(
|
||||||
|
prevProps.source,
|
||||||
|
prevProps.data,
|
||||||
|
'!raw'
|
||||||
|
);
|
||||||
|
const next = resolveVariableAndFilter(props.source, props.data, '!raw');
|
||||||
|
|
||||||
|
if (prev !== next) {
|
||||||
|
store.initFromScope(props.data, props.source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataInvalid) {
|
if (dataInvalid) {
|
||||||
|
@ -11,7 +11,11 @@ import {
|
|||||||
difference,
|
difference,
|
||||||
ucFirst
|
ucFirst
|
||||||
} from '../utils/helper';
|
} from '../utils/helper';
|
||||||
import {resolveVariable} from '../utils/tpl-builtin';
|
import {
|
||||||
|
isPureVariable,
|
||||||
|
resolveVariable,
|
||||||
|
resolveVariableAndFilter
|
||||||
|
} from '../utils/tpl-builtin';
|
||||||
import Sortable from 'sortablejs';
|
import Sortable from 'sortablejs';
|
||||||
import {filter} from '../utils/tpl';
|
import {filter} from '../utils/tpl';
|
||||||
import {Icon} from '../components/icons';
|
import {Icon} from '../components/icons';
|
||||||
@ -258,8 +262,10 @@ export default class Cards extends React.Component<GridProps, object> {
|
|||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
items = value;
|
items = value;
|
||||||
} else if (typeof source === 'string') {
|
} else if (typeof source === 'string') {
|
||||||
const resolved = resolveVariable(source, props.data);
|
const resolved = resolveVariableAndFilter(source, props.data);
|
||||||
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
|
const prev = prevProps
|
||||||
|
? resolveVariableAndFilter(source, prevProps.data)
|
||||||
|
: null;
|
||||||
|
|
||||||
if (prev && prev === resolved) {
|
if (prev && prev === resolved) {
|
||||||
updateItems = false;
|
updateItems = false;
|
||||||
@ -321,7 +327,8 @@ export default class Cards extends React.Component<GridProps, object> {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
anyChanged(['source', 'value', 'items'], prevProps, props) ||
|
anyChanged(['source', 'value', 'items'], prevProps, props) ||
|
||||||
(!props.value && !props.items && props.data !== prevProps.data)
|
(!props.value && !props.items && props.data !== prevProps.data) ||
|
||||||
|
(typeof props.source === 'string' && isPureVariable(props.source))
|
||||||
) {
|
) {
|
||||||
Cards.syncItems(store, props, prevProps);
|
Cards.syncItems(store, props, prevProps);
|
||||||
this.syncSelected();
|
this.syncSelected();
|
||||||
|
@ -771,7 +771,7 @@ export class DialogRenderer extends Dialog {
|
|||||||
} else if (action.actionType === 'reload') {
|
} else if (action.actionType === 'reload') {
|
||||||
store.setCurrentAction(action);
|
store.setCurrentAction(action);
|
||||||
action.target && scoped.reload(action.target, data);
|
action.target && scoped.reload(action.target, data);
|
||||||
if (action.close) {
|
if (action.close || action.type === 'submit') {
|
||||||
this.handleSelfClose();
|
this.handleSelfClose();
|
||||||
this.closeTarget(action.close);
|
this.closeTarget(action.close);
|
||||||
}
|
}
|
||||||
|
@ -58,20 +58,22 @@ export default class StaticControl extends React.Component<StaticProps, any> {
|
|||||||
this.handleQuickChange = this.handleQuickChange.bind(this);
|
this.handleQuickChange = this.handleQuickChange.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleQuickChange(values: any, saveImmediately: boolean | any) {
|
async handleQuickChange(values: any, saveImmediately: boolean | any) {
|
||||||
const {onBulkChange, onAction, data} = this.props;
|
const {onBulkChange, onAction, data} = this.props;
|
||||||
|
|
||||||
onBulkChange(values, saveImmediately === true);
|
|
||||||
if (saveImmediately && saveImmediately.api) {
|
if (saveImmediately && saveImmediately.api) {
|
||||||
onAction(
|
await onAction(
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
actionType: 'ajax',
|
actionType: 'ajax',
|
||||||
api: saveImmediately.api
|
api: saveImmediately.api
|
||||||
},
|
},
|
||||||
extendObject(data, values)
|
extendObject(data, values),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBulkChange(values, saveImmediately === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -16,7 +16,11 @@ import {
|
|||||||
isDisabled,
|
isDisabled,
|
||||||
noop
|
noop
|
||||||
} from '../utils/helper';
|
} from '../utils/helper';
|
||||||
import {resolveVariable} from '../utils/tpl-builtin';
|
import {
|
||||||
|
isPureVariable,
|
||||||
|
resolveVariable,
|
||||||
|
resolveVariableAndFilter
|
||||||
|
} from '../utils/tpl-builtin';
|
||||||
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
|
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
|
||||||
import PopOver, {SchemaPopOver} from './PopOver';
|
import PopOver, {SchemaPopOver} from './PopOver';
|
||||||
import Sortable from 'sortablejs';
|
import Sortable from 'sortablejs';
|
||||||
@ -327,8 +331,10 @@ export default class List extends React.Component<ListProps, object> {
|
|||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
items = value;
|
items = value;
|
||||||
} else if (typeof source === 'string') {
|
} else if (typeof source === 'string') {
|
||||||
const resolved = resolveVariable(source, props.data);
|
const resolved = resolveVariableAndFilter(source, props.data);
|
||||||
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
|
const prev = prevProps
|
||||||
|
? resolveVariableAndFilter(source, prevProps.data)
|
||||||
|
: null;
|
||||||
|
|
||||||
if (prev && prev === resolved) {
|
if (prev && prev === resolved) {
|
||||||
updateItems = false;
|
updateItems = false;
|
||||||
@ -390,7 +396,8 @@ export default class List extends React.Component<ListProps, object> {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
anyChanged(['source', 'value', 'items'], prevProps, props) ||
|
anyChanged(['source', 'value', 'items'], prevProps, props) ||
|
||||||
(!props.value && !props.items && props.data !== prevProps.data)
|
(!props.value && !props.items && props.data !== prevProps.data) ||
|
||||||
|
(typeof props.source === 'string' && isPureVariable(props.source))
|
||||||
) {
|
) {
|
||||||
List.syncItems(store, props, prevProps);
|
List.syncItems(store, props, prevProps);
|
||||||
this.syncSelected();
|
this.syncSelected();
|
||||||
|
@ -258,7 +258,7 @@ export default class Page extends React.Component<PageProps> {
|
|||||||
ctx: object,
|
ctx: object,
|
||||||
throwErrors: boolean = false,
|
throwErrors: boolean = false,
|
||||||
delegate?: IScopedContext
|
delegate?: IScopedContext
|
||||||
) {
|
): any {
|
||||||
const {env, store, messages, onAction} = this.props;
|
const {env, store, messages, onAction} = this.props;
|
||||||
|
|
||||||
if (action.actionType === 'dialog') {
|
if (action.actionType === 'dialog') {
|
||||||
@ -269,7 +269,7 @@ export default class Page extends React.Component<PageProps> {
|
|||||||
store.openDrawer(ctx);
|
store.openDrawer(ctx);
|
||||||
} else if (action.actionType === 'ajax') {
|
} else if (action.actionType === 'ajax') {
|
||||||
store.setCurrentAction(action);
|
store.setCurrentAction(action);
|
||||||
store
|
return store
|
||||||
.saveRemote(action.api as string, ctx, {
|
.saveRemote(action.api as string, ctx, {
|
||||||
successMessage:
|
successMessage:
|
||||||
(action.messages && action.messages.success) ||
|
(action.messages && action.messages.success) ||
|
||||||
@ -290,7 +290,7 @@ export default class Page extends React.Component<PageProps> {
|
|||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
onAction(e, action, ctx, throwErrors, delegate || this.context);
|
return onAction(e, action, ctx, throwErrors, delegate || this.context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,6 +310,8 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (
|
|||||||
false,
|
false,
|
||||||
(quickEdit as QuickEditConfig).resetOnFailed
|
(quickEdit as QuickEditConfig).resetOnFailed
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInit(values: object) {
|
handleInit(values: object) {
|
||||||
@ -513,7 +515,13 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (
|
|||||||
disabled
|
disabled
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (!quickEdit || !onQuickChange || quickEditEnabled === false || noHoc || disabled) {
|
if (
|
||||||
|
!quickEdit ||
|
||||||
|
!onQuickChange ||
|
||||||
|
quickEditEnabled === false ||
|
||||||
|
noHoc ||
|
||||||
|
disabled
|
||||||
|
) {
|
||||||
return <Component {...this.props} />;
|
return <Component {...this.props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,11 @@ import {
|
|||||||
getVariable,
|
getVariable,
|
||||||
removeHTMLTag
|
removeHTMLTag
|
||||||
} from '../../utils/helper';
|
} from '../../utils/helper';
|
||||||
import {resolveVariable} from '../../utils/tpl-builtin';
|
import {
|
||||||
|
isPureVariable,
|
||||||
|
resolveVariable,
|
||||||
|
resolveVariableAndFilter
|
||||||
|
} from '../../utils/tpl-builtin';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import Sortable from 'sortablejs';
|
import Sortable from 'sortablejs';
|
||||||
import {resizeSensor} from '../../utils/resize-sensor';
|
import {resizeSensor} from '../../utils/resize-sensor';
|
||||||
@ -471,8 +475,10 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
rows = value;
|
rows = value;
|
||||||
} else if (typeof source === 'string') {
|
} else if (typeof source === 'string') {
|
||||||
const resolved = resolveVariable(source, props.data);
|
const resolved = resolveVariableAndFilter(source, props.data);
|
||||||
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
|
const prev = prevProps
|
||||||
|
? resolveVariableAndFilter(source, prevProps.data)
|
||||||
|
: null;
|
||||||
|
|
||||||
if (prev && prev === resolved) {
|
if (prev && prev === resolved) {
|
||||||
updateRows = false;
|
updateRows = false;
|
||||||
@ -558,7 +564,8 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
anyChanged(['source', 'value', 'items'], prevProps, props) ||
|
anyChanged(['source', 'value', 'items'], prevProps, props) ||
|
||||||
(!props.value && !props.items && props.data !== prevProps.data)
|
(!props.value && !props.items && props.data !== prevProps.data) ||
|
||||||
|
(typeof props.source === 'string' && isPureVariable(props.source))
|
||||||
) {
|
) {
|
||||||
Table.syncRows(store, props, prevProps);
|
Table.syncRows(store, props, prevProps);
|
||||||
this.syncSelected();
|
this.syncSelected();
|
||||||
@ -566,6 +573,7 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
store.updateSelected(props.selected || [], props.valueField);
|
store.updateSelected(props.selected || [], props.valueField);
|
||||||
this.syncSelected();
|
this.syncSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateTableInfoLazy();
|
this.updateTableInfoLazy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,14 +153,18 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|||||||
let activeKey: any = 0;
|
let activeKey: any = 0;
|
||||||
|
|
||||||
if (typeof props.activeKey !== 'undefined') {
|
if (typeof props.activeKey !== 'undefined') {
|
||||||
activeKey =
|
activeKey = props.activeKey;
|
||||||
typeof props.activeKey === 'string'
|
|
||||||
? tokenize(props.activeKey, props.data)
|
|
||||||
: props.activeKey;
|
|
||||||
} else if (location && Array.isArray(tabs)) {
|
} else if (location && Array.isArray(tabs)) {
|
||||||
const hash = location.hash.substring(1);
|
const hash = location.hash.substring(1);
|
||||||
const tab: TabSchema = find(tabs, tab => tab.hash === hash) as TabSchema;
|
const tab: TabSchema = find(tabs, tab => tab.hash === hash) as TabSchema;
|
||||||
activeKey = tab && tab.hash ? tab.hash : (tabs[0] && tabs[0].hash) || 0;
|
|
||||||
|
if (tab) {
|
||||||
|
activeKey = tab.hash;
|
||||||
|
} else if (props.defaultActiveKey) {
|
||||||
|
activeKey = tokenize(props.defaultActiveKey, props.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
activeKey = activeKey || (tabs[0] && tabs[0].hash) || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -465,10 +465,12 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
|
|||||||
'| raw'
|
'| raw'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!Array.isArray(rowsData)) {
|
if (!Array.isArray(rowsData) && !self.items.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rowsData = Array.isArray(rowsData) ? rowsData : [];
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
...self.pristine,
|
...self.pristine,
|
||||||
items: rowsData,
|
items: rowsData,
|
||||||
|
Loading…
Reference in New Issue
Block a user