From 95ad3a6027f43698776036959889912fe2e96aef Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Thu, 17 Jun 2021 23:57:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compat.ts | 23 +++++++++++++++++++++++ src/renderers/Form/index.tsx | 3 ++- src/renderers/Form/wrapControl.tsx | 5 ++++- src/renderers/Tpl.tsx | 3 +-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/compat.ts b/src/compat.ts index 3fcd273c0..ae4b9139d 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -398,6 +398,27 @@ function wrapControl(item: any) { }; } +const maybeStatic = [ + 'tpl', + 'mapping', + 'progress', + 'status', + 'json', + 'video', + 'qrcode' +]; + +function wrapStatic(item: any) { + if (!item || !item.type) { + return item; + } + + return { + ...item, + type: `static-${item.type}` + }; +} + addSchemaFilter(function (schema: Schema, renderer: any, props: any) { // controls 转成 body if (schema?.type === 'combo' && Array.isArray(schema.conditions)) { @@ -520,6 +541,8 @@ addSchemaFilter(function (schema: Schema, renderer: any, props: any) { } : ~maybeFormItem.indexOf(item?.type) ? wrapControl(item) + : ~maybeStatic.indexOf(item?.type) + ? wrapStatic(item) : item; } }); diff --git a/src/renderers/Form/index.tsx b/src/renderers/Form/index.tsx index a3081cfa1..a8177baee 100644 --- a/src/renderers/Form/index.tsx +++ b/src/renderers/Form/index.tsx @@ -398,7 +398,8 @@ export default class Form extends React.Component { 'formLazyChange', 'lazyLoad', 'formInited', - 'simpleMode' + 'simpleMode', + 'inputOnly' ]; hooks: { diff --git a/src/renderers/Form/wrapControl.tsx b/src/renderers/Form/wrapControl.tsx index cb9d904b0..cc0b63df4 100644 --- a/src/renderers/Form/wrapControl.tsx +++ b/src/renderers/Form/wrapControl.tsx @@ -185,7 +185,10 @@ export function wrapControl< // 同步 value model.changeTmpValue( propValue ?? - store?.getValueByName(model.name, canAccessSuperData) ?? + store?.getValueByName( + model.name, + canAccessSuperData !== false + ) ?? value ); diff --git a/src/renderers/Tpl.tsx b/src/renderers/Tpl.tsx index e3df0370d..b4fe8ea8f 100644 --- a/src/renderers/Tpl.tsx +++ b/src/renderers/Tpl.tsx @@ -45,8 +45,7 @@ export interface TplProps extends RendererProps, TplSchema { export class Tpl extends React.Component { static defaultProps: Partial = { inline: true, - placeholder: '', - value: '' + placeholder: '' }; dom: any; From 18863ede69bb2f9e53af2c4745401e278633004e Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 18 Jun 2021 01:13:31 +0800 Subject: [PATCH 2/3] Grid --- src/compat.ts | 5 +---- src/renderers/Grid.tsx | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/compat.ts b/src/compat.ts index ae4b9139d..4836d7c87 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -511,11 +511,8 @@ addSchemaFilter(function (schema: Schema, renderer: any, props: any) { body: column?.controls.map(controlToNormalRenderer) }; + delete column.type; delete column.controls; - if (!column.type) { - column.type = 'wrapper'; - column.size = 'none'; - } } return column; diff --git a/src/renderers/Grid.tsx b/src/renderers/Grid.tsx index 22681fb73..3daa25d9b 100644 --- a/src/renderers/Grid.tsx +++ b/src/renderers/Grid.tsx @@ -2,7 +2,12 @@ import React from 'react'; import {Renderer, RendererProps} from '../factory'; import {Schema} from '../types'; import pick from 'lodash/pick'; -import {BaseSchema, SchemaClassName, SchemaObject} from '../Schema'; +import { + BaseSchema, + SchemaClassName, + SchemaCollection, + SchemaObject +} from '../Schema'; export const ColProps = ['lg', 'md', 'sm', 'xs']; @@ -106,6 +111,8 @@ export type GridColumnObject = { mode?: string; horizontal?: any; + body?: SchemaCollection; + /** * 列类名 */ @@ -168,7 +175,12 @@ export default class Grid extends React.Component { static propsList: Array = ['columns']; static defaultProps = {}; - renderChild(region: string, node: Schema, key: number, length: number) { + renderChild( + region: string, + node: SchemaCollection, + key: number, + length: number + ) { const {render, itemRender} = this.props; return itemRender @@ -206,7 +218,12 @@ export default class Grid extends React.Component { )} ) : ( - this.renderChild(`column/${key}`, column, key, length) + this.renderChild( + `column/${key}`, + column.type ? column : (column as any).body!, + key, + length + ) )} ); From d2acb0a50afe2ef6170bcf6711d72d1f8bab91f3 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 18 Jun 2021 01:38:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Hbox=20&=20Tabs=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scss/layout/_grid.scss | 1 + scss/layout/_hbox.scss | 44 +++++++++++++++++++++--------------------- src/compat.ts | 4 ++-- src/renderers/HBox.tsx | 17 ++++++++++++---- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/scss/layout/_grid.scss b/scss/layout/_grid.scss index 8d0bfeaf6..a09b03328 100644 --- a/scss/layout/_grid.scss +++ b/scss/layout/_grid.scss @@ -145,6 +145,7 @@ @include media-breakpoint-up(sm) { .#{$ns}Grid { @include make-row; + flex: 1; } @include make-grid(sm); diff --git a/scss/layout/_hbox.scss b/scss/layout/_hbox.scss index 54dee8719..f7b839873 100644 --- a/scss/layout/_hbox.scss +++ b/scss/layout/_hbox.scss @@ -12,32 +12,12 @@ width: 100%; float: none; } -} - -.#{$ns}FormHbox { - margin-left: calc(var(--gap-md) * -1); - margin-right: calc(var(--gap-md) * -1); - - > .#{$ns}Hbox > .#{$ns}Hbox-col { - padding-left: var(--gap-md); - padding-right: var(--gap-md); - vertical-align: top; - - > .#{$ns}Form-group { - margin-left: 0; - margin-right: 0; - } - - > .#{$ns}Form-group:last-child { - margin-bottom: 0; - } - } &.#{$ns}Hbox--xs { margin-left: -5px; margin-right: -5px; - > .#{$ns}Hbox > .#{$ns}Hbox-col { + > .#{$ns}Hbox-col { padding-left: 5px; padding-right: 5px; } @@ -47,13 +27,33 @@ margin-left: -10px; margin-right: -10px; - > .#{$ns}Hbox > .#{$ns}Hbox-col { + > .#{$ns}Hbox-col { padding-left: 10px; padding-right: 10px; } } } +// .#{$ns}FormHbox { +// margin-left: calc(var(--gap-md) * -1); +// margin-right: calc(var(--gap-md) * -1); + +// > .#{$ns}Hbox > .#{$ns}Hbox-col { +// padding-left: var(--gap-md); +// padding-right: var(--gap-md); +// vertical-align: top; + +// > .#{$ns}Form-group { +// margin-left: 0; +// margin-right: 0; +// } + +// > .#{$ns}Form-group:last-child { +// margin-bottom: 0; +// } +// } +// } + @include media-breakpoint-down(md) { .#{$ns}Hbox--autoSm { display: block; diff --git a/src/compat.ts b/src/compat.ts index 4836d7c87..d4c609fa3 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -464,10 +464,10 @@ addSchemaFilter(function (schema: Schema, renderer: any, props: any) { schema = { ...schema, tabs: schema.tabs.map(tab => { - if (Array.isArray(tab.controls)) { + if (Array.isArray(tab.controls) && !Array.isArray(tab.body)) { tab = { ...tab, - body: tab?.controls.map(controlToNormalRenderer) + body: tab.controls.map(controlToNormalRenderer) }; delete tab.controls; } diff --git a/src/renderers/HBox.tsx b/src/renderers/HBox.tsx index cbcb210fe..e7266163c 100644 --- a/src/renderers/HBox.tsx +++ b/src/renderers/HBox.tsx @@ -56,7 +56,9 @@ export interface HBoxProps extends RendererProps, HBoxSchema { export default class HBox extends React.Component { static propsList: Array = ['columns']; - static defaultProps: Partial = {}; + static defaultProps: Partial = { + gap: 'xs' + }; renderChild(region: string, node: Schema) { const {render} = this.props; @@ -85,7 +87,10 @@ export default class HBox extends React.Component { > {itemRender ? itemRender(column, key, length, this.props) - : this.renderChild(`column/${key}`, column)} + : this.renderChild( + `column/${key}`, + column.type ? column : (column as any).body + )} ); } @@ -99,8 +104,12 @@ export default class HBox extends React.Component { } render() { - const {className, classnames: cx} = this.props; - return
{this.renderColumns()}
; + const {className, classnames: cx, gap} = this.props; + return ( +
+ {this.renderColumns()} +
+ ); } }