mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat: input-table 的复制功能支持配置复制数据映射 (#10519)
This commit is contained in:
parent
612c16895d
commit
08835ccb70
@ -146,21 +146,26 @@ order: 54
|
||||
|
||||
还能通过 `copyable` 来增加一个复制按钮来复制当前行
|
||||
|
||||
> 6.6.0 起支持配置 `copyData` 属性,来指定复制的数据。默认值为 `{&: "$$"}`
|
||||
|
||||
```schema: scope="body"
|
||||
{
|
||||
"type": "form",
|
||||
"api": "/api/mock2/form/saveForm",
|
||||
"debug": true,
|
||||
"body": [
|
||||
{
|
||||
"type":"input-table",
|
||||
"name":"table",
|
||||
"addable": true,
|
||||
"copyable": true,
|
||||
"copyData": {"&": "$$$$", "id": "$${'__undefined'}", "copyFrom": "$${id}"},
|
||||
"editable": true,
|
||||
"value": [
|
||||
{
|
||||
"a": "a1",
|
||||
"b": "b1"
|
||||
"b": "b1",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"columns":[
|
||||
@ -917,6 +922,8 @@ order: 54
|
||||
| ---------------------------- | ----------------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------- |
|
||||
| type | `string` | `"input-table"` | 指定为 Table 渲染器 |
|
||||
| addable | `boolean` | `false` | 是否可增加一行 |
|
||||
| copyable | `boolean` | `false` | 是否可复制一行 |
|
||||
| copyData | `PlainObject` | | 控制复制时的数据映射,不配置时复制整行数据 |
|
||||
| childrenAddable | `boolean` | `false` | 是否可增加子级节点 |
|
||||
| editable | `boolean` | `false` | 是否可编辑 |
|
||||
| removable | `boolean` | `false` | 是否可删除 |
|
||||
|
@ -253,6 +253,11 @@
|
||||
& .label {
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
& > .#{$ns}Form,
|
||||
& > .#{$ns}Form-item {
|
||||
min-width: var(--Form-control-widthBase);
|
||||
}
|
||||
}
|
||||
|
||||
&.is-layout-fixed td {
|
||||
|
@ -76,6 +76,12 @@ export interface TableControlSchema
|
||||
*/
|
||||
copyAddBtn?: boolean;
|
||||
|
||||
/**
|
||||
* 复制的时候用来配置复制映射的数据。默认值是 {&:$$},相当与复制整个行数据
|
||||
* 通常有时候需要用来标记是复制过来的,也可能需要删掉一下主键字段。
|
||||
*/
|
||||
copyData?: Record<string, any>;
|
||||
|
||||
/**
|
||||
* 是否可以拖拽排序
|
||||
*/
|
||||
@ -622,20 +628,22 @@ export default class FormTable extends React.Component<TableProps, TableState> {
|
||||
}
|
||||
|
||||
async copyItem(index: string) {
|
||||
const {needConfirm} = this.props;
|
||||
const {needConfirm, data, copyData = {'&': '$$'}} = this.props;
|
||||
let items = this.state.items.concat();
|
||||
const indexes = index.split('.').map(item => parseInt(item, 10));
|
||||
const next = indexes.concat();
|
||||
next[next.length - 1] += 1;
|
||||
|
||||
const originItems = items;
|
||||
const src = getTree(items, indexes);
|
||||
const item = dataMapping(copyData, createObject(data, src));
|
||||
if (needConfirm === false) {
|
||||
items = spliceTree(items, next, 0, getTree(items, indexes));
|
||||
items = spliceTree(items, next, 0, item);
|
||||
} else {
|
||||
// 复制相当于新增一行
|
||||
// 需要同addItem一致添加__placeholder属性
|
||||
items = spliceTree(items, next, 0, {
|
||||
...getTree(items, indexes),
|
||||
...item,
|
||||
__isPlaceholder: true
|
||||
});
|
||||
}
|
||||
@ -650,7 +658,7 @@ export default class FormTable extends React.Component<TableProps, TableState> {
|
||||
const isPrevented = await this.dispatchEvent('add', {
|
||||
index: next[next.length - 1],
|
||||
indexPath: next.join('.'),
|
||||
item: getTree(items, next)
|
||||
item: item
|
||||
});
|
||||
if (isPrevented) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user