amis 1.10.1-beta.0 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/Schema.d.ts +1 -1
- package/lib/Schema.js.map +1 -1
- package/lib/components/Avatar.d.ts +10 -10
- package/lib/components/ListGroup.d.ts +10 -10
- package/lib/components/Range.js +8 -2
- package/lib/components/Range.js.map +2 -2
- package/lib/components/ResultBox.d.ts +41 -40
- package/lib/components/ResultBox.js +23 -19
- package/lib/components/ResultBox.js.map +2 -2
- package/lib/components/Select.js +5 -3
- package/lib/components/Select.js.map +2 -2
- package/lib/components/Steps.d.ts +1 -0
- package/lib/components/Steps.js +8 -6
- package/lib/components/Steps.js.map +2 -2
- package/lib/components/condition-builder/index.d.ts +12 -2
- package/lib/components/condition-builder/index.js +40 -4
- package/lib/components/condition-builder/index.js.map +2 -2
- package/lib/components/formula/Editor.js +1 -1
- package/lib/components/formula/Editor.js.map +2 -2
- package/lib/components/formula/VariableList.js +2 -2
- package/lib/components/formula/VariableList.js.map +2 -2
- package/lib/components/table/index.d.ts +9 -7
- package/lib/components/table/index.js +102 -102
- package/lib/components/table/index.js.map +2 -2
- package/lib/helper.css.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/index.js.map +2 -2
- package/lib/renderers/Action.js +18 -11
- package/lib/renderers/Action.js.map +2 -2
- package/lib/renderers/ButtonGroup.d.ts +2 -2
- package/lib/renderers/ButtonGroup.js.map +1 -1
- package/lib/renderers/CRUD.js +2 -2
- package/lib/renderers/CRUD.js.map +2 -2
- package/lib/renderers/CRUD2.d.ts +213 -0
- package/lib/renderers/CRUD2.js +724 -0
- package/lib/renderers/CRUD2.js.map +13 -0
- package/lib/renderers/Card2.d.ts +1 -1
- package/lib/renderers/Card2.js +1 -2
- package/lib/renderers/Card2.js.map +2 -2
- package/lib/renderers/Cards.d.ts +3 -0
- package/lib/renderers/Cards.js +52 -5
- package/lib/renderers/Cards.js.map +2 -2
- package/lib/renderers/Form/ConditionBuilder.d.ts +10 -0
- package/lib/renderers/Form/ConditionBuilder.js +6 -2
- package/lib/renderers/Form/ConditionBuilder.js.map +2 -2
- package/lib/renderers/Form/DiffEditor.d.ts +66 -20
- package/lib/renderers/Form/Editor.d.ts +66 -20
- package/lib/renderers/Form/Item.d.ts +4 -0
- package/lib/renderers/Form/Item.js +1 -1
- package/lib/renderers/Form/Item.js.map +2 -2
- package/lib/renderers/Form/TreeSelect.d.ts +0 -1
- package/lib/renderers/Form/TreeSelect.js +1 -9
- package/lib/renderers/Form/TreeSelect.js.map +2 -2
- package/lib/renderers/Form/index.js +8 -4
- package/lib/renderers/Form/index.js.map +2 -2
- package/lib/renderers/Icon.d.ts +1 -1
- package/lib/renderers/Icon.js +13 -8
- package/lib/renderers/Icon.js.map +2 -2
- package/lib/renderers/Table/index.d.ts +1 -0
- package/lib/renderers/Table/index.js +19 -5
- package/lib/renderers/Table/index.js.map +2 -2
- package/lib/renderers/Table-v2/index.d.ts +8 -5
- package/lib/renderers/Table-v2/index.js +83 -54
- package/lib/renderers/Table-v2/index.js.map +2 -2
- package/lib/store/combo.d.ts +72 -22
- package/lib/store/crud.d.ts +2 -0
- package/lib/store/crud.js +21 -1
- package/lib/store/crud.js.map +2 -2
- package/lib/store/form.d.ts +30 -9
- package/lib/store/form.js +28 -10
- package/lib/store/form.js.map +2 -2
- package/lib/store/formItem.d.ts +3 -1
- package/lib/store/formItem.js +3 -5
- package/lib/store/formItem.js.map +2 -2
- package/lib/store/list.d.ts +2 -0
- package/lib/store/list.js +8 -0
- package/lib/store/list.js.map +2 -2
- package/lib/store/table.d.ts +60 -18
- package/lib/themes/ang-ie11.css +166 -19
- package/lib/themes/ang.css +166 -19
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +166 -19
- package/lib/themes/antd.css +166 -19
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +166 -19
- package/lib/themes/cxd.css +166 -19
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +166 -19
- package/lib/themes/dark.css +166 -19
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default-ie11.css +166 -19
- package/lib/themes/default.css +166 -19
- package/lib/themes/default.css.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/icon.js +7 -0
- package/lib/utils/icon.js.map +2 -2
- package/package.json +1 -1
- package/schema.json +28 -25
- package/scss/_mixins.scss +1 -1
- package/scss/components/_condition-builder.scss +11 -0
- package/scss/components/_crud.scss +8 -3
- package/scss/components/_crud2.scss +148 -0
- package/scss/components/_result-box.scss +27 -8
- package/scss/components/_steps.scss +21 -26
- package/scss/components/_table-v2.scss +1 -3
- package/scss/components/form/_select.scss +4 -0
- package/scss/themes/_common.scss +1 -0
- package/sdk/ang-ie11.css +203 -20
- package/sdk/ang.css +203 -20
- package/sdk/antd-ie11.css +203 -20
- package/sdk/antd.css +203 -20
- package/sdk/barcode.js +51 -51
- package/sdk/charts.js +14 -14
- package/sdk/codemirror.js +7 -7
- package/sdk/color-picker.js +65 -65
- package/sdk/cropperjs.js +2 -2
- package/sdk/cxd-ie11.css +203 -20
- package/sdk/cxd.css +203 -20
- package/sdk/dark-ie11.css +203 -20
- package/sdk/dark.css +203 -20
- package/sdk/exceljs.js +1 -1
- package/sdk/helper.css.map +1 -1
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +16 -16
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +203 -20
- package/sdk/sdk.css +203 -20
- package/sdk/sdk.js +1344 -1340
- package/sdk/thirds/hls.js/hls.js +1 -1
- package/sdk/thirds/mpegts.js/mpegts.js +1 -1
- package/sdk/tinymce.js +57 -57
- package/src/Schema.ts +1 -0
- package/src/components/Range.tsx +14 -7
- package/src/components/ResultBox.tsx +65 -54
- package/src/components/Select.tsx +6 -5
- package/src/components/Steps.tsx +60 -18
- package/src/components/condition-builder/index.tsx +107 -8
- package/src/components/formula/Editor.tsx +1 -1
- package/src/components/formula/VariableList.tsx +2 -2
- package/src/components/table/index.tsx +190 -193
- package/src/index.tsx +1 -0
- package/src/renderers/Action.tsx +22 -11
- package/src/renderers/ButtonGroup.tsx +2 -2
- package/src/renderers/CRUD.tsx +2 -1
- package/src/renderers/CRUD2.tsx +1213 -0
- package/src/renderers/Card2.tsx +2 -3
- package/src/renderers/Cards.tsx +55 -10
- package/src/renderers/Form/ConditionBuilder.tsx +19 -2
- package/src/renderers/Form/Item.tsx +11 -1
- package/src/renderers/Form/TreeSelect.tsx +14 -16
- package/src/renderers/Form/index.tsx +11 -2
- package/src/renderers/Icon.tsx +8 -1
- package/src/renderers/Table/index.tsx +21 -5
- package/src/renderers/Table-v2/index.tsx +92 -72
- package/src/store/crud.ts +23 -1
- package/src/store/form.ts +31 -24
- package/src/store/formItem.ts +65 -52
- package/src/store/list.ts +10 -0
- package/src/types.ts +2 -1
- package/src/utils/icon.tsx +9 -0
@@ -119,7 +119,7 @@ export interface ColumnSchema {
|
|
119
119
|
* 列样式
|
120
120
|
*/
|
121
121
|
className?: string;
|
122
|
-
|
122
|
+
|
123
123
|
/**
|
124
124
|
* 表头单元格样式
|
125
125
|
*/
|
@@ -186,6 +186,10 @@ export interface RowSelectionSchema {
|
|
186
186
|
}
|
187
187
|
|
188
188
|
export interface ExpandableSchema {
|
189
|
+
/**
|
190
|
+
* 对应渲染器类型
|
191
|
+
*/
|
192
|
+
type: string;
|
189
193
|
/**
|
190
194
|
* 对应数据源的key值
|
191
195
|
*/
|
@@ -248,11 +252,6 @@ export interface TableSchemaV2 extends BaseSchema {
|
|
248
252
|
*/
|
249
253
|
expandable?: ExpandableSchema;
|
250
254
|
|
251
|
-
/**
|
252
|
-
* 表格行可展开内容配置
|
253
|
-
*/
|
254
|
-
expandableBody?: Array<SchemaObject>;
|
255
|
-
|
256
255
|
/**
|
257
256
|
* 粘性头部
|
258
257
|
*/
|
@@ -331,16 +330,7 @@ export interface TableV2Props extends RendererProps {
|
|
331
330
|
togglable: boolean;
|
332
331
|
}
|
333
332
|
|
334
|
-
|
335
|
-
type: 'table-v2',
|
336
|
-
storeType: TableStoreV2.name,
|
337
|
-
name: 'table-v2',
|
338
|
-
isolateScope: true
|
339
|
-
})
|
340
|
-
export default class TableRenderer extends React.Component<
|
341
|
-
TableV2Props,
|
342
|
-
object
|
343
|
-
> {
|
333
|
+
export default class TableV2 extends React.Component<TableV2Props, object> {
|
344
334
|
static contextType = ScopedContext;
|
345
335
|
|
346
336
|
renderedToolbars: Array<string> = [];
|
@@ -362,7 +352,7 @@ export default class TableRenderer extends React.Component<
|
|
362
352
|
const {store, columnsTogglable, columns} = props;
|
363
353
|
|
364
354
|
store.update({columnsTogglable, columns});
|
365
|
-
|
355
|
+
TableV2.syncRows(store, props, undefined) && this.syncSelected();
|
366
356
|
}
|
367
357
|
|
368
358
|
componentWillUnmount() {
|
@@ -485,7 +475,7 @@ export default class TableRenderer extends React.Component<
|
|
485
475
|
(props.data !== prevProps.data ||
|
486
476
|
(typeof props.source === 'string' && isPureVariable(props.source))))
|
487
477
|
) {
|
488
|
-
|
478
|
+
TableV2.syncRows(store, props, prevProps) && this.syncSelected();
|
489
479
|
}
|
490
480
|
|
491
481
|
if (!isEqual(prevProps.columns, props.columns)) {
|
@@ -600,9 +590,10 @@ export default class TableRenderer extends React.Component<
|
|
600
590
|
<div
|
601
591
|
key={col}
|
602
592
|
className={cx('Table-head-cell-wrapper', {
|
603
|
-
|
604
|
-
|
605
|
-
|
593
|
+
[`${column.className}`]: !!column.className,
|
594
|
+
[`${column.titleClassName}`]: !!column.titleClassName
|
595
|
+
})}
|
596
|
+
>
|
606
597
|
{content}
|
607
598
|
{remark}
|
608
599
|
{children}
|
@@ -624,7 +615,7 @@ export default class TableRenderer extends React.Component<
|
|
624
615
|
colIndex: number
|
625
616
|
) => {
|
626
617
|
const props: RenderProps = {};
|
627
|
-
const item = store.getRowByIndex(rowIndex);
|
618
|
+
const item = store.getRowByIndex(rowIndex) || {};
|
628
619
|
const obj = {
|
629
620
|
children: this.renderCellSchema(column, {
|
630
621
|
data: item.locals,
|
@@ -709,7 +700,9 @@ export default class TableRenderer extends React.Component<
|
|
709
700
|
if (column.classNameExpr) {
|
710
701
|
clone.className = (record: any, rowIndex: number) => {
|
711
702
|
const className = filter(column.classNameExpr, {record, rowIndex});
|
712
|
-
return `${className}${
|
703
|
+
return `${className}${
|
704
|
+
column.className ? ` ${column.className}` : ''
|
705
|
+
}`;
|
713
706
|
};
|
714
707
|
}
|
715
708
|
|
@@ -967,7 +960,9 @@ export default class TableRenderer extends React.Component<
|
|
967
960
|
isActived: store.hasColumnHidden(),
|
968
961
|
columns: store.columnsData,
|
969
962
|
onColumnToggle: this.handleColumnToggle,
|
970
|
-
children
|
963
|
+
children,
|
964
|
+
tooltipContainer:
|
965
|
+
env && env.getModalContainer ? env.getModalContainer : undefined
|
971
966
|
}
|
972
967
|
);
|
973
968
|
}
|
@@ -1058,10 +1053,7 @@ export default class TableRenderer extends React.Component<
|
|
1058
1053
|
}
|
1059
1054
|
|
1060
1055
|
@autobind
|
1061
|
-
async handleFilter(payload: {
|
1062
|
-
filterName: string,
|
1063
|
-
filterValue: string
|
1064
|
-
}) {
|
1056
|
+
async handleFilter(payload: {filterName: string; filterValue: string}) {
|
1065
1057
|
const {dispatchEvent, data, onFilter} = this.props;
|
1066
1058
|
const rendererEvent = await dispatchEvent(
|
1067
1059
|
'columnFilter',
|
@@ -1076,7 +1068,11 @@ export default class TableRenderer extends React.Component<
|
|
1076
1068
|
}
|
1077
1069
|
|
1078
1070
|
@autobind
|
1079
|
-
async handleRowClick(
|
1071
|
+
async handleRowClick(
|
1072
|
+
event: React.ChangeEvent<any>,
|
1073
|
+
rowItem: any,
|
1074
|
+
rowIndex?: number
|
1075
|
+
) {
|
1080
1076
|
const {dispatchEvent, data, onRow} = this.props;
|
1081
1077
|
|
1082
1078
|
const rendererEvent = await dispatchEvent(
|
@@ -1094,7 +1090,11 @@ export default class TableRenderer extends React.Component<
|
|
1094
1090
|
}
|
1095
1091
|
|
1096
1092
|
@autobind
|
1097
|
-
async handleOrderChange(
|
1093
|
+
async handleOrderChange(
|
1094
|
+
oldIndex: number,
|
1095
|
+
newIndex: number,
|
1096
|
+
levels: Array<string>
|
1097
|
+
) {
|
1098
1098
|
const {store} = this.props;
|
1099
1099
|
const rowItem = store.getRowByIndex(oldIndex, levels);
|
1100
1100
|
|
@@ -1121,10 +1121,7 @@ export default class TableRenderer extends React.Component<
|
|
1121
1121
|
return;
|
1122
1122
|
}
|
1123
1123
|
|
1124
|
-
onSaveOrder(
|
1125
|
-
movedItems,
|
1126
|
-
items
|
1127
|
-
);
|
1124
|
+
onSaveOrder(movedItems, items);
|
1128
1125
|
}
|
1129
1126
|
|
1130
1127
|
@autobind
|
@@ -1151,7 +1148,10 @@ export default class TableRenderer extends React.Component<
|
|
1151
1148
|
const dataSource = store.getData(data);
|
1152
1149
|
const selected: Array<any> = [];
|
1153
1150
|
dataSource.items.forEach((item: any, rowIndex: number) => {
|
1154
|
-
const flag = evalExpression(args?.selectedRowKeysExpr, {
|
1151
|
+
const flag = evalExpression(args?.selectedRowKeysExpr, {
|
1152
|
+
record: item,
|
1153
|
+
rowIndex
|
1154
|
+
});
|
1155
1155
|
if (flag) {
|
1156
1156
|
selected.push(item[keyField]);
|
1157
1157
|
}
|
@@ -1171,7 +1171,6 @@ export default class TableRenderer extends React.Component<
|
|
1171
1171
|
rowSelection,
|
1172
1172
|
columns,
|
1173
1173
|
expandable,
|
1174
|
-
expandableBody,
|
1175
1174
|
footSummary,
|
1176
1175
|
headSummary,
|
1177
1176
|
loading,
|
@@ -1199,9 +1198,9 @@ export default class TableRenderer extends React.Component<
|
|
1199
1198
|
delete expandableConfig.expandableOn;
|
1200
1199
|
}
|
1201
1200
|
|
1202
|
-
if (
|
1201
|
+
if (expandable && expandable.type) {
|
1203
1202
|
expandableConfig.expandedRowRender = (record: any, rowIndex: number) =>
|
1204
|
-
this.renderSchema('expandableBody',
|
1203
|
+
this.renderSchema('expandableBody', {...expandable}, {data: record});
|
1205
1204
|
}
|
1206
1205
|
|
1207
1206
|
if (expandable.expandedRowClassNameExpr) {
|
@@ -1287,8 +1286,8 @@ export default class TableRenderer extends React.Component<
|
|
1287
1286
|
let itemActionsConfig = undefined;
|
1288
1287
|
if (itemActions) {
|
1289
1288
|
const finalActions = Array.isArray(itemActions)
|
1290
|
-
|
1291
|
-
|
1289
|
+
? itemActions.filter(action => !action.hiddenOnHover)
|
1290
|
+
: [];
|
1292
1291
|
|
1293
1292
|
if (!finalActions.length) {
|
1294
1293
|
return null;
|
@@ -1346,41 +1345,34 @@ export default class TableRenderer extends React.Component<
|
|
1346
1345
|
}
|
1347
1346
|
|
1348
1347
|
renderHeading() {
|
1349
|
-
let {
|
1350
|
-
store,
|
1351
|
-
classnames: cx,
|
1352
|
-
headingClassName,
|
1353
|
-
translate: __
|
1354
|
-
} = this.props;
|
1348
|
+
let {store, classnames: cx, headingClassName, translate: __} = this.props;
|
1355
1349
|
|
1356
1350
|
if (store.moved) {
|
1357
1351
|
return (
|
1358
1352
|
<div className={cx('Table-heading', headingClassName)} key="heading">
|
1359
|
-
{
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
) : null
|
1383
|
-
}
|
1353
|
+
{store.moved ? (
|
1354
|
+
<span>
|
1355
|
+
{__('Table.moved', {
|
1356
|
+
moved: store.moved
|
1357
|
+
})}
|
1358
|
+
<button
|
1359
|
+
type="button"
|
1360
|
+
className={cx('Button Button--xs Button--success m-l-sm')}
|
1361
|
+
onClick={this.handleSaveOrder}
|
1362
|
+
>
|
1363
|
+
<Icon icon="check" className="icon m-r-xs" />
|
1364
|
+
{__('Form.submit')}
|
1365
|
+
</button>
|
1366
|
+
<button
|
1367
|
+
type="button"
|
1368
|
+
className={cx('Button Button--xs Button--danger m-l-sm')}
|
1369
|
+
onClick={this.reset}
|
1370
|
+
>
|
1371
|
+
<Icon icon="close" className="icon m-r-xs" />
|
1372
|
+
{__('Table.discard')}
|
1373
|
+
</button>
|
1374
|
+
</span>
|
1375
|
+
) : null}
|
1384
1376
|
</div>
|
1385
1377
|
);
|
1386
1378
|
}
|
@@ -1392,7 +1384,7 @@ export default class TableRenderer extends React.Component<
|
|
1392
1384
|
const {classnames: cx} = this.props;
|
1393
1385
|
|
1394
1386
|
this.renderedToolbars = []; // 用来记录哪些 toolbar 已经渲染了
|
1395
|
-
|
1387
|
+
|
1396
1388
|
const heading = this.renderHeading();
|
1397
1389
|
|
1398
1390
|
return (
|
@@ -1404,3 +1396,31 @@ export default class TableRenderer extends React.Component<
|
|
1404
1396
|
);
|
1405
1397
|
}
|
1406
1398
|
}
|
1399
|
+
|
1400
|
+
@Renderer({
|
1401
|
+
type: 'table-v2',
|
1402
|
+
storeType: TableStoreV2.name,
|
1403
|
+
name: 'table-v2',
|
1404
|
+
isolateScope: true
|
1405
|
+
})
|
1406
|
+
export class TableRenderer extends TableV2 {
|
1407
|
+
receive(values: any, subPath?: string) {
|
1408
|
+
const scoped = this.context as IScopedContext;
|
1409
|
+
const parents = scoped?.parent?.getComponents();
|
1410
|
+
|
1411
|
+
/**
|
1412
|
+
* 因为Table在scope上注册,导致getComponentByName查询组件时会优先找到Table,和CRUD联动的动作都会失效
|
1413
|
+
* 这里先做兼容处理,把动作交给上层的CRUD处理
|
1414
|
+
*/
|
1415
|
+
if (Array.isArray(parents) && parents.length) {
|
1416
|
+
// CRUD的name会透传给Table,这样可以保证找到CRUD
|
1417
|
+
const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name);
|
1418
|
+
|
1419
|
+
return crud?.receive?.(values, subPath);
|
1420
|
+
}
|
1421
|
+
|
1422
|
+
if (subPath) {
|
1423
|
+
return scoped.send(subPath, values);
|
1424
|
+
}
|
1425
|
+
}
|
1426
|
+
}
|
package/src/store/crud.ts
CHANGED
@@ -494,6 +494,16 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
|
|
494
494
|
self.unSelectedItems.replace(items);
|
495
495
|
};
|
496
496
|
|
497
|
+
const updateSelectData = (selected: Array<any>, unSelected: Array<any>) => {
|
498
|
+
self.selectedItems.replace(selected);
|
499
|
+
self.unSelectedItems.replace(unSelected);
|
500
|
+
// 同步到data中,使filter等部分也能拿到
|
501
|
+
self.reInitData({
|
502
|
+
selectedItems: selected,
|
503
|
+
unSelectedItems: unSelected
|
504
|
+
});
|
505
|
+
};
|
506
|
+
|
497
507
|
const setInnerModalOpened = (value: boolean) => {
|
498
508
|
self.hasInnerModalOpen = value;
|
499
509
|
};
|
@@ -515,7 +525,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
|
|
515
525
|
...self.pristine,
|
516
526
|
items: rowsData,
|
517
527
|
count: 0,
|
518
|
-
total:
|
528
|
+
total: rowsData.length
|
519
529
|
};
|
520
530
|
|
521
531
|
self.items.replace(rowsData);
|
@@ -555,7 +565,19 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
|
|
555
565
|
});
|
556
566
|
};
|
557
567
|
|
568
|
+
const getData = (superData: any): any => {
|
569
|
+
return createObject(superData, {
|
570
|
+
total: self.total,
|
571
|
+
page: self.page,
|
572
|
+
items: self.items.concat(),
|
573
|
+
selectedItems: self.selectedItems.concat(),
|
574
|
+
unSelectedItems: self.unSelectedItems.concat()
|
575
|
+
});
|
576
|
+
};
|
577
|
+
|
558
578
|
return {
|
579
|
+
getData,
|
580
|
+
updateSelectData,
|
559
581
|
setPristineQuery,
|
560
582
|
updateQuery,
|
561
583
|
fetchInitData,
|
package/src/store/form.ts
CHANGED
@@ -9,6 +9,7 @@ import {
|
|
9
9
|
Instance
|
10
10
|
} from 'mobx-state-tree';
|
11
11
|
import debounce from 'lodash/debounce';
|
12
|
+
import find from 'lodash/find';
|
12
13
|
import {ServiceStore} from './service';
|
13
14
|
import {FormItemStore, IFormItemStore, SFormItemStore} from './formItem';
|
14
15
|
import {Api, ApiObject, fetchOptions, Payload} from '../types';
|
@@ -326,7 +327,6 @@ export const FormStore = ServiceStore.named('FormStore')
|
|
326
327
|
}
|
327
328
|
|
328
329
|
if (!json.ok) {
|
329
|
-
|
330
330
|
if (json.status === 422 && json.errors) {
|
331
331
|
setFormItemErrors(json.errors);
|
332
332
|
|
@@ -359,22 +359,23 @@ export const FormStore = ServiceStore.named('FormStore')
|
|
359
359
|
);
|
360
360
|
if (!ret?.dispatcher?.prevented) {
|
361
361
|
self.msg &&
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
362
|
+
getEnv(self).notify(
|
363
|
+
'success',
|
364
|
+
self.msg,
|
365
|
+
json.msgTimeout !== undefined
|
366
|
+
? {
|
367
|
+
closeButton: true,
|
368
|
+
timeout: json.msgTimeout
|
369
|
+
}
|
370
|
+
: undefined
|
371
|
+
);
|
372
372
|
}
|
373
373
|
return json.data;
|
374
374
|
}
|
375
375
|
} catch (e) {
|
376
376
|
self.markSaving(false);
|
377
|
-
let ret =
|
377
|
+
let ret =
|
378
|
+
options && options.onFailed && options.onFailed(e.response || {});
|
378
379
|
if (ret?.then) {
|
379
380
|
ret = yield ret;
|
380
381
|
}
|
@@ -486,7 +487,7 @@ export const FormStore = ServiceStore.named('FormStore')
|
|
486
487
|
if (dispatcher?.then) {
|
487
488
|
dispatcher = yield dispatcher;
|
488
489
|
}
|
489
|
-
if (!dispatcher?.prevented){
|
490
|
+
if (!dispatcher?.prevented) {
|
490
491
|
msg && env.notify('error', msg);
|
491
492
|
}
|
492
493
|
throw new Error(msg);
|
@@ -548,20 +549,26 @@ export const FormStore = ServiceStore.named('FormStore')
|
|
548
549
|
return self.valid;
|
549
550
|
});
|
550
551
|
|
551
|
-
const validateFields: (
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
552
|
+
const validateFields: (
|
553
|
+
fields: Array<string | {name: string; rules: {[propName: string]: any}}>
|
554
|
+
) => Promise<boolean> = flow(function* validateFields(
|
555
|
+
fields: Array<string | {name: string; rules: {[propName: string]: any}}>
|
556
|
+
) {
|
557
|
+
const items = self.items.concat();
|
558
|
+
const normalizedfields = fields.map(field =>
|
559
|
+
typeof field === 'string' ? {name: field, rules: {}} : field
|
560
|
+
);
|
561
|
+
let result: Array<boolean> = [];
|
562
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
563
|
+
let item = items[i] as IFormItemStore;
|
564
|
+
const field = find(normalizedfields, field => field.name === item.name);
|
557
565
|
|
558
|
-
|
559
|
-
|
560
|
-
}
|
566
|
+
if (field) {
|
567
|
+
result.push(yield item.validate(self.data, undefined, field.rules));
|
561
568
|
}
|
562
|
-
return result.every(item => item);
|
563
569
|
}
|
564
|
-
|
570
|
+
return result.every(item => item);
|
571
|
+
});
|
565
572
|
|
566
573
|
function clearErrors() {
|
567
574
|
const items = self.items.concat();
|
package/src/store/formItem.ts
CHANGED
@@ -326,70 +326,83 @@ export const FormItemStore = StoreNode.named('FormItemStore')
|
|
326
326
|
}
|
327
327
|
|
328
328
|
let validateCancel: Function | null = null;
|
329
|
-
const validate: (
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
329
|
+
const validate: (
|
330
|
+
data: Object,
|
331
|
+
hook?: any,
|
332
|
+
/**
|
333
|
+
* customRules主要是为了支持action.require的验证方式
|
334
|
+
* 这样可以基于不同的action实现不同的校验规则
|
335
|
+
*/
|
336
|
+
customRules?: {[propName: string]: any}
|
337
|
+
) => Promise<boolean> = flow(function* validate(
|
338
|
+
data: Object,
|
339
|
+
hook?: any,
|
340
|
+
customRules?: {[propName: string]: any}
|
341
|
+
) {
|
342
|
+
if (self.validating && !isEffectiveApi(self.validateApi, data)) {
|
343
|
+
return self.valid;
|
344
|
+
}
|
340
345
|
|
341
|
-
|
342
|
-
|
343
|
-
|
346
|
+
self.validating = true;
|
347
|
+
clearError();
|
348
|
+
if (hook) {
|
349
|
+
yield hook();
|
350
|
+
}
|
344
351
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
352
|
+
addError(
|
353
|
+
doValidate(
|
354
|
+
self.tmpValue,
|
355
|
+
data,
|
356
|
+
customRules ? str2rules(customRules) : self.rules,
|
357
|
+
self.messages,
|
358
|
+
self.__
|
359
|
+
)
|
360
|
+
);
|
350
361
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
createObject(data, {[self.name]: self.tmpValue}),
|
355
|
-
{
|
356
|
-
cancelExecutor: (executor: Function) =>
|
357
|
-
(validateCancel = executor)
|
358
|
-
}
|
359
|
-
);
|
362
|
+
if (!self.errors.length && isEffectiveApi(self.validateApi, data)) {
|
363
|
+
if (validateCancel) {
|
364
|
+
validateCancel();
|
360
365
|
validateCancel = null;
|
366
|
+
}
|
361
367
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
)
|
368
|
+
const json: Payload = yield getEnv(self).fetcher(
|
369
|
+
self.validateApi,
|
370
|
+
/** 如果配置validateApi,需要将用户最新输入同步到数据域内 */
|
371
|
+
createObject(data, {[self.name]: self.tmpValue}),
|
372
|
+
{
|
373
|
+
cancelExecutor: (executor: Function) => (validateCancel = executor)
|
368
374
|
}
|
375
|
+
);
|
376
|
+
validateCancel = null;
|
377
|
+
|
378
|
+
if (!json.ok && json.status === 422 && json.errors) {
|
379
|
+
addError(
|
380
|
+
String(json.errors || json.msg || `表单项「${self.name}」校验失败`)
|
381
|
+
);
|
369
382
|
}
|
383
|
+
}
|
370
384
|
|
371
|
-
|
385
|
+
self.validated = true;
|
372
386
|
|
373
|
-
|
374
|
-
|
375
|
-
|
387
|
+
if (self.unique && self.form?.parentStore?.storeType === 'ComboStore') {
|
388
|
+
const combo = self.form.parentStore as IComboStore;
|
389
|
+
const group = combo.uniques.get(self.name) as IUniqueGroup;
|
376
390
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
}
|
391
|
+
if (
|
392
|
+
group.items.some(
|
393
|
+
item =>
|
394
|
+
item !== self &&
|
395
|
+
self.tmpValue !== undefined &&
|
396
|
+
item.value === self.tmpValue
|
397
|
+
)
|
398
|
+
) {
|
399
|
+
addError(self.__('Form.unique'));
|
387
400
|
}
|
388
|
-
|
389
|
-
self.validating = false;
|
390
|
-
return self.valid;
|
391
401
|
}
|
392
|
-
|
402
|
+
|
403
|
+
self.validating = false;
|
404
|
+
return self.valid;
|
405
|
+
});
|
393
406
|
|
394
407
|
function setError(msg: string | Array<string>, tag: string = 'builtin') {
|
395
408
|
clearError();
|
package/src/store/list.ts
CHANGED
@@ -233,6 +233,14 @@ export const ListStore = iRendererStore
|
|
233
233
|
}
|
234
234
|
}
|
235
235
|
|
236
|
+
function clearAll() {
|
237
|
+
self.selectedItems.clear();
|
238
|
+
}
|
239
|
+
|
240
|
+
function selectAll() {
|
241
|
+
self.selectedItems.replace(self.checkableItems);
|
242
|
+
}
|
243
|
+
|
236
244
|
function toggle(item: IItem) {
|
237
245
|
if (!item.checkable) {
|
238
246
|
return;
|
@@ -289,6 +297,8 @@ export const ListStore = iRendererStore
|
|
289
297
|
initItems,
|
290
298
|
updateSelected,
|
291
299
|
toggleAll,
|
300
|
+
clearAll,
|
301
|
+
selectAll,
|
292
302
|
toggle,
|
293
303
|
clear,
|
294
304
|
setOrderByInfo,
|
package/src/types.ts
CHANGED
package/src/utils/icon.tsx
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
|
5
5
|
import React from 'react';
|
6
|
+
import {getIcon, Icon} from '../components/icons';
|
6
7
|
import {ClassNamesFn} from '../theme';
|
7
8
|
|
8
9
|
/**
|
@@ -17,10 +18,18 @@ export const generateIcon = (
|
|
17
18
|
className?: string,
|
18
19
|
classNameProp?: string
|
19
20
|
) => {
|
21
|
+
if (!icon) {
|
22
|
+
return null;
|
23
|
+
}
|
24
|
+
|
20
25
|
if (React.isValidElement(icon)) {
|
21
26
|
return icon;
|
22
27
|
}
|
23
28
|
|
29
|
+
if (getIcon(icon)) {
|
30
|
+
return <Icon icon={icon} className={cx(className, icon, classNameProp)} />;
|
31
|
+
}
|
32
|
+
|
24
33
|
const isURLIcon = icon?.indexOf('.') !== -1;
|
25
34
|
|
26
35
|
return icon ? (
|