amis-core 2.9.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/Root.d.ts +89 -4
- package/esm/Root.js +15 -4
- package/esm/RootRenderer.d.ts +3 -1
- package/esm/RootRenderer.js +9 -3
- package/esm/SchemaRenderer.d.ts +4 -2
- package/esm/SchemaRenderer.js +32 -24
- package/esm/Scoped.d.ts +8 -0
- package/esm/Scoped.js +20 -5
- package/esm/StatusScoped.d.ts +58 -0
- package/esm/StatusScoped.js +54 -0
- package/esm/WithRootStore.d.ts +2 -2
- package/esm/WithRootStore.js +1 -1
- package/esm/WithStore.js +6 -2
- package/esm/actions/Action.d.ts +1 -0
- package/esm/actions/Action.js +19 -5
- package/esm/actions/AjaxAction.js +1 -1
- package/esm/actions/BreakAction.js +1 -1
- package/esm/actions/BroadcastAction.js +1 -1
- package/esm/actions/CmptAction.js +8 -7
- package/esm/actions/ContinueAction.js +1 -1
- package/esm/actions/CopyAction.js +1 -1
- package/esm/actions/CustomAction.js +4 -4
- package/esm/actions/DialogAction.d.ts +16 -2
- package/esm/actions/DialogAction.js +23 -7
- package/esm/actions/DrawerAction.js +1 -1
- package/esm/actions/EmailAction.js +1 -1
- package/esm/actions/LinkAction.js +1 -1
- package/esm/actions/LoopAction.js +1 -1
- package/esm/actions/PageAction.js +1 -1
- package/esm/actions/ParallelAction.js +1 -1
- package/esm/actions/SwitchAction.js +1 -1
- package/esm/actions/ToastAction.js +1 -1
- package/esm/components/CustomStyle.d.ts +13 -0
- package/esm/components/CustomStyle.js +18 -0
- package/esm/components/LazyComponent.d.ts +1 -1
- package/esm/components/LazyComponent.js +1 -1
- package/esm/components/Overlay.d.ts +3 -3
- package/esm/components/Overlay.js +1 -1
- package/esm/components/PopOver.d.ts +2 -2
- package/esm/components/PopOver.js +1 -1
- package/esm/env.d.ts +10 -2
- package/esm/env.js +1 -1
- package/esm/envOverwrite.js +1 -5
- package/esm/factory.d.ts +5 -3
- package/esm/factory.js +3 -3
- package/esm/index.d.ts +11 -4
- package/esm/index.js +55 -33
- package/esm/locale.d.ts +2 -2
- package/esm/locale.js +10 -3
- package/esm/renderers/Form.d.ts +3 -2
- package/esm/renderers/Form.js +216 -180
- package/esm/renderers/Item.d.ts +55 -41
- package/esm/renderers/Item.js +30 -19
- package/esm/renderers/Options.js +11 -4
- package/esm/renderers/Placeholder.js +1 -1
- package/esm/renderers/builtin.js +1 -1
- package/esm/renderers/register.js +1 -1
- package/esm/renderers/wrapControl.d.ts +2 -2
- package/esm/renderers/wrapControl.js +13 -16
- package/esm/store/app.d.ts +1 -0
- package/esm/store/app.js +1 -1
- package/esm/store/combo.d.ts +3 -0
- package/esm/store/combo.js +1 -1
- package/esm/store/crud.d.ts +2 -0
- package/esm/store/crud.js +31 -9
- package/esm/store/form.d.ts +1 -0
- package/esm/store/form.js +10 -4
- package/esm/store/formItem.js +2 -2
- package/esm/store/iRenderer.d.ts +1 -0
- package/esm/store/iRenderer.js +54 -13
- package/esm/store/index.js +1 -1
- package/esm/store/list.d.ts +1 -0
- package/esm/store/list.js +7 -3
- package/esm/store/manager.js +1 -1
- package/esm/store/modal.d.ts +1 -0
- package/esm/store/modal.js +1 -1
- package/esm/store/node.js +1 -1
- package/esm/store/pagination.d.ts +1 -0
- package/esm/store/pagination.js +2 -2
- package/esm/store/root.d.ts +4 -6
- package/esm/store/root.js +53 -24
- package/esm/store/service.d.ts +1 -0
- package/esm/store/service.js +1 -1
- package/esm/store/status.d.ts +12 -0
- package/esm/store/status.js +38 -0
- package/esm/store/table.d.ts +28 -23
- package/esm/store/table.js +26 -5
- package/esm/store/table2.d.ts +7 -6
- package/esm/store/table2.js +27 -23
- package/esm/theme.d.ts +1 -1
- package/esm/theme.js +1 -1
- package/esm/types.d.ts +7 -1
- package/esm/utils/Animation.js +1 -1
- package/esm/utils/ColorScale.js +1 -1
- package/esm/utils/DataSchema.js +1 -1
- package/esm/utils/DataScope.d.ts +3 -5
- package/esm/utils/DataScope.js +88 -31
- package/esm/utils/RootClose.js +1 -1
- package/esm/utils/SimpleMap.js +1 -1
- package/esm/utils/api.js +14 -5
- package/esm/utils/attachmentAdpator.js +2 -2
- package/esm/utils/autobind.js +1 -1
- package/esm/utils/columnsSplit.js +1 -1
- package/esm/utils/dataMapping.js +1 -1
- package/esm/utils/date.d.ts +7 -0
- package/esm/utils/date.js +34 -2
- package/esm/utils/debug.js +4 -4
- package/esm/utils/decodeEntity.js +1 -1
- package/esm/utils/dom.d.ts +3 -0
- package/esm/utils/dom.js +47 -10
- package/esm/utils/errors.js +1 -1
- package/esm/utils/escapeHtml.js +1 -1
- package/esm/utils/filter-schema.js +1 -1
- package/esm/utils/filter.js +1 -1
- package/esm/utils/formatDuration.js +1 -1
- package/esm/utils/formula.js +2 -2
- package/esm/utils/getVariable.js +1 -1
- package/esm/utils/grammar.js +3 -3
- package/esm/utils/handleAction.js +1 -1
- package/esm/utils/helper.d.ts +9 -2
- package/esm/utils/helper.js +52 -20
- package/esm/utils/highlight.js +1 -1
- package/esm/utils/icon.d.ts +6 -1
- package/esm/utils/icon.js +6 -1
- package/esm/utils/image.js +1 -1
- package/esm/utils/isPureVariable.js +3 -3
- package/esm/utils/json-schema-2-amis-schema.js +1 -1
- package/esm/utils/keyToPath.js +1 -1
- package/esm/utils/makeSorter.js +1 -1
- package/esm/utils/memoryParse.d.ts +17 -0
- package/esm/utils/memoryParse.js +26 -0
- package/esm/utils/normalizeLink.js +1 -1
- package/esm/utils/normalizeOptions.js +4 -2
- package/esm/utils/object.d.ts +2 -0
- package/esm/utils/object.js +27 -2
- package/esm/utils/offset.js +1 -1
- package/esm/utils/offsetParent.js +1 -1
- package/esm/utils/optionValueCompare.js +1 -1
- package/esm/utils/position.js +1 -1
- package/esm/utils/prettyBytes.js +1 -1
- package/esm/utils/renderer-event.js +35 -32
- package/esm/utils/replaceText.js +1 -1
- package/esm/utils/resize-sensor.js +1 -1
- package/esm/utils/resolveCondition.d.ts +1 -0
- package/esm/utils/resolveCondition.js +19 -4
- package/esm/utils/resolveVariable.js +4 -3
- package/esm/utils/resolveVariableAndFilter.js +1 -1
- package/esm/utils/resolveVariableAndFilterForAsync.d.ts +6 -1
- package/esm/utils/resolveVariableAndFilterForAsync.js +23 -5
- package/esm/utils/scrollPosition.js +1 -1
- package/esm/utils/string2regExp.js +1 -1
- package/esm/utils/stripNumber.js +1 -1
- package/esm/utils/style-helper.d.ts +12 -4
- package/esm/utils/style-helper.js +96 -19
- package/esm/utils/style.js +2 -2
- package/esm/utils/toNumber.js +1 -1
- package/esm/utils/tokenize.js +1 -1
- package/esm/utils/tpl-builtin.d.ts +2 -1
- package/esm/utils/tpl-builtin.js +19 -2
- package/esm/utils/tpl-lodash.js +3 -2
- package/esm/utils/tpl.d.ts +2 -0
- package/esm/utils/tpl.js +24 -2
- package/esm/utils/uncontrollable.js +1 -1
- package/esm/utils/validations.d.ts +4 -1
- package/esm/utils/validations.js +27 -12
- package/lib/Root.d.ts +89 -4
- package/lib/Root.js +15 -4
- package/lib/RootRenderer.d.ts +3 -1
- package/lib/RootRenderer.js +8 -2
- package/lib/SchemaRenderer.d.ts +4 -2
- package/lib/SchemaRenderer.js +32 -23
- package/lib/Scoped.d.ts +8 -0
- package/lib/Scoped.js +20 -4
- package/lib/StatusScoped.d.ts +58 -0
- package/lib/StatusScoped.js +63 -0
- package/lib/WithRootStore.d.ts +2 -2
- package/lib/WithRootStore.js +1 -1
- package/lib/WithStore.js +6 -2
- package/lib/actions/Action.d.ts +1 -0
- package/lib/actions/Action.js +19 -5
- package/lib/actions/AjaxAction.js +1 -1
- package/lib/actions/BreakAction.js +1 -1
- package/lib/actions/BroadcastAction.js +1 -1
- package/lib/actions/CmptAction.js +8 -7
- package/lib/actions/ContinueAction.js +1 -1
- package/lib/actions/CopyAction.js +1 -1
- package/lib/actions/CustomAction.js +4 -4
- package/lib/actions/DialogAction.d.ts +16 -2
- package/lib/actions/DialogAction.js +23 -7
- package/lib/actions/DrawerAction.js +1 -1
- package/lib/actions/EmailAction.js +1 -1
- package/lib/actions/LinkAction.js +1 -1
- package/lib/actions/LoopAction.js +1 -1
- package/lib/actions/PageAction.js +1 -1
- package/lib/actions/ParallelAction.js +1 -1
- package/lib/actions/SwitchAction.js +1 -1
- package/lib/actions/ToastAction.js +1 -1
- package/lib/components/CustomStyle.d.ts +13 -0
- package/lib/components/CustomStyle.js +22 -0
- package/lib/components/LazyComponent.d.ts +1 -1
- package/lib/components/LazyComponent.js +1 -1
- package/lib/components/Overlay.d.ts +3 -3
- package/lib/components/Overlay.js +1 -1
- package/lib/components/PopOver.d.ts +2 -2
- package/lib/components/PopOver.js +1 -1
- package/lib/env.d.ts +10 -2
- package/lib/env.js +1 -1
- package/lib/envOverwrite.js +1 -5
- package/lib/factory.d.ts +5 -3
- package/lib/factory.js +3 -3
- package/lib/index.d.ts +11 -4
- package/lib/index.js +61 -23
- package/lib/locale.d.ts +2 -2
- package/lib/locale.js +10 -3
- package/lib/renderers/Form.d.ts +3 -2
- package/lib/renderers/Form.js +215 -179
- package/lib/renderers/Item.d.ts +55 -41
- package/lib/renderers/Item.js +30 -19
- package/lib/renderers/Options.js +11 -4
- package/lib/renderers/Placeholder.js +1 -1
- package/lib/renderers/builtin.js +1 -1
- package/lib/renderers/register.js +1 -1
- package/lib/renderers/wrapControl.d.ts +2 -2
- package/lib/renderers/wrapControl.js +12 -15
- package/lib/store/app.d.ts +1 -0
- package/lib/store/app.js +1 -1
- package/lib/store/combo.d.ts +3 -0
- package/lib/store/combo.js +1 -1
- package/lib/store/crud.d.ts +2 -0
- package/lib/store/crud.js +31 -9
- package/lib/store/form.d.ts +1 -0
- package/lib/store/form.js +10 -4
- package/lib/store/formItem.js +2 -2
- package/lib/store/iRenderer.d.ts +1 -0
- package/lib/store/iRenderer.js +53 -12
- package/lib/store/index.js +1 -1
- package/lib/store/list.d.ts +1 -0
- package/lib/store/list.js +7 -3
- package/lib/store/manager.js +1 -1
- package/lib/store/modal.d.ts +1 -0
- package/lib/store/modal.js +1 -1
- package/lib/store/node.js +1 -1
- package/lib/store/pagination.d.ts +1 -0
- package/lib/store/pagination.js +2 -2
- package/lib/store/root.d.ts +4 -6
- package/lib/store/root.js +52 -23
- package/lib/store/service.d.ts +1 -0
- package/lib/store/service.js +1 -1
- package/lib/store/status.d.ts +12 -0
- package/lib/store/status.js +42 -0
- package/lib/store/table.d.ts +28 -23
- package/lib/store/table.js +26 -5
- package/lib/store/table2.d.ts +7 -6
- package/lib/store/table2.js +27 -23
- package/lib/theme.d.ts +1 -1
- package/lib/theme.js +1 -1
- package/lib/types.d.ts +7 -1
- package/lib/utils/Animation.js +1 -1
- package/lib/utils/ColorScale.js +1 -1
- package/lib/utils/DataSchema.js +1 -1
- package/lib/utils/DataScope.d.ts +3 -5
- package/lib/utils/DataScope.js +86 -29
- package/lib/utils/RootClose.js +1 -1
- package/lib/utils/SimpleMap.js +1 -1
- package/lib/utils/api.js +13 -4
- package/lib/utils/attachmentAdpator.js +2 -2
- package/lib/utils/autobind.js +1 -1
- package/lib/utils/columnsSplit.js +1 -1
- package/lib/utils/dataMapping.js +1 -1
- package/lib/utils/date.d.ts +7 -0
- package/lib/utils/date.js +34 -1
- package/lib/utils/debug.js +4 -4
- package/lib/utils/decodeEntity.js +1 -1
- package/lib/utils/dom.d.ts +3 -0
- package/lib/utils/dom.js +48 -9
- package/lib/utils/errors.js +1 -1
- package/lib/utils/escapeHtml.js +1 -1
- package/lib/utils/filter-schema.js +1 -1
- package/lib/utils/filter.js +1 -1
- package/lib/utils/formatDuration.js +1 -1
- package/lib/utils/formula.js +2 -2
- package/lib/utils/getVariable.js +1 -1
- package/lib/utils/grammar.js +3 -3
- package/lib/utils/handleAction.js +1 -1
- package/lib/utils/helper.d.ts +9 -2
- package/lib/utils/helper.js +53 -19
- package/lib/utils/highlight.js +1 -1
- package/lib/utils/icon.d.ts +6 -1
- package/lib/utils/icon.js +6 -1
- package/lib/utils/image.js +1 -1
- package/lib/utils/isPureVariable.js +3 -3
- package/lib/utils/json-schema-2-amis-schema.js +1 -1
- package/lib/utils/keyToPath.js +1 -1
- package/lib/utils/makeSorter.js +1 -1
- package/lib/utils/memoryParse.d.ts +17 -0
- package/lib/utils/memoryParse.js +30 -0
- package/lib/utils/normalizeLink.js +1 -1
- package/lib/utils/normalizeOptions.js +4 -2
- package/lib/utils/object.d.ts +2 -0
- package/lib/utils/object.js +28 -1
- package/lib/utils/offset.js +1 -1
- package/lib/utils/offsetParent.js +1 -1
- package/lib/utils/optionValueCompare.js +1 -1
- package/lib/utils/position.js +1 -1
- package/lib/utils/prettyBytes.js +1 -1
- package/lib/utils/renderer-event.js +35 -32
- package/lib/utils/replaceText.js +1 -1
- package/lib/utils/resize-sensor.js +1 -1
- package/lib/utils/resolveCondition.d.ts +1 -0
- package/lib/utils/resolveCondition.js +19 -3
- package/lib/utils/resolveVariable.js +3 -2
- package/lib/utils/resolveVariableAndFilter.js +1 -1
- package/lib/utils/resolveVariableAndFilterForAsync.d.ts +6 -1
- package/lib/utils/resolveVariableAndFilterForAsync.js +22 -3
- package/lib/utils/scrollPosition.js +1 -1
- package/lib/utils/string2regExp.js +1 -1
- package/lib/utils/stripNumber.js +1 -1
- package/lib/utils/style-helper.d.ts +12 -4
- package/lib/utils/style-helper.js +101 -18
- package/lib/utils/style.js +2 -2
- package/lib/utils/toNumber.js +1 -1
- package/lib/utils/tokenize.js +1 -1
- package/lib/utils/tpl-builtin.d.ts +2 -1
- package/lib/utils/tpl-builtin.js +19 -2
- package/lib/utils/tpl-lodash.js +3 -2
- package/lib/utils/tpl.d.ts +2 -0
- package/lib/utils/tpl.js +24 -1
- package/lib/utils/uncontrollable.js +1 -1
- package/lib/utils/validations.d.ts +4 -1
- package/lib/utils/validations.js +27 -12
- package/package.json +3 -3
package/lib/renderers/Form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.1.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -66,6 +66,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
66
66
|
_this.reload = _this.reload.bind(_this);
|
|
67
67
|
_this.silentReload = _this.silentReload.bind(_this);
|
|
68
68
|
_this.initInterval = _this.initInterval.bind(_this);
|
|
69
|
+
_this.dispatchInited = _this.dispatchInited.bind(_this);
|
|
69
70
|
_this.blockRouting = _this.blockRouting.bind(_this);
|
|
70
71
|
_this.beforePageUnload = _this.beforePageUnload.bind(_this);
|
|
71
72
|
var store = props.store, canAccessSuperData = props.canAccessSuperData, persistData = props.persistData, simpleMode = props.simpleMode;
|
|
@@ -148,6 +149,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
148
149
|
return helper.until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, initCheckInterval);
|
|
149
150
|
}
|
|
150
151
|
})
|
|
152
|
+
.then(this.dispatchInited)
|
|
151
153
|
.then(this.initInterval)
|
|
152
154
|
.then(this.onInit);
|
|
153
155
|
}
|
|
@@ -167,7 +169,9 @@ var Form = /** @class */ (function (_super) {
|
|
|
167
169
|
store[store.hasRemoteData ? 'fetchData' : 'fetchInitData'](props.initApi, store.data, {
|
|
168
170
|
successMessage: fetchSuccess,
|
|
169
171
|
errorMessage: fetchFailed
|
|
170
|
-
})
|
|
172
|
+
})
|
|
173
|
+
.then(this.dispatchInited)
|
|
174
|
+
.then(this.initInterval);
|
|
171
175
|
}
|
|
172
176
|
};
|
|
173
177
|
Form.prototype.componentWillUnmount = function () {
|
|
@@ -182,6 +186,27 @@ var Form = /** @class */ (function (_super) {
|
|
|
182
186
|
window.removeEventListener('beforeunload', this.beforePageUnload);
|
|
183
187
|
(_a = this.unBlockRouting) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
184
188
|
};
|
|
189
|
+
Form.prototype.dispatchInited = function (value) {
|
|
190
|
+
var _a;
|
|
191
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
192
|
+
var _b, data, store, dispatchEvent;
|
|
193
|
+
return tslib.__generator(this, function (_c) {
|
|
194
|
+
switch (_c.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
_b = this.props, data = _b.data, store = _b.store, dispatchEvent = _b.dispatchEvent;
|
|
197
|
+
if (store.fetching) {
|
|
198
|
+
return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
// 派发init事件,参数为初始化数据
|
|
201
|
+
return [4 /*yield*/, dispatchEvent('inited', object.createObject(data, tslib.__assign(tslib.__assign({}, value === null || value === void 0 ? void 0 : value.data), { responseData: (_a = value === null || value === void 0 ? void 0 : value.data) !== null && _a !== void 0 ? _a : {}, responseStatus: store.error ? 1 : 0, responseMsg: store.msg })))];
|
|
202
|
+
case 1:
|
|
203
|
+
// 派发init事件,参数为初始化数据
|
|
204
|
+
_c.sent();
|
|
205
|
+
return [2 /*return*/, value];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
185
210
|
Form.prototype.blockRouting = function () {
|
|
186
211
|
var store = this.props.store;
|
|
187
212
|
var _a = this.props, promptPageLeaveMessage = _a.promptPageLeaveMessage, promptPageLeave = _a.promptPageLeave;
|
|
@@ -198,11 +223,11 @@ var Form = /** @class */ (function (_super) {
|
|
|
198
223
|
};
|
|
199
224
|
Form.prototype.onInit = function () {
|
|
200
225
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
201
|
-
var _a, onInit, store, persistData, submitOnInit,
|
|
226
|
+
var _a, onInit, store, persistData, submitOnInit, data, initedAt, hooks;
|
|
202
227
|
return tslib.__generator(this, function (_b) {
|
|
203
228
|
switch (_b.label) {
|
|
204
229
|
case 0:
|
|
205
|
-
_a = this.props, onInit = _a.onInit, store = _a.store, persistData = _a.persistData, submitOnInit = _a.submitOnInit,
|
|
230
|
+
_a = this.props, onInit = _a.onInit, store = _a.store, persistData = _a.persistData, submitOnInit = _a.submitOnInit, _a.dispatchEvent;
|
|
206
231
|
if (!mobxStateTree.isAlive(store)) {
|
|
207
232
|
return [2 /*return*/];
|
|
208
233
|
}
|
|
@@ -227,12 +252,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
227
252
|
store.getLocalPersistData();
|
|
228
253
|
data = object.cloneObject(store.data);
|
|
229
254
|
}
|
|
230
|
-
|
|
231
|
-
case 2:
|
|
232
|
-
dispatcher = _b.sent();
|
|
233
|
-
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
234
|
-
onInit && onInit(data, this.props);
|
|
235
|
-
}
|
|
255
|
+
onInit && onInit(data, this.props);
|
|
236
256
|
submitOnInit &&
|
|
237
257
|
this.handleAction(undefined, {
|
|
238
258
|
type: 'submit'
|
|
@@ -267,12 +287,23 @@ var Form = /** @class */ (function (_super) {
|
|
|
267
287
|
return helper.until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); });
|
|
268
288
|
}
|
|
269
289
|
})
|
|
270
|
-
.then(function (result) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
290
|
+
.then(function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
291
|
+
return tslib.__generator(this, function (_a) {
|
|
292
|
+
switch (_a.label) {
|
|
293
|
+
case 0:
|
|
294
|
+
// 派发初始化接口请求完成事件
|
|
295
|
+
return [4 /*yield*/, this.dispatchInited(result)];
|
|
296
|
+
case 1:
|
|
297
|
+
// 派发初始化接口请求完成事件
|
|
298
|
+
_a.sent();
|
|
299
|
+
if (result === null || result === void 0 ? void 0 : result.ok) {
|
|
300
|
+
this.initInterval(result);
|
|
301
|
+
store.reset(undefined, false);
|
|
302
|
+
}
|
|
303
|
+
return [2 /*return*/];
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}); })
|
|
276
307
|
: store.reset(undefined, false);
|
|
277
308
|
};
|
|
278
309
|
Form.prototype.receive = function (values, name, replace) {
|
|
@@ -455,14 +486,15 @@ var Form = /** @class */ (function (_super) {
|
|
|
455
486
|
};
|
|
456
487
|
};
|
|
457
488
|
Form.prototype.handleAction = function (e, action, data, throwErrors, delegate) {
|
|
489
|
+
var _a, _b;
|
|
458
490
|
if (throwErrors === void 0) { throwErrors = false; }
|
|
459
491
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
460
|
-
var
|
|
492
|
+
var _c, store, onSubmit, api$1, asyncApi, finishedField, checkInterval, _d, saveSuccess, saveFailed, resetAfterSubmit, clearAfterSubmit, onAction, onSaved, onReset, onFinished, onFailed, redirect, reload, target, env, onChange, clearPersistDataAfterSubmit, trimValues, dispatchEvent, __, fields, validationRes, dispatcher, _e, dispatchEvent_1, onEvent, submitEvent, dispatcher;
|
|
461
493
|
var _this = this;
|
|
462
|
-
return tslib.__generator(this, function (
|
|
463
|
-
switch (
|
|
494
|
+
return tslib.__generator(this, function (_f) {
|
|
495
|
+
switch (_f.label) {
|
|
464
496
|
case 0:
|
|
465
|
-
|
|
497
|
+
_c = this.props, store = _c.store, onSubmit = _c.onSubmit, api$1 = _c.api, asyncApi = _c.asyncApi, finishedField = _c.finishedField, checkInterval = _c.checkInterval, _d = _c.messages, saveSuccess = _d.saveSuccess, saveFailed = _d.saveFailed, resetAfterSubmit = _c.resetAfterSubmit, clearAfterSubmit = _c.clearAfterSubmit, onAction = _c.onAction, onSaved = _c.onSaved, onReset = _c.onReset, onFinished = _c.onFinished, onFailed = _c.onFailed, redirect = _c.redirect, reload = _c.reload, target = _c.target, env = _c.env, onChange = _c.onChange, clearPersistDataAfterSubmit = _c.clearPersistDataAfterSubmit, trimValues = _c.trimValues, dispatchEvent = _c.dispatchEvent, __ = _c.translate;
|
|
466
498
|
// 做动作之前,先把数据同步一下。
|
|
467
499
|
this.flush();
|
|
468
500
|
if (trimValues) {
|
|
@@ -481,11 +513,11 @@ var Form = /** @class */ (function (_super) {
|
|
|
481
513
|
}); });
|
|
482
514
|
return [4 /*yield*/, store.validateFields(fields)];
|
|
483
515
|
case 1:
|
|
484
|
-
validationRes =
|
|
516
|
+
validationRes = _f.sent();
|
|
485
517
|
if (!!validationRes) return [3 /*break*/, 3];
|
|
486
518
|
return [4 /*yield*/, dispatchEvent('validateError', this.props.data)];
|
|
487
519
|
case 2:
|
|
488
|
-
dispatcher =
|
|
520
|
+
dispatcher = _f.sent();
|
|
489
521
|
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
490
522
|
env.notify('error', __('Form.validateFailed'));
|
|
491
523
|
}
|
|
@@ -494,147 +526,158 @@ var Form = /** @class */ (function (_super) {
|
|
|
494
526
|
case 3:
|
|
495
527
|
/** 重置validated状态,保证submit时触发表单中的校验项 */
|
|
496
528
|
store.clearErrors();
|
|
497
|
-
|
|
529
|
+
_f.label = 4;
|
|
498
530
|
case 4:
|
|
499
|
-
if (action.type === 'submit' ||
|
|
531
|
+
if (!(action.type === 'submit' ||
|
|
500
532
|
action.actionType === 'submit' ||
|
|
501
533
|
action.actionType === 'confirm' ||
|
|
502
534
|
action.actionType === 'reset-and-submit' ||
|
|
503
|
-
action.actionType === 'clear-and-submit')
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
dispatcher: dispatcher
|
|
561
|
-
}];
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
}); },
|
|
565
|
-
onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
566
|
-
var dispatcher;
|
|
567
|
-
return tslib.__generator(this, function (_a) {
|
|
568
|
-
switch (_a.label) {
|
|
569
|
-
case 0: return [4 /*yield*/, dispatchEvent('submitFail', object.createObject(this.props.data, { error: result }))];
|
|
570
|
-
case 1:
|
|
571
|
-
dispatcher = _a.sent();
|
|
535
|
+
action.actionType === 'clear-and-submit')) return [3 /*break*/, 6];
|
|
536
|
+
_e = this.props, dispatchEvent_1 = _e.dispatchEvent, onEvent = _e.onEvent;
|
|
537
|
+
submitEvent = (_b = (_a = onEvent === null || onEvent === void 0 ? void 0 : onEvent.submit) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.length;
|
|
538
|
+
return [4 /*yield*/, dispatchEvent_1('submit', this.props.data)];
|
|
539
|
+
case 5:
|
|
540
|
+
dispatcher = _f.sent();
|
|
541
|
+
if ((dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented) || submitEvent) {
|
|
542
|
+
return [2 /*return*/];
|
|
543
|
+
}
|
|
544
|
+
store.setCurrentAction(action);
|
|
545
|
+
if (action.actionType === 'reset-and-submit') {
|
|
546
|
+
store.reset(this.handleReset(action));
|
|
547
|
+
}
|
|
548
|
+
else if (action.actionType === 'clear-and-submit') {
|
|
549
|
+
store.clear(this.handleReset(action));
|
|
550
|
+
}
|
|
551
|
+
return [2 /*return*/, this.submit(function (values) {
|
|
552
|
+
var _a;
|
|
553
|
+
if (onSubmit && onSubmit(values, action) === false) {
|
|
554
|
+
return Promise.resolve(false);
|
|
555
|
+
}
|
|
556
|
+
// 走到这里代表校验成功了
|
|
557
|
+
dispatchEvent_1('validateSucc', _this.props.data);
|
|
558
|
+
if (target) {
|
|
559
|
+
_this.submitToTarget(Scoped.filterTarget(target, values), values);
|
|
560
|
+
dispatchEvent_1('submitSucc', object.createObject(_this.props.data, values));
|
|
561
|
+
}
|
|
562
|
+
else if (action.actionType === 'reload') {
|
|
563
|
+
action.target &&
|
|
564
|
+
_this.reloadTarget(Scoped.filterTarget(action.target, values), values);
|
|
565
|
+
}
|
|
566
|
+
else if (action.actionType === 'dialog') {
|
|
567
|
+
store.openDialog(data);
|
|
568
|
+
}
|
|
569
|
+
else if (action.actionType === 'drawer') {
|
|
570
|
+
store.openDrawer(data);
|
|
571
|
+
}
|
|
572
|
+
else if (api.isEffectiveApi(action.api || api$1, values)) {
|
|
573
|
+
var finnalAsyncApi_1 = action.asyncApi || asyncApi;
|
|
574
|
+
api.isEffectiveApi(finnalAsyncApi_1, store.data) &&
|
|
575
|
+
store.updateData((_a = {},
|
|
576
|
+
_a[finishedField || 'finished'] = false,
|
|
577
|
+
_a));
|
|
578
|
+
return store
|
|
579
|
+
.saveRemote(action.api || api$1, values, {
|
|
580
|
+
successMessage: saveSuccess,
|
|
581
|
+
errorMessage: saveFailed,
|
|
582
|
+
onSuccess: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
583
|
+
var dispatcher, cbResult;
|
|
584
|
+
var _this = this;
|
|
585
|
+
return tslib.__generator(this, function (_a) {
|
|
586
|
+
switch (_a.label) {
|
|
587
|
+
case 0: return [4 /*yield*/, dispatchEvent_1('submitSucc', object.createObject(this.props.data, { result: result }))];
|
|
588
|
+
case 1:
|
|
589
|
+
dispatcher = _a.sent();
|
|
590
|
+
if (!api.isEffectiveApi(finnalAsyncApi_1, store.data) ||
|
|
591
|
+
store.data[finishedField || 'finished']) {
|
|
572
592
|
return [2 /*return*/, {
|
|
593
|
+
cbResult: null,
|
|
573
594
|
dispatcher: dispatcher
|
|
574
595
|
}];
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
596
|
+
}
|
|
597
|
+
cbResult = helper.until(function () { return store.checkRemote(finnalAsyncApi_1, store.data); }, function (ret) { return ret && ret[finishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, checkInterval).then(function (value) {
|
|
598
|
+
// 派发asyncApiFinished事件
|
|
599
|
+
dispatchEvent_1('asyncApiFinished', store.data);
|
|
600
|
+
});
|
|
601
|
+
return [2 /*return*/, {
|
|
602
|
+
cbResult: cbResult,
|
|
603
|
+
dispatcher: dispatcher
|
|
604
|
+
}];
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}); },
|
|
608
|
+
onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
609
|
+
var dispatcher;
|
|
581
610
|
return tslib.__generator(this, function (_a) {
|
|
582
611
|
switch (_a.label) {
|
|
583
|
-
case 0:
|
|
584
|
-
onSaved && onSaved(values, response);
|
|
585
|
-
feedback = action.feedback || this.props.feedback;
|
|
586
|
-
if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
|
|
587
|
-
return [4 /*yield*/, this.openFeedback(feedback, store.data)];
|
|
612
|
+
case 0: return [4 /*yield*/, dispatchEvent_1('submitFail', object.createObject(this.props.data, { error: result }))];
|
|
588
613
|
case 1:
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
else if (feedback.skipRestOnConfirm && confirmed) {
|
|
595
|
-
throw new helper.SkipOperation();
|
|
596
|
-
}
|
|
597
|
-
_a.label = 2;
|
|
598
|
-
case 2: return [2 /*return*/];
|
|
614
|
+
dispatcher = _a.sent();
|
|
615
|
+
return [2 /*return*/, {
|
|
616
|
+
dispatcher: dispatcher
|
|
617
|
+
}];
|
|
599
618
|
}
|
|
600
619
|
});
|
|
601
|
-
}); }
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
620
|
+
}); }
|
|
621
|
+
})
|
|
622
|
+
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
623
|
+
var feedback, confirmed;
|
|
624
|
+
return tslib.__generator(this, function (_a) {
|
|
625
|
+
switch (_a.label) {
|
|
626
|
+
case 0:
|
|
627
|
+
onSaved && onSaved(values, response);
|
|
628
|
+
feedback = action.feedback || this.props.feedback;
|
|
629
|
+
if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
|
|
630
|
+
return [4 /*yield*/, this.openFeedback(feedback, store.data)];
|
|
631
|
+
case 1:
|
|
632
|
+
confirmed = _a.sent();
|
|
633
|
+
// 如果 feedback 配置了,取消就跳过原有逻辑。
|
|
634
|
+
if (feedback.skipRestOnCancel && !confirmed) {
|
|
635
|
+
throw new helper.SkipOperation();
|
|
636
|
+
}
|
|
637
|
+
else if (feedback.skipRestOnConfirm && confirmed) {
|
|
638
|
+
throw new helper.SkipOperation();
|
|
639
|
+
}
|
|
640
|
+
_a.label = 2;
|
|
641
|
+
case 2: return [2 /*return*/];
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
}); });
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
// type为submit,但是没有配api以及target时,只派发事件
|
|
648
|
+
dispatchEvent_1('submitSucc', object.createObject(_this.props.data, values));
|
|
649
|
+
}
|
|
650
|
+
return Promise.resolve(null);
|
|
651
|
+
})
|
|
652
|
+
.then(function (values) {
|
|
653
|
+
// 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
|
|
654
|
+
if (values === false) {
|
|
655
|
+
return store.data;
|
|
656
|
+
}
|
|
657
|
+
if (onFinished && onFinished(values, action) === false) {
|
|
628
658
|
return values;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
659
|
+
}
|
|
660
|
+
resetAfterSubmit && store.reset(_this.handleReset(action));
|
|
661
|
+
clearAfterSubmit && store.clear(_this.handleReset(action));
|
|
662
|
+
clearPersistDataAfterSubmit && store.clearLocalPersistData();
|
|
663
|
+
if (action.redirect || redirect) {
|
|
664
|
+
var finalRedirect = tpl.filter(action.redirect || redirect, store.data);
|
|
665
|
+
finalRedirect && env.jumpTo(finalRedirect, action);
|
|
666
|
+
}
|
|
667
|
+
else if (action.reload || reload) {
|
|
668
|
+
_this.reloadTarget(Scoped.filterTarget(action.reload || reload, store.data), store.data);
|
|
669
|
+
}
|
|
670
|
+
action.close && _this.closeTarget(action.close);
|
|
671
|
+
return values;
|
|
672
|
+
})
|
|
673
|
+
.catch(function (reason) {
|
|
674
|
+
onFailed && onFailed(reason, store.errors);
|
|
675
|
+
if (throwErrors) {
|
|
676
|
+
throw reason;
|
|
677
|
+
}
|
|
678
|
+
})];
|
|
679
|
+
case 6:
|
|
680
|
+
if (action.type === 'reset' || action.actionType === 'reset') {
|
|
638
681
|
store.setCurrentAction(action);
|
|
639
682
|
store.reset(onReset);
|
|
640
683
|
}
|
|
@@ -687,7 +730,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
687
730
|
redirect = action.redirect && tpl.filter(action.redirect, store.data);
|
|
688
731
|
redirect && env.jumpTo(redirect, action);
|
|
689
732
|
action.reload &&
|
|
690
|
-
this.reloadTarget(
|
|
733
|
+
this.reloadTarget(Scoped.filterTarget(action.reload, store.data), store.data);
|
|
691
734
|
action.close && this.closeTarget(action.close);
|
|
692
735
|
return [2 /*return*/];
|
|
693
736
|
}
|
|
@@ -703,18 +746,19 @@ var Form = /** @class */ (function (_super) {
|
|
|
703
746
|
else if (action.actionType === 'reload') {
|
|
704
747
|
store.setCurrentAction(action);
|
|
705
748
|
if (action.target) {
|
|
706
|
-
this.reloadTarget(
|
|
749
|
+
this.reloadTarget(Scoped.filterTarget(action.target, data), data);
|
|
707
750
|
}
|
|
708
751
|
else {
|
|
709
752
|
this.receive(data);
|
|
710
753
|
}
|
|
711
|
-
// action.target && this.reloadTarget(action.target, data);
|
|
754
|
+
// action.target && this.reloadTarget(filterTarget(action.target, data), data);
|
|
712
755
|
}
|
|
713
756
|
else if (onAction) {
|
|
714
757
|
// 不识别的丢给上层去处理。
|
|
715
758
|
return [2 /*return*/, onAction(e, action, data, throwErrors, delegate || this.context)];
|
|
716
759
|
}
|
|
717
|
-
|
|
760
|
+
_f.label = 7;
|
|
761
|
+
case 7: return [2 /*return*/];
|
|
718
762
|
}
|
|
719
763
|
});
|
|
720
764
|
});
|
|
@@ -1062,33 +1106,25 @@ var FormRenderer = /** @class */ (function (_super) {
|
|
|
1062
1106
|
return this.handleAction(undefined, action, data, throwErrors);
|
|
1063
1107
|
};
|
|
1064
1108
|
FormRenderer.prototype.handleAction = function (e, action, ctx, throwErrors, delegate) {
|
|
1065
|
-
var _a, _b;
|
|
1066
1109
|
if (throwErrors === void 0) { throwErrors = false; }
|
|
1067
1110
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1068
|
-
var
|
|
1069
|
-
return tslib.__generator(this, function (
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
return
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
target.doAction &&
|
|
1086
|
-
target.doAction(tslib.__assign(tslib.__assign({}, action), { target: undefined }), ctx, throwErrors));
|
|
1087
|
-
}))];
|
|
1088
|
-
}
|
|
1089
|
-
else {
|
|
1090
|
-
return [2 /*return*/, _super.prototype.handleAction.call(this, e, action, ctx, throwErrors, delegate)];
|
|
1091
|
-
}
|
|
1111
|
+
var scoped_1;
|
|
1112
|
+
return tslib.__generator(this, function (_a) {
|
|
1113
|
+
// 禁用了不要做任何动作。@先注释掉,会引起其他问题
|
|
1114
|
+
// if (this.props.disabled) {
|
|
1115
|
+
// return;
|
|
1116
|
+
// }
|
|
1117
|
+
if (action.target && action.actionType !== 'reload') {
|
|
1118
|
+
scoped_1 = this.context;
|
|
1119
|
+
return [2 /*return*/, Promise.all(action.target.split(',').map(function (name) {
|
|
1120
|
+
var target = scoped_1.getComponentByName(name);
|
|
1121
|
+
return (target &&
|
|
1122
|
+
target.doAction &&
|
|
1123
|
+
target.doAction(tslib.__assign(tslib.__assign({}, action), { target: undefined }), ctx, throwErrors));
|
|
1124
|
+
}))];
|
|
1125
|
+
}
|
|
1126
|
+
else {
|
|
1127
|
+
return [2 /*return*/, _super.prototype.handleAction.call(this, e, action, ctx, throwErrors, delegate)];
|
|
1092
1128
|
}
|
|
1093
1129
|
});
|
|
1094
1130
|
});
|