mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +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) {
|
||||
file.skiped = true;
|
||||
let contents = file.getContent();
|
||||
|
||||
|
||||
if (/_map\.js$/.test(file.subpath)) {
|
||||
contents = `(function() {
|
||||
|
@ -262,7 +262,12 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
||||
|
||||
const renderer = this.renderer as RendererConfig;
|
||||
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;
|
||||
|
||||
// 原来表单项的 visible: false 和 hidden: true 表单项的值和验证是有效的
|
||||
@ -287,6 +292,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
||||
{...exprProps}
|
||||
defaultData={defaultData}
|
||||
defaultValue={defaultValue}
|
||||
defaultActiveKey={defaultActiveKey}
|
||||
$path={$path}
|
||||
$schema={schema}
|
||||
ref={this.refFn}
|
||||
|
@ -59,6 +59,7 @@ import {ActionSchema} from './Action';
|
||||
import {CardsSchema} from './Cards';
|
||||
import {ListSchema} from './List';
|
||||
import {TableSchema} from './Table';
|
||||
import {isPureVariable, resolveVariableAndFilter} from '../utils/tpl-builtin';
|
||||
|
||||
export type CRUDBultinToolbarType =
|
||||
| 'columns-toggler'
|
||||
@ -529,6 +530,17 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
)
|
||||
) {
|
||||
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) {
|
||||
|
@ -11,7 +11,11 @@ import {
|
||||
difference,
|
||||
ucFirst
|
||||
} from '../utils/helper';
|
||||
import {resolveVariable} from '../utils/tpl-builtin';
|
||||
import {
|
||||
isPureVariable,
|
||||
resolveVariable,
|
||||
resolveVariableAndFilter
|
||||
} from '../utils/tpl-builtin';
|
||||
import Sortable from 'sortablejs';
|
||||
import {filter} from '../utils/tpl';
|
||||
import {Icon} from '../components/icons';
|
||||
@ -258,8 +262,10 @@ export default class Cards extends React.Component<GridProps, object> {
|
||||
if (Array.isArray(value)) {
|
||||
items = value;
|
||||
} else if (typeof source === 'string') {
|
||||
const resolved = resolveVariable(source, props.data);
|
||||
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
|
||||
const resolved = resolveVariableAndFilter(source, props.data);
|
||||
const prev = prevProps
|
||||
? resolveVariableAndFilter(source, prevProps.data)
|
||||
: null;
|
||||
|
||||
if (prev && prev === resolved) {
|
||||
updateItems = false;
|
||||
@ -321,7 +327,8 @@ export default class Cards extends React.Component<GridProps, object> {
|
||||
|
||||
if (
|
||||
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);
|
||||
this.syncSelected();
|
||||
|
@ -771,7 +771,7 @@ export class DialogRenderer extends Dialog {
|
||||
} else if (action.actionType === 'reload') {
|
||||
store.setCurrentAction(action);
|
||||
action.target && scoped.reload(action.target, data);
|
||||
if (action.close) {
|
||||
if (action.close || action.type === 'submit') {
|
||||
this.handleSelfClose();
|
||||
this.closeTarget(action.close);
|
||||
}
|
||||
|
@ -58,20 +58,22 @@ export default class StaticControl extends React.Component<StaticProps, any> {
|
||||
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;
|
||||
|
||||
onBulkChange(values, saveImmediately === true);
|
||||
if (saveImmediately && saveImmediately.api) {
|
||||
onAction(
|
||||
await onAction(
|
||||
null,
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: saveImmediately.api
|
||||
},
|
||||
extendObject(data, values)
|
||||
extendObject(data, values),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
onBulkChange(values, saveImmediately === true);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -16,7 +16,11 @@ import {
|
||||
isDisabled,
|
||||
noop
|
||||
} from '../utils/helper';
|
||||
import {resolveVariable} from '../utils/tpl-builtin';
|
||||
import {
|
||||
isPureVariable,
|
||||
resolveVariable,
|
||||
resolveVariableAndFilter
|
||||
} from '../utils/tpl-builtin';
|
||||
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
|
||||
import PopOver, {SchemaPopOver} from './PopOver';
|
||||
import Sortable from 'sortablejs';
|
||||
@ -327,8 +331,10 @@ export default class List extends React.Component<ListProps, object> {
|
||||
if (Array.isArray(value)) {
|
||||
items = value;
|
||||
} else if (typeof source === 'string') {
|
||||
const resolved = resolveVariable(source, props.data);
|
||||
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
|
||||
const resolved = resolveVariableAndFilter(source, props.data);
|
||||
const prev = prevProps
|
||||
? resolveVariableAndFilter(source, prevProps.data)
|
||||
: null;
|
||||
|
||||
if (prev && prev === resolved) {
|
||||
updateItems = false;
|
||||
@ -390,7 +396,8 @@ export default class List extends React.Component<ListProps, object> {
|
||||
|
||||
if (
|
||||
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);
|
||||
this.syncSelected();
|
||||
|
@ -258,7 +258,7 @@ export default class Page extends React.Component<PageProps> {
|
||||
ctx: object,
|
||||
throwErrors: boolean = false,
|
||||
delegate?: IScopedContext
|
||||
) {
|
||||
): any {
|
||||
const {env, store, messages, onAction} = this.props;
|
||||
|
||||
if (action.actionType === 'dialog') {
|
||||
@ -269,7 +269,7 @@ export default class Page extends React.Component<PageProps> {
|
||||
store.openDrawer(ctx);
|
||||
} else if (action.actionType === 'ajax') {
|
||||
store.setCurrentAction(action);
|
||||
store
|
||||
return store
|
||||
.saveRemote(action.api as string, ctx, {
|
||||
successMessage:
|
||||
(action.messages && action.messages.success) ||
|
||||
@ -290,7 +290,7 @@ export default class Page extends React.Component<PageProps> {
|
||||
})
|
||||
.catch(() => {});
|
||||
} 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,
|
||||
(quickEdit as QuickEditConfig).resetOnFailed
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handleInit(values: object) {
|
||||
@ -513,7 +515,13 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (
|
||||
disabled
|
||||
} = this.props;
|
||||
|
||||
if (!quickEdit || !onQuickChange || quickEditEnabled === false || noHoc || disabled) {
|
||||
if (
|
||||
!quickEdit ||
|
||||
!onQuickChange ||
|
||||
quickEditEnabled === false ||
|
||||
noHoc ||
|
||||
disabled
|
||||
) {
|
||||
return <Component {...this.props} />;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,11 @@ import {
|
||||
getVariable,
|
||||
removeHTMLTag
|
||||
} from '../../utils/helper';
|
||||
import {resolveVariable} from '../../utils/tpl-builtin';
|
||||
import {
|
||||
isPureVariable,
|
||||
resolveVariable,
|
||||
resolveVariableAndFilter
|
||||
} from '../../utils/tpl-builtin';
|
||||
import debounce from 'lodash/debounce';
|
||||
import Sortable from 'sortablejs';
|
||||
import {resizeSensor} from '../../utils/resize-sensor';
|
||||
@ -471,8 +475,10 @@ export default class Table extends React.Component<TableProps, object> {
|
||||
if (Array.isArray(value)) {
|
||||
rows = value;
|
||||
} else if (typeof source === 'string') {
|
||||
const resolved = resolveVariable(source, props.data);
|
||||
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
|
||||
const resolved = resolveVariableAndFilter(source, props.data);
|
||||
const prev = prevProps
|
||||
? resolveVariableAndFilter(source, prevProps.data)
|
||||
: null;
|
||||
|
||||
if (prev && prev === resolved) {
|
||||
updateRows = false;
|
||||
@ -558,7 +564,8 @@ export default class Table extends React.Component<TableProps, object> {
|
||||
|
||||
if (
|
||||
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);
|
||||
this.syncSelected();
|
||||
@ -566,6 +573,7 @@ export default class Table extends React.Component<TableProps, object> {
|
||||
store.updateSelected(props.selected || [], props.valueField);
|
||||
this.syncSelected();
|
||||
}
|
||||
|
||||
this.updateTableInfoLazy();
|
||||
}
|
||||
|
||||
|
@ -153,14 +153,18 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
||||
let activeKey: any = 0;
|
||||
|
||||
if (typeof props.activeKey !== 'undefined') {
|
||||
activeKey =
|
||||
typeof props.activeKey === 'string'
|
||||
? tokenize(props.activeKey, props.data)
|
||||
: props.activeKey;
|
||||
activeKey = props.activeKey;
|
||||
} else if (location && Array.isArray(tabs)) {
|
||||
const hash = location.hash.substring(1);
|
||||
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 = {
|
||||
|
@ -465,10 +465,12 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
|
||||
'| raw'
|
||||
);
|
||||
|
||||
if (!Array.isArray(rowsData)) {
|
||||
if (!Array.isArray(rowsData) && !self.items.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
rowsData = Array.isArray(rowsData) ? rowsData : [];
|
||||
|
||||
const data = {
|
||||
...self.pristine,
|
||||
items: rowsData,
|
||||
|
Loading…
Reference in New Issue
Block a user