From 9ee369a5b7be1c6526b6d5daf02eb6c14c0938ac Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Thu, 1 Jul 2021 00:46:18 +0800 Subject: [PATCH] =?UTF-8?q?Merge=201.1.x=20&=20CRUD=20=E7=9A=84=20source?= =?UTF-8?q?=20=E7=94=A8=E6=B3=95=E4=BC=98=E5=8C=96=20(#2188)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * jssdk 产出带版本 * jssdk 产出带版本 * feat:当表单disable时隐藏QuickEdit (#2175) Co-authored-by: qinhaoyan * 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 Co-authored-by: 吴多益 Co-authored-by: RickCole Co-authored-by: xuzhendong666 <810792608@Outlook.com> --- scripts/embed-packager.js | 1 + src/SchemaRenderer.tsx | 8 +++++++- src/renderers/CRUD.tsx | 12 ++++++++++++ src/renderers/Cards.tsx | 15 +++++++++++---- src/renderers/Dialog.tsx | 2 +- src/renderers/Form/Static.tsx | 10 ++++++---- src/renderers/List.tsx | 15 +++++++++++---- src/renderers/Page.tsx | 6 +++--- src/renderers/QuickEdit.tsx | 10 +++++++++- src/renderers/Table/index.tsx | 16 ++++++++++++---- src/renderers/Tabs.tsx | 14 +++++++++----- src/store/crud.ts | 4 +++- 12 files changed, 85 insertions(+), 28 deletions(-) diff --git a/scripts/embed-packager.js b/scripts/embed-packager.js index b331126db1b..ec04de2e86d 100644 --- a/scripts/embed-packager.js +++ b/scripts/embed-packager.js @@ -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() { diff --git a/src/SchemaRenderer.tsx b/src/SchemaRenderer.tsx index 2efde15544a..656f7b21a15 100644 --- a/src/SchemaRenderer.tsx +++ b/src/SchemaRenderer.tsx @@ -262,7 +262,12 @@ export class SchemaRenderer extends React.Component { 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 { {...exprProps} defaultData={defaultData} defaultValue={defaultValue} + defaultActiveKey={defaultActiveKey} $path={$path} $schema={schema} ref={this.refFn} diff --git a/src/renderers/CRUD.tsx b/src/renderers/CRUD.tsx index b1b13aefb1f..646c81363c4 100644 --- a/src/renderers/CRUD.tsx +++ b/src/renderers/CRUD.tsx @@ -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 { ) ) { 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) { diff --git a/src/renderers/Cards.tsx b/src/renderers/Cards.tsx index 615774975f4..c52e43489a0 100644 --- a/src/renderers/Cards.tsx +++ b/src/renderers/Cards.tsx @@ -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 { 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 { 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(); diff --git a/src/renderers/Dialog.tsx b/src/renderers/Dialog.tsx index 85b30fe7877..d6b9c81137c 100644 --- a/src/renderers/Dialog.tsx +++ b/src/renderers/Dialog.tsx @@ -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); } diff --git a/src/renderers/Form/Static.tsx b/src/renderers/Form/Static.tsx index 56ff73a7bae..855a070e7fb 100644 --- a/src/renderers/Form/Static.tsx +++ b/src/renderers/Form/Static.tsx @@ -58,20 +58,22 @@ export default class StaticControl extends React.Component { 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() { diff --git a/src/renderers/List.tsx b/src/renderers/List.tsx index a30310740a9..8ced08bafc4 100644 --- a/src/renderers/List.tsx +++ b/src/renderers/List.tsx @@ -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 { 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 { 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(); diff --git a/src/renderers/Page.tsx b/src/renderers/Page.tsx index 217643d24b5..3eaca04fa5a 100644 --- a/src/renderers/Page.tsx +++ b/src/renderers/Page.tsx @@ -258,7 +258,7 @@ export default class Page extends React.Component { 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 { 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 { }) .catch(() => {}); } else { - onAction(e, action, ctx, throwErrors, delegate || this.context); + return onAction(e, action, ctx, throwErrors, delegate || this.context); } } diff --git a/src/renderers/QuickEdit.tsx b/src/renderers/QuickEdit.tsx index 7d6b9657844..89209c74445 100644 --- a/src/renderers/QuickEdit.tsx +++ b/src/renderers/QuickEdit.tsx @@ -310,6 +310,8 @@ export const HocQuickEdit = (config: Partial = {}) => ( false, (quickEdit as QuickEditConfig).resetOnFailed ); + + return false; } handleInit(values: object) { @@ -513,7 +515,13 @@ export const HocQuickEdit = (config: Partial = {}) => ( disabled } = this.props; - if (!quickEdit || !onQuickChange || quickEditEnabled === false || noHoc || disabled) { + if ( + !quickEdit || + !onQuickChange || + quickEditEnabled === false || + noHoc || + disabled + ) { return ; } diff --git a/src/renderers/Table/index.tsx b/src/renderers/Table/index.tsx index 2d0981747c2..cfe75b50060 100644 --- a/src/renderers/Table/index.tsx +++ b/src/renderers/Table/index.tsx @@ -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 { 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 { 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 { store.updateSelected(props.selected || [], props.valueField); this.syncSelected(); } + this.updateTableInfoLazy(); } diff --git a/src/renderers/Tabs.tsx b/src/renderers/Tabs.tsx index d333021a7d7..9dd9b7da7f6 100644 --- a/src/renderers/Tabs.tsx +++ b/src/renderers/Tabs.tsx @@ -153,14 +153,18 @@ export default class Tabs extends React.Component { 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 = { diff --git a/src/store/crud.ts b/src/store/crud.ts index b1bce245c07..7366b8023b1 100644 --- a/src/store/crud.ts +++ b/src/store/crud.ts @@ -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,