Grid 调整删掉一些没用的属性 (#2338)

* 页面的区域可以固定配置,而不是根据内容自动

* chore: grid 删掉一些没用的属性

* rm console.log
This commit is contained in:
liaoxuezhi 2021-07-29 18:57:57 +08:00 committed by GitHub
parent 7e445a091c
commit 8676fc95ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 127 deletions

View File

@ -47,32 +47,16 @@ order: 46
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| -------------------------- | ----------------------------------------- | -------- | ----------------------- |
| type | `string` | `"grid"` | 指定为 Grid 渲染器 |
| className | `string` | | 外层 Dom 的类名 |
| columns | `Array` | | 列集合 |
| columns[x] | [SchemaNode](../../docs/types/schemanode) | | 成员可以是其他渲染器 |
| columns[x].xs | `int` | | 宽度占比: 1 - 12 |
| columns[x].columnClassName | | | 列类名 |
| columns[x].xsHidden | `boolean` | | 是否隐藏 |
| columns[x].xsOffset | `int` | | 偏移量 1 - 12 |
| columns[x].xsPull | `int` | | 靠左的距离占比1 - 12 |
| columns[x].xsPush | `int` | | 靠右的距离占比: 1 - 12 |
| columns[x].sm | `int` | | 宽度占比: 1 - 12 |
| columns[x].smHidden | `boolean` | | 是否隐藏 |
| columns[x].smOffset | `int` | | 偏移量 1 - 12 |
| columns[x].smPull | `int` | | 靠左的距离占比1 - 12 |
| columns[x].smPush | `int` | | 靠右的距离占比: 1 - 12 |
| columns[x].md | `int` | | 宽度占比: 1 - 12 |
| columns[x].mdHidden | `boolean` | | 是否隐藏 |
| columns[x].mdOffset | `int` | | 偏移量 1 - 12 |
| columns[x].mdPull | `int` | | 靠左的距离占比1 - 12 |
| columns[x].mdPush | `int` | | 靠右的距离占比: 1 - 12 |
| columns[x].lg | `int` | | 宽度占比: 1 - 12 |
| columns[x].lgHidden | `boolean` | | 是否隐藏 |
| columns[x].lgOffset | `int` | | 偏移量 1 - 12 |
| columns[x].lgPull | `int` | | 靠左的距离占比1 - 12 |
| columns[x].lgPush | `int` | | 靠右的距离占比: 1 - 12 |
| 属性名 | 类型 | 默认值 | 说明 |
| -------------------------- | ----------------------------------------- | -------- | -------------------- |
| type | `string` | `"grid"` | 指定为 Grid 渲染器 |
| className | `string` | | 外层 Dom 的类名 |
| columns | `Array` | | 列集合 |
| columns[x] | [SchemaNode](../../docs/types/schemanode) | | 成员可以是其他渲染器 |
| columns[x].xs | `int` | | 宽度占比: 1 - 12 |
| columns[x].columnClassName | | | 列类名 |
| columns[x].sm | `int` | | 宽度占比: 1 - 12 |
| columns[x].md | `int` | | 宽度占比: 1 - 12 |
| columns[x].lg | `int` | | 宽度占比: 1 - 12 |
更多使用说明,请参看 [Grid Props](https://react-bootstrap.github.io/layout/grid/#col-props)

View File

@ -15,6 +15,7 @@ import {FileControlRenderer} from './renderers/Form/InputFile';
import {ImageControlRenderer} from './renderers/Form/InputImage';
import {RichTextControlRenderer} from './renderers/Form/InputRichText';
import isPlainObject from 'lodash/isPlainObject';
import {GridRenderer} from './renderers/Grid';
// 兼容老的用法,老用法 label 用在 checkbox 的右侧内容,新用法用 option 来代替。
addSchemaFilter(function CheckboxPropsFilter(schema: Schema, renderer) {
@ -287,6 +288,49 @@ addSchemaFilter(function (scheam: Schema, renderer) {
return scheam;
});
// Grid 一些旧格式的兼容
addSchemaFilter(function (scheam: Schema, renderer) {
if (renderer.component !== GridRenderer) {
return scheam;
}
if (
Array.isArray(scheam.columns) &&
scheam.columns.some(item => Array.isArray(item) || item.type)
) {
scheam = {
...scheam,
columns: scheam.columns.map(item => {
if (Array.isArray(item)) {
return {
body: [
{
type: 'grid',
columns: item
}
]
};
} else if (item.type) {
let {xs, sm, md, lg, body, ...rest} = item;
body = Array.isArray(body) ? body.concat() : body ? [body] : [];
body.push(rest);
item = {
xs,
sm,
md,
lg,
body
};
}
return item;
})
};
}
return scheam;
});
const controlMapping: any = {
'array': 'input-array',
'button-group': 'button-group-select',

View File

@ -18,101 +18,26 @@ export type GridColumnObject = {
*/
xs?: number;
/**
* <768px时是否隐藏该列
*/
xsHidden?: boolean;
/**
* <768px时宽度偏移量
*/
xsOffset?: number;
/**
* <768px时宽度右偏移量
*/
xsPull?: number;
/**
* <768px时宽度左偏移量
*/
xsPush?: number;
/**
* >=768px
*/
sm?: number;
/**
* >=768px
*/
smHidden?: boolean;
/**
* >=768px
*/
smOffset?: number;
/**
* >=768px
*/
smPull?: number;
/**
* >=768px
*/
smPush?: number;
/**
* (>=992px)
*/
md?: number;
/**
* (>=992px)
*/
mdHidden?: boolean;
/**
* (>=992px)
*/
mdOffset?: number;
/**
* (>=992px)
*/
mdPull?: number;
/**
* (>=992px)
*/
mdPush?: number;
/**
* (>=1200px)
*/
lg?: number;
/**
* (>=1200px)
*/
lgHidden?: boolean;
/**
* (>=1200px)
*/
lgOffset?: number;
/**
* (>=1200px)
*/
lgPull?: number;
/**
* (>=1200px)
*/
lgPush?: number;
/**
*
*/
mode?: 'normal' | 'inline' | 'horizontal';
/**
*
*/
@ -127,7 +52,7 @@ export type GridColumnObject = {
};
export type GridColumn = GridColumnObject & SchemaObject;
export type ColumnNode = GridColumn | ColumnArray;
export type ColumnNode = GridColumn;
export interface ColumnArray extends Array<ColumnNode> {}
/**
@ -174,7 +99,7 @@ function copProps2Class(props: any): string {
props[modifier] &&
cns.push(`Grid-col--${modifier}${props[modifier]}`)
);
cns.length || cns.push('Grid-col--sm');
cns.length || cns.push('Grid-col--md');
return cns.join(' ');
}
@ -221,28 +146,16 @@ export default class Grid<T> extends React.Component<GridProps & T, object> {
fromBsClass((column as any).columnClassName!)
)}
>
{Array.isArray(column) ? (
<div className={cx('Grid')}>
{column.map((column, key) =>
this.renderColumn(
column,
key,
(column as Array<GridColumn>).length
)
)}
</div>
) : (
this.renderChild(
`column/${key}`,
column.type ? column : (column as any).body!,
key,
length,
{
formMode: column.mode || subFormMode || formMode,
formHorizontal:
column.horizontal || subFormHorizontal || formHorizontal
}
)
{this.renderChild(
`column/${key}`,
(column as any).type ? column : (column as any).body!,
key,
length,
{
formMode: column.mode || subFormMode || formMode,
formHorizontal:
column.horizontal || subFormHorizontal || formHorizontal
}
)}
</div>
);