Skip to content

Commit 72fc1d5

Browse files
authored
fix(amis-editor): Form & CRUD2脚手架使用api数据源时无法新增字段问题 (#8402)
1 parent 034d18e commit 72fc1d5

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

packages/amis-editor-core/scss/control/_crud2-control.scss

+10
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,13 @@
162162
--Spinner-color: #fff;
163163
}
164164
}
165+
166+
.ae-FieldSetting-footer {
167+
position: absolute;
168+
right: 0;
169+
bottom: 35px;
170+
171+
&--form {
172+
bottom: 55px;
173+
}
174+
}

packages/amis-editor/src/renderer/FieldSetting.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,20 @@ export class FieldSetting extends React.Component<
346346
const scaffoldData = store?.data;
347347
const {initApi, listApi} = scaffoldData || {};
348348
const {loading} = this.state;
349-
const fieldApi =
350-
renderer === 'form' ? initApi : renderer === 'crud' ? listApi : '';
349+
const isForm = renderer === 'form';
350+
const isCRUD = renderer === 'crud';
351+
const fieldApi = isForm ? initApi : isCRUD ? listApi : '';
351352
const isApiValid = isValidApi(normalizeApi(fieldApi)?.url);
352353
const showAutoGenBtn =
353-
(renderer === 'form' && feat === 'Edit') ||
354-
(renderer === 'crud' && feat === 'List' && ctx?.__step === 0);
354+
(isForm && feat === 'Edit') ||
355+
(isCRUD && feat === 'List' && ctx?.__step === 0);
355356

356357
return showAutoGenBtn ? (
357-
<div className={cx('ae-FieldSetting-footer', 'flex flex-row-reverse')}>
358+
<div
359+
className={cx('ae-FieldSetting-footer', {
360+
['ae-FieldSetting-footer--form']: isForm
361+
})}
362+
>
358363
<Button
359364
size="sm"
360365
level="link"
@@ -363,7 +368,7 @@ export class FieldSetting extends React.Component<
363368
disabledTip={{
364369
content: loading
365370
? '数据处理中...'
366-
: renderer === 'form'
371+
: isForm
367372
? '请先填写初始化接口'
368373
: '请先填写接口',
369374
tooltipTheme: 'dark'
@@ -401,8 +406,9 @@ export class FieldSetting extends React.Component<
401406
'ae-FieldSetting-Table',
402407
'mb-0'
403408
) /** 底部有操作区,干掉默认的 margin-bottom */,
409+
toolbarClassName: 'w-1/2',
404410
showIndex: true,
405-
showFooterAddBtn: false,
411+
showFooterAddBtn: true,
406412
addable: true,
407413
addBtnLabel: '新增',
408414
addBtnIcon: false,
@@ -426,6 +432,7 @@ export class FieldSetting extends React.Component<
426432
level: 'link',
427433
label: '添加字段'
428434
},
435+
placeholder: '暂无字段',
429436
scaffold: this.scaffold,
430437
columns: [
431438
{

packages/amis/src/renderers/Form/InputTable.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {Button, Icon} from 'amis-ui';
3232
import omit from 'lodash/omit';
3333
import findIndex from 'lodash/findIndex';
3434
import {TableSchema} from '../Table';
35-
import {SchemaApi, SchemaCollection} from '../../Schema';
35+
import {SchemaApi, SchemaCollection, SchemaClassName} from '../../Schema';
3636
import find from 'lodash/find';
3737
import moment from 'moment';
3838
import merge from 'lodash/merge';
@@ -214,6 +214,11 @@ export interface TableControlSchema
214214
* 是否开启 static 状态切换
215215
*/
216216
enableStaticTransform?: boolean;
217+
218+
/**
219+
* 底部工具栏CSS样式类
220+
*/
221+
toolbarClassName?: SchemaClassName;
217222
}
218223

219224
export interface TableProps
@@ -283,7 +288,9 @@ export default class FormTable extends React.Component<TableProps, TableState> {
283288
'deleteApi',
284289
'needConfirm',
285290
'canAccessSuperData',
286-
'formStore'
291+
'formStore',
292+
'footerActions',
293+
'toolbarClassName'
287294
];
288295

289296
entries: SimpleMap<any, number>;
@@ -1572,7 +1579,8 @@ export default class FormTable extends React.Component<TableProps, TableState> {
15721579
tableContentClassName,
15731580
static: isStatic,
15741581
showFooterAddBtn,
1575-
footerAddBtn
1582+
footerAddBtn,
1583+
toolbarClassName
15761584
} = this.props;
15771585
const maxLength = this.resolveVariableProps(this.props, 'maxLength');
15781586

@@ -1641,7 +1649,7 @@ export default class FormTable extends React.Component<TableProps, TableState> {
16411649
showFooterAddBtn !== false &&
16421650
(!maxLength || maxLength > items.length)) ||
16431651
showPager ? (
1644-
<div className={cx('InputTable-toolbar')}>
1652+
<div className={cx('InputTable-toolbar', toolbarClassName)}>
16451653
{addable && showFooterAddBtn !== false
16461654
? render(
16471655
'button',

0 commit comments

Comments
 (0)