amis-core 1.0.0-beta.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/dist/Root.js +94 -0
- package/dist/RootRenderer.js +288 -0
- package/dist/SchemaRenderer.js +323 -0
- package/dist/Scoped.js +252 -0
- package/dist/WithRootStore.js +44 -0
- package/dist/WithStore.js +179 -0
- package/dist/__tests__/compat.test.d.ts +1 -0
- package/dist/__tests__/factory.test.d.ts +1 -0
- package/dist/__tests__/filter.test.d.ts +1 -0
- package/dist/__tests__/helper.d.ts +13 -0
- package/dist/__tests__/tokenize.test.d.ts +1 -0
- package/dist/actions/Action.js +119 -0
- package/dist/actions/AjaxAction.js +96 -0
- package/dist/actions/BreakAction.js +35 -0
- package/dist/actions/BroadcastAction.js +49 -0
- package/dist/actions/CmptAction.js +60 -0
- package/dist/actions/ContinueAction.js +35 -0
- package/dist/actions/CopyAction.js +43 -0
- package/dist/actions/CustomAction.js +49 -0
- package/dist/actions/DialogAction.js +104 -0
- package/dist/actions/DrawerAction.js +66 -0
- package/dist/actions/EmailAction.js +48 -0
- package/dist/actions/LinkAction.js +52 -0
- package/dist/actions/LoopAction.js +107 -0
- package/dist/actions/PageAction.js +80 -0
- package/dist/actions/ParallelAction.js +40 -0
- package/dist/actions/SwitchAction.js +52 -0
- package/dist/actions/ToastAction.js +35 -0
- package/dist/components/LazyComponent.js +99 -0
- package/dist/env.js +20 -0
- package/dist/envOverwrite.js +43 -0
- package/dist/factory.js +308 -0
- package/dist/index.js +218 -0
- package/dist/index2.js +255 -0
- package/dist/locale.js +114 -0
- package/dist/renderers/Form.js +1162 -0
- package/dist/renderers/Item.js +636 -0
- package/dist/renderers/Options.js +881 -0
- package/dist/renderers/Placeholder.js +31 -0
- package/dist/renderers/builtin.js +27 -0
- package/dist/renderers/wrapControl.js +507 -0
- package/dist/src/Root.d.ts +37 -0
- package/dist/src/RootRenderer.d.ts +27 -0
- package/dist/src/SchemaRenderer.d.ts +37 -0
- package/dist/src/Scoped.d.ts +38 -0
- package/dist/src/WithRootStore.d.ts +737 -0
- package/dist/src/WithStore.d.ts +5 -0
- package/dist/src/actions/Action.d.ts +38 -0
- package/dist/src/actions/AjaxAction.d.ts +25 -0
- package/dist/src/actions/BreakAction.d.ts +15 -0
- package/dist/src/actions/BroadcastAction.d.ts +16 -0
- package/dist/src/actions/CmptAction.d.ts +20 -0
- package/dist/src/actions/ContinueAction.d.ts +15 -0
- package/dist/src/actions/CopyAction.d.ts +20 -0
- package/dist/src/actions/CustomAction.d.ts +17 -0
- package/dist/src/actions/Decorators.d.ts +25 -0
- package/dist/src/actions/DialogAction.d.ts +57 -0
- package/dist/src/actions/DrawerAction.d.ts +30 -0
- package/dist/src/actions/EmailAction.d.ts +23 -0
- package/dist/src/actions/LinkAction.d.ts +24 -0
- package/dist/src/actions/LoopAction.d.ts +19 -0
- package/dist/src/actions/PageAction.d.ts +39 -0
- package/dist/src/actions/ParallelAction.d.ts +8 -0
- package/dist/src/actions/SwitchAction.d.ts +11 -0
- package/dist/src/actions/ToastAction.d.ts +19 -0
- package/dist/src/actions/index.d.ts +21 -0
- package/dist/src/components/LazyComponent.d.ts +32 -0
- package/dist/src/env.d.ts +172 -0
- package/dist/src/envOverwrite.d.ts +4 -0
- package/dist/src/factory.d.ts +78 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/locale.d.ts +82 -0
- package/dist/src/renderers/Form.d.ts +352 -0
- package/dist/src/renderers/Item.d.ts +795 -0
- package/dist/src/renderers/Options.d.ts +150 -0
- package/dist/src/renderers/Placeholder.d.ts +6 -0
- package/dist/src/renderers/builtin.d.ts +1 -0
- package/dist/src/renderers/wrapControl.d.ts +446 -0
- package/dist/src/schema.d.ts +369 -0
- package/dist/src/store/app.d.ts +89 -0
- package/dist/src/store/combo.d.ts +8504 -0
- package/dist/src/store/crud.d.ts +124 -0
- package/dist/src/store/form.d.ts +3394 -0
- package/dist/src/store/formItem.d.ts +130 -0
- package/dist/src/store/iRenderer.d.ts +46 -0
- package/dist/src/store/index.d.ts +105 -0
- package/dist/src/store/list.d.ts +270 -0
- package/dist/src/store/manager.d.ts +115 -0
- package/dist/src/store/modal.d.ts +84 -0
- package/dist/src/store/node.d.ts +22 -0
- package/dist/src/store/pagination.d.ts +58 -0
- package/dist/src/store/root.d.ts +79 -0
- package/dist/src/store/service.d.ts +71 -0
- package/dist/src/store/table-v2.d.ts +309 -0
- package/dist/src/store/table.d.ts +8334 -0
- package/dist/src/theme.d.ts +83 -0
- package/dist/src/types.d.ts +217 -0
- package/dist/src/utils/Animation.d.ts +22 -0
- package/dist/src/utils/ColorScale.d.ts +19 -0
- package/dist/src/utils/DataSchema.d.ts +25 -0
- package/dist/src/utils/DataScope.d.ts +23 -0
- package/dist/src/utils/RootClose.d.ts +4 -0
- package/dist/src/utils/SimpleMap.d.ts +8 -0
- package/dist/src/utils/api.d.ts +27 -0
- package/dist/src/utils/attachmentAdpator.d.ts +7 -0
- package/dist/src/utils/autobind.d.ts +7 -0
- package/dist/src/utils/columnsSplit.d.ts +1 -0
- package/dist/src/utils/dataMapping.d.ts +3 -0
- package/dist/src/utils/date.d.ts +4 -0
- package/dist/src/utils/debug.d.ts +26 -0
- package/dist/src/utils/dom.d.ts +13 -0
- package/dist/src/utils/errors.d.ts +6 -0
- package/dist/src/utils/escapeHtml.d.ts +1 -0
- package/dist/src/utils/filter-schema.d.ts +12 -0
- package/dist/src/utils/filter.d.ts +1 -0
- package/dist/src/utils/formatDuration.d.ts +1 -0
- package/dist/src/utils/formula.d.ts +16 -0
- package/dist/src/utils/getVariable.d.ts +3 -0
- package/dist/src/utils/grammar.d.ts +4 -0
- package/dist/src/utils/handleAction.d.ts +6 -0
- package/dist/src/utils/helper.d.ts +286 -0
- package/dist/src/utils/icon.d.ts +12 -0
- package/dist/src/utils/image.d.ts +17 -0
- package/dist/src/utils/index.d.ts +12 -0
- package/dist/src/utils/isPureVariable.d.ts +1 -0
- package/dist/src/utils/json-schema-2-amis-schema.d.ts +6 -0
- package/dist/src/utils/keyToPath.d.ts +6 -0
- package/dist/src/utils/makeSorter.d.ts +1 -0
- package/dist/src/utils/markdown.d.ts +5 -0
- package/dist/src/utils/normalizeLink.d.ts +1 -0
- package/dist/src/utils/normalizeOptions.d.ts +7 -0
- package/dist/src/utils/object.d.ts +15 -0
- package/dist/src/utils/offset.d.ts +14 -0
- package/dist/src/utils/offsetParent.d.ts +4 -0
- package/dist/src/utils/optionValueCompare.d.ts +3 -0
- package/dist/src/utils/position.d.ts +15 -0
- package/dist/src/utils/prettyBytes.d.ts +1 -0
- package/dist/src/utils/renderer-event.d.ts +44 -0
- package/dist/src/utils/replaceText.d.ts +6 -0
- package/dist/src/utils/resize-sensor.d.ts +6 -0
- package/dist/src/utils/resolveVariable.d.ts +1 -0
- package/dist/src/utils/resolveVariableAndFilter.d.ts +1 -0
- package/dist/src/utils/scrollPosition.d.ts +6 -0
- package/dist/src/utils/string2regExp.d.ts +1 -0
- package/dist/src/utils/stripNumber.d.ts +1 -0
- package/dist/src/utils/style.d.ts +10 -0
- package/dist/src/utils/tokenize.d.ts +1 -0
- package/dist/src/utils/tpl-builtin.d.ts +18 -0
- package/dist/src/utils/tpl-lodash.d.ts +4 -0
- package/dist/src/utils/tpl.d.ts +11 -0
- package/dist/src/utils/validations.d.ts +39 -0
- package/dist/store/app.js +190 -0
- package/dist/store/combo.js +154 -0
- package/dist/store/crud.js +413 -0
- package/dist/store/form.js +579 -0
- package/dist/store/formItem.js +846 -0
- package/dist/store/iRenderer.js +189 -0
- package/dist/store/index.js +103 -0
- package/dist/store/list.js +248 -0
- package/dist/store/manager.js +56 -0
- package/dist/store/modal.js +54 -0
- package/dist/store/node.js +93 -0
- package/dist/store/pagination.js +60 -0
- package/dist/store/root.js +45 -0
- package/dist/store/service.js +415 -0
- package/dist/store/table-v2.js +471 -0
- package/dist/store/table.js +1105 -0
- package/dist/theme.js +93 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/Animation.js +290 -0
- package/dist/utils/DataSchema.js +120 -0
- package/dist/utils/DataScope.js +151 -0
- package/dist/utils/SimpleMap.js +46 -0
- package/dist/utils/api.js +555 -0
- package/dist/utils/autobind.js +94 -0
- package/dist/utils/dataMapping.js +136 -0
- package/dist/utils/date.js +90 -0
- package/dist/utils/debug.js +343 -0
- package/dist/utils/errors.js +23 -0
- package/dist/utils/escapeHtml.js +24 -0
- package/dist/utils/filter-schema.js +75 -0
- package/dist/utils/filter.js +481 -0
- package/dist/utils/formatDuration.js +27 -0
- package/dist/utils/formula.js +165 -0
- package/dist/utils/getVariable.js +29 -0
- package/dist/utils/grammar.js +54 -0
- package/dist/utils/helper.js +1283 -0
- package/dist/utils/isPureVariable.js +16 -0
- package/dist/utils/keyToPath.js +34 -0
- package/dist/utils/makeSorter.js +30 -0
- package/dist/utils/normalizeLink.js +47 -0
- package/dist/utils/normalizeOptions.js +92 -0
- package/dist/utils/object.js +156 -0
- package/dist/utils/offset.js +36 -0
- package/dist/utils/offsetParent.js +27 -0
- package/dist/utils/optionValueCompare.js +25 -0
- package/dist/utils/position.js +50 -0
- package/dist/utils/prettyBytes.js +28 -0
- package/dist/utils/renderer-event.js +131 -0
- package/dist/utils/replaceText.js +35 -0
- package/dist/utils/resize-sensor.js +177 -0
- package/dist/utils/resolveVariable.js +39 -0
- package/dist/utils/resolveVariableAndFilter.js +37 -0
- package/dist/utils/string2regExp.js +18 -0
- package/dist/utils/stripNumber.js +20 -0
- package/dist/utils/tokenize.js +33 -0
- package/dist/utils/tpl-builtin.js +71 -0
- package/dist/utils/tpl-lodash.js +71 -0
- package/dist/utils/tpl.js +140 -0
- package/dist/utils/validations.js +377 -0
- package/package.json +121 -0
|
@@ -0,0 +1,1162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v1.0.0-beta.0
|
|
3
|
+
* Copyright 2018-2022 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var React = require('react');
|
|
12
|
+
var factory = require('../factory.js');
|
|
13
|
+
var form = require('../store/form.js');
|
|
14
|
+
var tpl = require('../utils/tpl.js');
|
|
15
|
+
var cx = require('classnames');
|
|
16
|
+
var filterSchema = require('../utils/filter-schema.js');
|
|
17
|
+
var helper = require('../utils/helper.js');
|
|
18
|
+
var debouce = require('lodash/debounce');
|
|
19
|
+
var flatten = require('lodash/flatten');
|
|
20
|
+
var find = require('lodash/find');
|
|
21
|
+
var Scoped = require('../Scoped.js');
|
|
22
|
+
require('amis-formula');
|
|
23
|
+
require('moment');
|
|
24
|
+
var object = require('../utils/object.js');
|
|
25
|
+
var getVariable = require('../utils/getVariable.js');
|
|
26
|
+
var dataMapping = require('../utils/dataMapping.js');
|
|
27
|
+
require('../utils/filter.js');
|
|
28
|
+
var api = require('../utils/api.js');
|
|
29
|
+
var LazyComponent = require('../components/LazyComponent.js');
|
|
30
|
+
var mobxStateTree = require('mobx-state-tree');
|
|
31
|
+
|
|
32
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
33
|
+
|
|
34
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
35
|
+
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
36
|
+
var debouce__default = /*#__PURE__*/_interopDefaultLegacy(debouce);
|
|
37
|
+
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
38
|
+
var find__default = /*#__PURE__*/_interopDefaultLegacy(find);
|
|
39
|
+
|
|
40
|
+
var Form = /** @class */ (function (_super) {
|
|
41
|
+
tslib.__extends(Form, _super);
|
|
42
|
+
function Form(props) {
|
|
43
|
+
var _this = _super.call(this, props) || this;
|
|
44
|
+
_this.hooks = {};
|
|
45
|
+
_this.shouldLoadInitApi = false;
|
|
46
|
+
_this.lazyEmitChange = debouce__default["default"](_this.emitChange.bind(_this), 250, {
|
|
47
|
+
trailing: true,
|
|
48
|
+
leading: false
|
|
49
|
+
});
|
|
50
|
+
_this.onInit = _this.onInit.bind(_this);
|
|
51
|
+
_this.handleAction = _this.handleAction.bind(_this);
|
|
52
|
+
_this.handleQuery = _this.handleQuery.bind(_this);
|
|
53
|
+
_this.handleChange = _this.handleChange.bind(_this);
|
|
54
|
+
_this.handleDialogConfirm = _this.handleDialogConfirm.bind(_this);
|
|
55
|
+
_this.handleDialogClose = _this.handleDialogClose.bind(_this);
|
|
56
|
+
_this.handleDrawerConfirm = _this.handleDrawerConfirm.bind(_this);
|
|
57
|
+
_this.handleDrawerClose = _this.handleDrawerClose.bind(_this);
|
|
58
|
+
_this.handleFormSubmit = _this.handleFormSubmit.bind(_this);
|
|
59
|
+
_this.validate = _this.validate.bind(_this);
|
|
60
|
+
_this.submit = _this.submit.bind(_this);
|
|
61
|
+
_this.addHook = _this.addHook.bind(_this);
|
|
62
|
+
_this.removeHook = _this.removeHook.bind(_this);
|
|
63
|
+
_this.emitChange = _this.emitChange.bind(_this);
|
|
64
|
+
_this.handleBulkChange = _this.handleBulkChange.bind(_this);
|
|
65
|
+
_this.renderFormItems = _this.renderFormItems.bind(_this);
|
|
66
|
+
_this.reload = _this.reload.bind(_this);
|
|
67
|
+
_this.silentReload = _this.silentReload.bind(_this);
|
|
68
|
+
_this.initInterval = _this.initInterval.bind(_this);
|
|
69
|
+
_this.blockRouting = _this.blockRouting.bind(_this);
|
|
70
|
+
_this.beforePageUnload = _this.beforePageUnload.bind(_this);
|
|
71
|
+
var store = props.store, canAccessSuperData = props.canAccessSuperData, persistData = props.persistData, simpleMode = props.simpleMode;
|
|
72
|
+
store.setCanAccessSuperData(canAccessSuperData !== false);
|
|
73
|
+
store.setPersistData(persistData);
|
|
74
|
+
if (simpleMode) {
|
|
75
|
+
store.setInited(true);
|
|
76
|
+
}
|
|
77
|
+
if (store &&
|
|
78
|
+
store.parentStore &&
|
|
79
|
+
store.parentStore.storeType === 'ComboStore') {
|
|
80
|
+
var combo = store.parentStore;
|
|
81
|
+
combo.addForm(store);
|
|
82
|
+
combo.forms.forEach(function (form) {
|
|
83
|
+
return form.items.forEach(function (item) { return item.unique && item.syncOptions(undefined, form.data); });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return _this;
|
|
87
|
+
}
|
|
88
|
+
Form.prototype.componentDidMount = function () {
|
|
89
|
+
var _this = this;
|
|
90
|
+
var _a, _b;
|
|
91
|
+
var _c = this.props, initApi = _c.initApi, initFetch = _c.initFetch, initFetchOn = _c.initFetchOn, initAsyncApi = _c.initAsyncApi, initFinishedField = _c.initFinishedField, initCheckInterval = _c.initCheckInterval, store = _c.store, _d = _c.messages, fetchSuccess = _d.fetchSuccess, fetchFailed = _d.fetchFailed, onValidate = _c.onValidate, promptPageLeave = _c.promptPageLeave, env = _c.env, rules = _c.rules;
|
|
92
|
+
this.mounted = true;
|
|
93
|
+
if (onValidate) {
|
|
94
|
+
var finalValidate_1 = helper.promisify(onValidate);
|
|
95
|
+
this.disposeOnValidate = this.addHook(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
96
|
+
var result;
|
|
97
|
+
return tslib.__generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, finalValidate_1(store.data, store)];
|
|
100
|
+
case 1:
|
|
101
|
+
result = _a.sent();
|
|
102
|
+
if (result && object.isObject(result)) {
|
|
103
|
+
Object.keys(result).forEach(function (key) {
|
|
104
|
+
var msg = result[key];
|
|
105
|
+
var items = store.getItemsByPath(key);
|
|
106
|
+
// 没有找到
|
|
107
|
+
if (!Array.isArray(items) || !items.length) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// 在setError之前,提前把残留的error信息清除掉,否则每次onValidate后都会一直把报错 append 上去
|
|
111
|
+
items.forEach(function (item) { return item.clearError(); });
|
|
112
|
+
if (msg) {
|
|
113
|
+
msg = Array.isArray(msg) ? msg : [msg];
|
|
114
|
+
items.forEach(function (item) { return item.addError(msg); });
|
|
115
|
+
}
|
|
116
|
+
delete result[key];
|
|
117
|
+
});
|
|
118
|
+
helper.isEmpty(result)
|
|
119
|
+
? store.clearRestError()
|
|
120
|
+
: store.setRestError(Object.keys(result).map(function (key) { return result[key]; }));
|
|
121
|
+
}
|
|
122
|
+
return [2 /*return*/];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}); });
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(rules) && rules.length) {
|
|
128
|
+
this.disposeRulesValidate = this.addHook(function () {
|
|
129
|
+
if (!store.valid) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
rules.forEach(function (item) {
|
|
133
|
+
return !tpl.evalExpression(item.rule, store.data) &&
|
|
134
|
+
store.addRestError(item.message, item.name);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (api.isEffectiveApi(initApi, store.data, initFetch, initFetchOn)) {
|
|
139
|
+
store
|
|
140
|
+
.fetchInitData(initApi, store.data, {
|
|
141
|
+
successMessage: fetchSuccess,
|
|
142
|
+
errorMessage: fetchFailed,
|
|
143
|
+
onSuccess: function () {
|
|
144
|
+
if (!api.isEffectiveApi(initAsyncApi, store.data) ||
|
|
145
|
+
store.data[initFinishedField || 'finished']) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
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
|
+
})
|
|
151
|
+
.then(this.initInterval)
|
|
152
|
+
.then(this.onInit);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
setTimeout(this.onInit.bind(this), 4);
|
|
156
|
+
}
|
|
157
|
+
if (promptPageLeave) {
|
|
158
|
+
window.addEventListener('beforeunload', this.beforePageUnload);
|
|
159
|
+
this.unBlockRouting = (_b = (_a = env.blockRouting) === null || _a === void 0 ? void 0 : _a.call(env, this.blockRouting)) !== null && _b !== void 0 ? _b : undefined;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
Form.prototype.componentDidUpdate = function (prevProps) {
|
|
163
|
+
var props = this.props;
|
|
164
|
+
var store = props.store;
|
|
165
|
+
if (api.isApiOutdated(prevProps.initApi, props.initApi, prevProps.data, props.data)) {
|
|
166
|
+
var fetchSuccess = props.fetchSuccess, fetchFailed = props.fetchFailed;
|
|
167
|
+
store[store.hasRemoteData ? 'fetchData' : 'fetchInitData'](props.initApi, store.data, {
|
|
168
|
+
successMessage: fetchSuccess,
|
|
169
|
+
errorMessage: fetchFailed
|
|
170
|
+
}).then(this.initInterval);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
Form.prototype.componentWillUnmount = function () {
|
|
174
|
+
var _a;
|
|
175
|
+
this.mounted = false;
|
|
176
|
+
clearTimeout(this.timer);
|
|
177
|
+
// this.lazyHandleChange.flush();
|
|
178
|
+
this.lazyEmitChange.cancel();
|
|
179
|
+
this.asyncCancel && this.asyncCancel();
|
|
180
|
+
this.disposeOnValidate && this.disposeOnValidate();
|
|
181
|
+
this.disposeRulesValidate && this.disposeRulesValidate();
|
|
182
|
+
window.removeEventListener('beforeunload', this.beforePageUnload);
|
|
183
|
+
(_a = this.unBlockRouting) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
184
|
+
};
|
|
185
|
+
Form.prototype.blockRouting = function () {
|
|
186
|
+
var store = this.props.store;
|
|
187
|
+
var _a = this.props, promptPageLeaveMessage = _a.promptPageLeaveMessage, promptPageLeave = _a.promptPageLeave;
|
|
188
|
+
if (promptPageLeave && store.modified) {
|
|
189
|
+
return promptPageLeaveMessage || '新的修改没有保存,确认要离开?';
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
Form.prototype.beforePageUnload = function (e) {
|
|
193
|
+
var blocked = this.blockRouting();
|
|
194
|
+
if (blocked) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
e.returnValue = '';
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
Form.prototype.onInit = function () {
|
|
200
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var _a, onInit, store, persistData, submitOnInit, dispatchEvent, data, initedAt, hooks, dispatcher;
|
|
202
|
+
return tslib.__generator(this, function (_b) {
|
|
203
|
+
switch (_b.label) {
|
|
204
|
+
case 0:
|
|
205
|
+
_a = this.props, onInit = _a.onInit, store = _a.store, persistData = _a.persistData, submitOnInit = _a.submitOnInit, dispatchEvent = _a.dispatchEvent;
|
|
206
|
+
if (!mobxStateTree.isAlive(store)) {
|
|
207
|
+
return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
data = object.cloneObject(store.data);
|
|
210
|
+
initedAt = store.initedAt;
|
|
211
|
+
store.setInited(true);
|
|
212
|
+
hooks = this.hooks['init'] || [];
|
|
213
|
+
return [4 /*yield*/, Promise.all(hooks.map(function (hook) { return hook(data); }))];
|
|
214
|
+
case 1:
|
|
215
|
+
_b.sent();
|
|
216
|
+
if (!mobxStateTree.isAlive(store)) {
|
|
217
|
+
return [2 /*return*/];
|
|
218
|
+
}
|
|
219
|
+
if (store.initedAt !== initedAt) {
|
|
220
|
+
// 说明,之前的数据已经失效了。
|
|
221
|
+
// 比如 combo 一开始设置了初始值,然后 form 的 initApi 又返回了新的值。
|
|
222
|
+
// 这个时候 store 的数据应该已经 init 了新的值。但是 data 还是老的,这个时候
|
|
223
|
+
// onInit 出去就是错误的。
|
|
224
|
+
data = tslib.__assign(tslib.__assign({}, data), store.data);
|
|
225
|
+
}
|
|
226
|
+
if (persistData) {
|
|
227
|
+
store.getLocalPersistData();
|
|
228
|
+
data = object.cloneObject(store.data);
|
|
229
|
+
}
|
|
230
|
+
return [4 /*yield*/, dispatchEvent('inited', object.createObject(this.props.data, data))];
|
|
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
|
+
}
|
|
236
|
+
submitOnInit &&
|
|
237
|
+
this.handleAction(undefined, {
|
|
238
|
+
type: 'submit'
|
|
239
|
+
}, store.data);
|
|
240
|
+
return [2 /*return*/];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
Form.prototype.reload = function (subPath, query, ctx, silent) {
|
|
246
|
+
var _a;
|
|
247
|
+
var _this = this;
|
|
248
|
+
if (query) {
|
|
249
|
+
return this.receive(query);
|
|
250
|
+
}
|
|
251
|
+
var _b = this.props, store = _b.store, initApi = _b.initApi, initAsyncApi = _b.initAsyncApi, initFinishedField = _b.initFinishedField, _c = _b.messages, fetchSuccess = _c.fetchSuccess, fetchFailed = _c.fetchFailed;
|
|
252
|
+
api.isEffectiveApi(initAsyncApi, store.data) &&
|
|
253
|
+
store.updateData((_a = {},
|
|
254
|
+
_a[initFinishedField || 'finished'] = false,
|
|
255
|
+
_a));
|
|
256
|
+
api.isEffectiveApi(initApi, store.data)
|
|
257
|
+
? store
|
|
258
|
+
.fetchInitData(initApi, store.data, {
|
|
259
|
+
successMessage: fetchSuccess,
|
|
260
|
+
errorMessage: fetchFailed,
|
|
261
|
+
silent: silent,
|
|
262
|
+
onSuccess: function () {
|
|
263
|
+
if (!api.isEffectiveApi(initAsyncApi, store.data) ||
|
|
264
|
+
store.data[initFinishedField || 'finished']) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
return helper.until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); });
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
.then(function (result) {
|
|
271
|
+
if (result === null || result === void 0 ? void 0 : result.ok) {
|
|
272
|
+
_this.initInterval(result);
|
|
273
|
+
store.reset(undefined, false);
|
|
274
|
+
}
|
|
275
|
+
})
|
|
276
|
+
: store.reset(undefined, false);
|
|
277
|
+
};
|
|
278
|
+
Form.prototype.receive = function (values) {
|
|
279
|
+
var store = this.props.store;
|
|
280
|
+
store.updateData(values);
|
|
281
|
+
this.reload();
|
|
282
|
+
};
|
|
283
|
+
Form.prototype.silentReload = function (target, query) {
|
|
284
|
+
this.reload(target, query, undefined, true);
|
|
285
|
+
};
|
|
286
|
+
Form.prototype.initInterval = function (value) {
|
|
287
|
+
var _a = this.props, interval = _a.interval, silentPolling = _a.silentPolling, stopAutoRefreshWhen = _a.stopAutoRefreshWhen, data = _a.data;
|
|
288
|
+
clearTimeout(this.timer);
|
|
289
|
+
interval &&
|
|
290
|
+
this.mounted &&
|
|
291
|
+
(!stopAutoRefreshWhen || !tpl.evalExpression(stopAutoRefreshWhen, data)) &&
|
|
292
|
+
(this.timer = setTimeout(silentPolling ? this.silentReload : this.reload, Math.max(interval, 1000)));
|
|
293
|
+
return value;
|
|
294
|
+
};
|
|
295
|
+
Form.prototype.isValidated = function () {
|
|
296
|
+
return this.props.store.validated;
|
|
297
|
+
};
|
|
298
|
+
Form.prototype.validate = function (forceValidate) {
|
|
299
|
+
var _a = this.props, store = _a.store, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
300
|
+
this.flush();
|
|
301
|
+
return store
|
|
302
|
+
.validate(this.hooks['validate'] || [], forceValidate)
|
|
303
|
+
.then(function (result) {
|
|
304
|
+
if (result) {
|
|
305
|
+
dispatchEvent('validateSucc', data);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
dispatchEvent('validateError', data);
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
Form.prototype.clearErrors = function () {
|
|
314
|
+
var store = this.props.store;
|
|
315
|
+
return store.clearErrors();
|
|
316
|
+
};
|
|
317
|
+
Form.prototype.getValues = function () {
|
|
318
|
+
var store = this.props.store;
|
|
319
|
+
this.flush();
|
|
320
|
+
return store.data;
|
|
321
|
+
};
|
|
322
|
+
Form.prototype.setValues = function (value) {
|
|
323
|
+
var store = this.props.store;
|
|
324
|
+
this.flush();
|
|
325
|
+
store.setValues(value);
|
|
326
|
+
};
|
|
327
|
+
Form.prototype.submit = function (fn) {
|
|
328
|
+
var _a = this.props, store = _a.store, messages = _a.messages, __ = _a.translate, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
329
|
+
this.flush();
|
|
330
|
+
var validateErrCb = function () { return dispatchEvent('validateError', data); };
|
|
331
|
+
return store.submit(fn, this.hooks['validate'] || [], __(messages && messages.validateFailed), validateErrCb);
|
|
332
|
+
};
|
|
333
|
+
// 如果开启了 lazyChange,需要一个 flush 方法把队列中值应用上。
|
|
334
|
+
Form.prototype.flush = function () {
|
|
335
|
+
var hooks = this.hooks['flush'] || [];
|
|
336
|
+
hooks.forEach(function (fn) { return fn(); });
|
|
337
|
+
this.lazyEmitChange.flush();
|
|
338
|
+
};
|
|
339
|
+
Form.prototype.reset = function () {
|
|
340
|
+
var _a = this.props, store = _a.store, onReset = _a.onReset;
|
|
341
|
+
store.reset(onReset);
|
|
342
|
+
};
|
|
343
|
+
Form.prototype.addHook = function (fn, type) {
|
|
344
|
+
var _this = this;
|
|
345
|
+
if (type === void 0) { type = 'validate'; }
|
|
346
|
+
this.hooks[type] = this.hooks[type] || [];
|
|
347
|
+
this.hooks[type].push(type === 'flush' ? fn : helper.promisify(fn));
|
|
348
|
+
return function () {
|
|
349
|
+
_this.removeHook(fn, type);
|
|
350
|
+
fn = helper.noop;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
Form.prototype.removeHook = function (fn, type) {
|
|
354
|
+
if (type === void 0) { type = 'validate'; }
|
|
355
|
+
var hooks = this.hooks[type];
|
|
356
|
+
if (!hooks) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
for (var i = 0, len = hooks.length; i < len; i++) {
|
|
360
|
+
var hook = hooks[i];
|
|
361
|
+
if (hook === fn || hook.raw === fn) {
|
|
362
|
+
hooks.splice(i, 1);
|
|
363
|
+
len--;
|
|
364
|
+
i--;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
Form.prototype.handleChange = function (value, name, submit, changePristine) {
|
|
369
|
+
if (changePristine === void 0) { changePristine = false; }
|
|
370
|
+
var _a = this.props, store = _a.store, formLazyChange = _a.formLazyChange;
|
|
371
|
+
if (typeof name !== 'string') {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
store.changeValue(name, value, changePristine);
|
|
375
|
+
if (!changePristine) {
|
|
376
|
+
(formLazyChange === false ? this.emitChange : this.lazyEmitChange)(submit);
|
|
377
|
+
}
|
|
378
|
+
if (store.persistData && store.inited) {
|
|
379
|
+
store.setLocalPersistData();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
Form.prototype.formItemDispatchEvent = function (dispatchEvent) {
|
|
383
|
+
return function (type, data) {
|
|
384
|
+
dispatchEvent(type, data);
|
|
385
|
+
};
|
|
386
|
+
};
|
|
387
|
+
Form.prototype.emitChange = function (submit) {
|
|
388
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
389
|
+
var _a, onChange, store, submitOnChange, dispatchEvent, data, dispatcher;
|
|
390
|
+
return tslib.__generator(this, function (_b) {
|
|
391
|
+
switch (_b.label) {
|
|
392
|
+
case 0:
|
|
393
|
+
_a = this.props, onChange = _a.onChange, store = _a.store, submitOnChange = _a.submitOnChange, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
394
|
+
if (!mobxStateTree.isAlive(store)) {
|
|
395
|
+
return [2 /*return*/];
|
|
396
|
+
}
|
|
397
|
+
return [4 /*yield*/, dispatchEvent('change', object.createObject(data, store.data))];
|
|
398
|
+
case 1:
|
|
399
|
+
dispatcher = _b.sent();
|
|
400
|
+
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
401
|
+
onChange &&
|
|
402
|
+
onChange(store.data, helper.difference(store.data, store.pristine), this.props);
|
|
403
|
+
}
|
|
404
|
+
store.clearRestError();
|
|
405
|
+
(submit || (submitOnChange && store.inited)) &&
|
|
406
|
+
this.handleAction(undefined, {
|
|
407
|
+
type: 'submit'
|
|
408
|
+
}, store.data);
|
|
409
|
+
return [2 /*return*/];
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
Form.prototype.handleBulkChange = function (values, submit) {
|
|
415
|
+
var _a = this.props; _a.onChange; var store = _a.store, formLazyChange = _a.formLazyChange;
|
|
416
|
+
store.updateData(values);
|
|
417
|
+
store.items.forEach(function (formItem) {
|
|
418
|
+
var updatedValue = getVariable.getVariable(values, formItem.name, false);
|
|
419
|
+
if (updatedValue !== undefined) {
|
|
420
|
+
// 更新验证状态但保留错误信息
|
|
421
|
+
formItem.reset(true);
|
|
422
|
+
// 这里需要更新value,否则提交时不会使用新的字段值校验
|
|
423
|
+
formItem.changeTmpValue(updatedValue);
|
|
424
|
+
formItem.validateOnChange && formItem.validate(values);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
(formLazyChange === false ? this.emitChange : this.lazyEmitChange)(submit);
|
|
428
|
+
};
|
|
429
|
+
Form.prototype.handleFormSubmit = function (e) {
|
|
430
|
+
var preventEnterSubmit = this.props.preventEnterSubmit;
|
|
431
|
+
e.preventDefault();
|
|
432
|
+
if (preventEnterSubmit) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
return this.handleAction(e, {
|
|
436
|
+
type: 'submit'
|
|
437
|
+
}, this.props.store.data);
|
|
438
|
+
};
|
|
439
|
+
Form.prototype.handleAction = function (e, action, data, throwErrors, delegate) {
|
|
440
|
+
var _this = this;
|
|
441
|
+
if (throwErrors === void 0) { throwErrors = false; }
|
|
442
|
+
var _a = this.props, store = _a.store, onSubmit = _a.onSubmit, api$1 = _a.api, asyncApi = _a.asyncApi, finishedField = _a.finishedField, checkInterval = _a.checkInterval, _b = _a.messages, saveSuccess = _b.saveSuccess, saveFailed = _b.saveFailed, resetAfterSubmit = _a.resetAfterSubmit, clearAfterSubmit = _a.clearAfterSubmit, onAction = _a.onAction, onSaved = _a.onSaved, onReset = _a.onReset, onFinished = _a.onFinished, onFailed = _a.onFailed, redirect = _a.redirect, reload = _a.reload, target = _a.target, env = _a.env, onChange = _a.onChange, clearPersistDataAfterSubmit = _a.clearPersistDataAfterSubmit, trimValues = _a.trimValues, dispatchEvent = _a.dispatchEvent, __ = _a.translate;
|
|
443
|
+
// 做动作之前,先把数据同步一下。
|
|
444
|
+
this.flush();
|
|
445
|
+
if (trimValues) {
|
|
446
|
+
store.trimValues();
|
|
447
|
+
}
|
|
448
|
+
// 如果 data 就是当前层,则 flush 一下。
|
|
449
|
+
if (data === this.props.data) {
|
|
450
|
+
data = store.data;
|
|
451
|
+
}
|
|
452
|
+
if (Array.isArray(action.required) && action.required.length) {
|
|
453
|
+
return store.validateFields(action.required).then(function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
454
|
+
var dispatcher;
|
|
455
|
+
return tslib.__generator(this, function (_a) {
|
|
456
|
+
switch (_a.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
if (!!result) return [3 /*break*/, 2];
|
|
459
|
+
return [4 /*yield*/, dispatchEvent('validateError', this.props.data)];
|
|
460
|
+
case 1:
|
|
461
|
+
dispatcher = _a.sent();
|
|
462
|
+
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
463
|
+
env.notify('error', __('Form.validateFailed'));
|
|
464
|
+
}
|
|
465
|
+
return [3 /*break*/, 3];
|
|
466
|
+
case 2:
|
|
467
|
+
dispatchEvent('validateSucc', this.props.data);
|
|
468
|
+
this.handleAction(e, tslib.__assign(tslib.__assign({}, action), { required: undefined }), data, throwErrors, delegate);
|
|
469
|
+
_a.label = 3;
|
|
470
|
+
case 3: return [2 /*return*/];
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}); });
|
|
474
|
+
}
|
|
475
|
+
if (action.type === 'submit' ||
|
|
476
|
+
action.actionType === 'submit' ||
|
|
477
|
+
action.actionType === 'confirm' ||
|
|
478
|
+
action.actionType === 'reset-and-submit' ||
|
|
479
|
+
action.actionType === 'clear-and-submit') {
|
|
480
|
+
store.setCurrentAction(action);
|
|
481
|
+
if (action.actionType === 'reset-and-submit') {
|
|
482
|
+
store.reset(onReset);
|
|
483
|
+
}
|
|
484
|
+
else if (action.actionType === 'clear-and-submit') {
|
|
485
|
+
store.clear(onReset);
|
|
486
|
+
}
|
|
487
|
+
return this.submit(function (values) {
|
|
488
|
+
var _a;
|
|
489
|
+
if (onSubmit && onSubmit(values, action) === false) {
|
|
490
|
+
return Promise.resolve(false);
|
|
491
|
+
}
|
|
492
|
+
// 走到这里代表校验成功了
|
|
493
|
+
dispatchEvent('validateSucc', _this.props.data);
|
|
494
|
+
if (target) {
|
|
495
|
+
_this.submitToTarget(target, values);
|
|
496
|
+
dispatchEvent('submitSucc', object.createObject(_this.props.data, values));
|
|
497
|
+
}
|
|
498
|
+
else if (action.actionType === 'reload') {
|
|
499
|
+
action.target && _this.reloadTarget(action.target, values);
|
|
500
|
+
}
|
|
501
|
+
else if (action.actionType === 'dialog') {
|
|
502
|
+
store.openDialog(data);
|
|
503
|
+
}
|
|
504
|
+
else if (action.actionType === 'drawer') {
|
|
505
|
+
store.openDrawer(data);
|
|
506
|
+
}
|
|
507
|
+
else if (api.isEffectiveApi(action.api || api$1, values)) {
|
|
508
|
+
var finnalAsyncApi_1 = action.asyncApi || asyncApi;
|
|
509
|
+
api.isEffectiveApi(finnalAsyncApi_1, store.data) &&
|
|
510
|
+
store.updateData((_a = {},
|
|
511
|
+
_a[finishedField || 'finished'] = false,
|
|
512
|
+
_a));
|
|
513
|
+
return store
|
|
514
|
+
.saveRemote(action.api || api$1, values, {
|
|
515
|
+
successMessage: saveSuccess,
|
|
516
|
+
errorMessage: saveFailed,
|
|
517
|
+
onSuccess: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
518
|
+
var dispatcher, cbResult;
|
|
519
|
+
var _this = this;
|
|
520
|
+
return tslib.__generator(this, function (_a) {
|
|
521
|
+
switch (_a.label) {
|
|
522
|
+
case 0: return [4 /*yield*/, dispatchEvent('submitSucc', object.createObject(this.props.data, { result: result }))];
|
|
523
|
+
case 1:
|
|
524
|
+
dispatcher = _a.sent();
|
|
525
|
+
if (!api.isEffectiveApi(finnalAsyncApi_1, store.data) ||
|
|
526
|
+
store.data[finishedField || 'finished']) {
|
|
527
|
+
return [2 /*return*/, {
|
|
528
|
+
cbResult: null,
|
|
529
|
+
dispatcher: dispatcher
|
|
530
|
+
}];
|
|
531
|
+
}
|
|
532
|
+
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);
|
|
533
|
+
return [2 /*return*/, {
|
|
534
|
+
cbResult: cbResult,
|
|
535
|
+
dispatcher: dispatcher
|
|
536
|
+
}];
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}); },
|
|
540
|
+
onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
541
|
+
var dispatcher;
|
|
542
|
+
return tslib.__generator(this, function (_a) {
|
|
543
|
+
switch (_a.label) {
|
|
544
|
+
case 0: return [4 /*yield*/, dispatchEvent('submitFail', object.createObject(this.props.data, { error: result }))];
|
|
545
|
+
case 1:
|
|
546
|
+
dispatcher = _a.sent();
|
|
547
|
+
return [2 /*return*/, {
|
|
548
|
+
dispatcher: dispatcher
|
|
549
|
+
}];
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}); }
|
|
553
|
+
})
|
|
554
|
+
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
555
|
+
var feedback, confirmed;
|
|
556
|
+
return tslib.__generator(this, function (_a) {
|
|
557
|
+
switch (_a.label) {
|
|
558
|
+
case 0:
|
|
559
|
+
onSaved && onSaved(values, response);
|
|
560
|
+
feedback = action.feedback || this.props.feedback;
|
|
561
|
+
if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
|
|
562
|
+
return [4 /*yield*/, this.openFeedback(feedback, store.data)];
|
|
563
|
+
case 1:
|
|
564
|
+
confirmed = _a.sent();
|
|
565
|
+
// 如果 feedback 配置了,取消就跳过原有逻辑。
|
|
566
|
+
if (feedback.skipRestOnCancel && !confirmed) {
|
|
567
|
+
throw new helper.SkipOperation();
|
|
568
|
+
}
|
|
569
|
+
else if (feedback.skipRestOnConfirm && confirmed) {
|
|
570
|
+
throw new helper.SkipOperation();
|
|
571
|
+
}
|
|
572
|
+
_a.label = 2;
|
|
573
|
+
case 2: return [2 /*return*/];
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}); });
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
// type为submit,但是没有配api以及target时,只派发事件
|
|
580
|
+
dispatchEvent('submitSucc', object.createObject(_this.props.data, values));
|
|
581
|
+
}
|
|
582
|
+
return Promise.resolve(null);
|
|
583
|
+
})
|
|
584
|
+
.then(function (values) {
|
|
585
|
+
// 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
|
|
586
|
+
if (values === false) {
|
|
587
|
+
return store.data;
|
|
588
|
+
}
|
|
589
|
+
if (onFinished && onFinished(values, action) === false) {
|
|
590
|
+
return values;
|
|
591
|
+
}
|
|
592
|
+
resetAfterSubmit && store.reset(onReset);
|
|
593
|
+
clearAfterSubmit && store.clear(onReset);
|
|
594
|
+
clearPersistDataAfterSubmit && store.clearLocalPersistData();
|
|
595
|
+
if (action.redirect || redirect) {
|
|
596
|
+
var finalRedirect = tpl.filter(action.redirect || redirect, store.data);
|
|
597
|
+
finalRedirect && env.jumpTo(finalRedirect, action);
|
|
598
|
+
}
|
|
599
|
+
else if (action.reload || reload) {
|
|
600
|
+
_this.reloadTarget(action.reload || reload, store.data);
|
|
601
|
+
}
|
|
602
|
+
action.close && _this.closeTarget(action.close);
|
|
603
|
+
return values;
|
|
604
|
+
})
|
|
605
|
+
.catch(function (reason) {
|
|
606
|
+
if (reason instanceof helper.SkipOperation) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
onFailed && onFailed(reason, store.errors);
|
|
610
|
+
if (throwErrors) {
|
|
611
|
+
throw reason;
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
else if (action.type === 'reset' || action.actionType === 'reset') {
|
|
616
|
+
store.setCurrentAction(action);
|
|
617
|
+
store.reset(onReset);
|
|
618
|
+
}
|
|
619
|
+
else if (action.actionType === 'clear') {
|
|
620
|
+
store.setCurrentAction(action);
|
|
621
|
+
store.clear(onReset);
|
|
622
|
+
}
|
|
623
|
+
else if (action.actionType === 'validate') {
|
|
624
|
+
store.setCurrentAction(action);
|
|
625
|
+
this.validate(true);
|
|
626
|
+
}
|
|
627
|
+
else if (action.actionType === 'dialog') {
|
|
628
|
+
store.setCurrentAction(action);
|
|
629
|
+
store.openDialog(data);
|
|
630
|
+
}
|
|
631
|
+
else if (action.actionType === 'drawer') {
|
|
632
|
+
store.setCurrentAction(action);
|
|
633
|
+
store.openDrawer(data);
|
|
634
|
+
}
|
|
635
|
+
else if (action.actionType === 'ajax') {
|
|
636
|
+
store.setCurrentAction(action);
|
|
637
|
+
if (!api.isEffectiveApi(action.api)) {
|
|
638
|
+
return env.alert(__("\u5F53 actionType \u4E3A ajax \u65F6\uFF0C\u8BF7\u8BBE\u7F6E api \u5C5E\u6027"));
|
|
639
|
+
}
|
|
640
|
+
return store
|
|
641
|
+
.saveRemote(action.api, data, {
|
|
642
|
+
successMessage: __((action.messages && action.messages.success) || saveSuccess),
|
|
643
|
+
errorMessage: __((action.messages && action.messages.failed) || saveFailed)
|
|
644
|
+
})
|
|
645
|
+
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
646
|
+
var redirect;
|
|
647
|
+
return tslib.__generator(this, function (_a) {
|
|
648
|
+
switch (_a.label) {
|
|
649
|
+
case 0:
|
|
650
|
+
response &&
|
|
651
|
+
onChange &&
|
|
652
|
+
onChange(store.data, helper.difference(store.data, store.pristine), this.props);
|
|
653
|
+
if (!store.validated) return [3 /*break*/, 2];
|
|
654
|
+
return [4 /*yield*/, this.validate(true)];
|
|
655
|
+
case 1:
|
|
656
|
+
_a.sent();
|
|
657
|
+
_a.label = 2;
|
|
658
|
+
case 2:
|
|
659
|
+
if (!(action.feedback && helper.isVisible(action.feedback, store.data))) return [3 /*break*/, 4];
|
|
660
|
+
return [4 /*yield*/, this.openFeedback(action.feedback, store.data)];
|
|
661
|
+
case 3:
|
|
662
|
+
_a.sent();
|
|
663
|
+
_a.label = 4;
|
|
664
|
+
case 4:
|
|
665
|
+
redirect = action.redirect && tpl.filter(action.redirect, store.data);
|
|
666
|
+
redirect && env.jumpTo(redirect, action);
|
|
667
|
+
action.reload && this.reloadTarget(action.reload, store.data);
|
|
668
|
+
action.close && this.closeTarget(action.close);
|
|
669
|
+
return [2 /*return*/];
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}); })
|
|
673
|
+
.catch(function (e) {
|
|
674
|
+
onFailed && onFailed(e, store.errors);
|
|
675
|
+
if (throwErrors || action.countDown) {
|
|
676
|
+
throw e;
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
else if (action.actionType === 'reload') {
|
|
681
|
+
store.setCurrentAction(action);
|
|
682
|
+
if (action.target) {
|
|
683
|
+
this.reloadTarget(action.target, data);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
this.receive(data);
|
|
687
|
+
}
|
|
688
|
+
// action.target && this.reloadTarget(action.target, data);
|
|
689
|
+
}
|
|
690
|
+
else if (onAction) {
|
|
691
|
+
// 不识别的丢给上层去处理。
|
|
692
|
+
return onAction(e, action, data, throwErrors, delegate || this.context);
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
Form.prototype.handleQuery = function (query) {
|
|
696
|
+
var _a, _b;
|
|
697
|
+
if (this.props.initApi) {
|
|
698
|
+
this.receive(query);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
(_b = (_a = this.props).onQuery) === null || _b === void 0 ? void 0 : _b.call(_a, query);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
Form.prototype.handleDialogConfirm = function (values, action, ctx, targets) {
|
|
705
|
+
var _a = this.props, store = _a.store; _a.onChange;
|
|
706
|
+
if ((action.mergeData || store.action.mergeData) &&
|
|
707
|
+
values.length === 1 &&
|
|
708
|
+
values[0] &&
|
|
709
|
+
targets[0].props.type === 'form') {
|
|
710
|
+
this.handleBulkChange(values[0], false);
|
|
711
|
+
}
|
|
712
|
+
store.closeDialog(true);
|
|
713
|
+
};
|
|
714
|
+
Form.prototype.handleDialogClose = function (confirmed) {
|
|
715
|
+
if (confirmed === void 0) { confirmed = false; }
|
|
716
|
+
var store = this.props.store;
|
|
717
|
+
store.closeDialog(confirmed);
|
|
718
|
+
};
|
|
719
|
+
Form.prototype.handleDrawerConfirm = function (values, action, ctx, targets) {
|
|
720
|
+
var _a = this.props, store = _a.store, onChange = _a.onChange;
|
|
721
|
+
if ((action.mergeData || store.action.mergeData) &&
|
|
722
|
+
values.length === 1 &&
|
|
723
|
+
values[0] &&
|
|
724
|
+
targets[0].props.type === 'form') {
|
|
725
|
+
store.updateData(values[0]);
|
|
726
|
+
onChange &&
|
|
727
|
+
onChange(store.data, helper.difference(store.data, store.pristine), this.props);
|
|
728
|
+
}
|
|
729
|
+
store.closeDrawer(true);
|
|
730
|
+
};
|
|
731
|
+
Form.prototype.handleDrawerClose = function () {
|
|
732
|
+
var store = this.props.store;
|
|
733
|
+
store.closeDrawer(false);
|
|
734
|
+
};
|
|
735
|
+
Form.prototype.submitToTarget = function (target, values) {
|
|
736
|
+
// 会被覆写
|
|
737
|
+
};
|
|
738
|
+
Form.prototype.reloadTarget = function (target, data) {
|
|
739
|
+
// 会被覆写
|
|
740
|
+
};
|
|
741
|
+
Form.prototype.closeTarget = function (target) {
|
|
742
|
+
// 会被覆写
|
|
743
|
+
};
|
|
744
|
+
Form.prototype.openFeedback = function (dialog, ctx) {
|
|
745
|
+
var _this = this;
|
|
746
|
+
return new Promise(function (resolve) {
|
|
747
|
+
var store = _this.props.store;
|
|
748
|
+
store.setCurrentAction({
|
|
749
|
+
type: 'button',
|
|
750
|
+
actionType: 'dialog',
|
|
751
|
+
dialog: dialog
|
|
752
|
+
});
|
|
753
|
+
store.openDialog(ctx, undefined, function (confirmed) {
|
|
754
|
+
resolve(confirmed);
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
};
|
|
758
|
+
Form.prototype.buildActions = function () {
|
|
759
|
+
var _a = this.props, actions = _a.actions, submitText = _a.submitText, body = _a.body, __ = _a.translate;
|
|
760
|
+
if (typeof actions !== 'undefined' ||
|
|
761
|
+
!submitText ||
|
|
762
|
+
(Array.isArray(body) &&
|
|
763
|
+
body.some(function (item) {
|
|
764
|
+
var _a, _b, _c;
|
|
765
|
+
return item &&
|
|
766
|
+
!!~['submit', 'button', 'button-group', 'reset'].indexOf(((_b = (_a = item === null || item === void 0 ? void 0 : item.body) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) ||
|
|
767
|
+
((_c = item === null || item === void 0 ? void 0 : item.body) === null || _c === void 0 ? void 0 : _c.type) ||
|
|
768
|
+
item.type);
|
|
769
|
+
}))) {
|
|
770
|
+
return actions;
|
|
771
|
+
}
|
|
772
|
+
return [
|
|
773
|
+
{
|
|
774
|
+
type: 'submit',
|
|
775
|
+
label: __(submitText),
|
|
776
|
+
primary: true
|
|
777
|
+
}
|
|
778
|
+
];
|
|
779
|
+
};
|
|
780
|
+
Form.prototype.renderFormItems = function (schema, region, otherProps) {
|
|
781
|
+
if (region === void 0) { region = ''; }
|
|
782
|
+
if (otherProps === void 0) { otherProps = {}; }
|
|
783
|
+
var body = Array.isArray(schema.body)
|
|
784
|
+
? schema.body
|
|
785
|
+
: schema.body
|
|
786
|
+
? [schema.body]
|
|
787
|
+
: [];
|
|
788
|
+
// 旧用法,让 wrapper 走走 compat 逻辑兼容旧用法
|
|
789
|
+
// 后续可以删除。
|
|
790
|
+
if (!body.length && schema.controls) {
|
|
791
|
+
console.warn('请用 body 代替 controls');
|
|
792
|
+
body = [
|
|
793
|
+
{
|
|
794
|
+
size: 'none',
|
|
795
|
+
type: 'wrapper',
|
|
796
|
+
wrap: false,
|
|
797
|
+
controls: schema.controls
|
|
798
|
+
}
|
|
799
|
+
];
|
|
800
|
+
}
|
|
801
|
+
return this.renderChildren(body, region, otherProps);
|
|
802
|
+
};
|
|
803
|
+
Form.prototype.renderChildren = function (children, region, otherProps) {
|
|
804
|
+
var _this = this;
|
|
805
|
+
if (otherProps === void 0) { otherProps = {}; }
|
|
806
|
+
children = children || [];
|
|
807
|
+
if (!Array.isArray(children)) {
|
|
808
|
+
children = [children];
|
|
809
|
+
}
|
|
810
|
+
if (this.props.mode === 'row') {
|
|
811
|
+
var ns_1 = this.props.classPrefix;
|
|
812
|
+
children = flatten__default["default"](children).filter(function (item) {
|
|
813
|
+
if (item.hidden || item.visible === false) {
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
var exprProps = filterSchema["default"](item, _this.props.store.data, undefined, _this.props);
|
|
817
|
+
if (exprProps.hidden || exprProps.visible === false) {
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
return true;
|
|
821
|
+
});
|
|
822
|
+
if (!children.length) {
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
return (React__default["default"].createElement("div", { className: "".concat(ns_1, "Form-row") }, children.map(function (control, key) {
|
|
826
|
+
return ~['hidden', 'formula'].indexOf(control.type) ||
|
|
827
|
+
control.mode === 'inline' ? (_this.renderChild(control, key, otherProps)) : (React__default["default"].createElement("div", { key: key, className: cx__default["default"]("".concat(ns_1, "Form-col"), control.columnClassName) }, _this.renderChild(control, '', tslib.__assign(tslib.__assign({}, otherProps), { mode: 'row' }))));
|
|
828
|
+
})));
|
|
829
|
+
}
|
|
830
|
+
return children.map(function (control, key) {
|
|
831
|
+
return _this.renderChild(control, key, otherProps, region);
|
|
832
|
+
});
|
|
833
|
+
};
|
|
834
|
+
Form.prototype.renderChild = function (control, key, otherProps, region) {
|
|
835
|
+
if (key === void 0) { key = ''; }
|
|
836
|
+
if (otherProps === void 0) { otherProps = {}; }
|
|
837
|
+
if (region === void 0) { region = ''; }
|
|
838
|
+
if (!control) {
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
else if (typeof control === 'string') {
|
|
842
|
+
control = {
|
|
843
|
+
type: 'tpl',
|
|
844
|
+
tpl: control
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
var props = tslib.__assign(tslib.__assign({}, this.props), otherProps);
|
|
848
|
+
var form = this.props.store;
|
|
849
|
+
var render = props.render, mode = props.mode, horizontal = props.horizontal, store = props.store, disabled = props.disabled, controlWidth = props.controlWidth, resolveDefinitions = props.resolveDefinitions, lazyChange = props.lazyChange; props.formLazyChange; var dispatchEvent = props.dispatchEvent, labelAlign = props.labelAlign;
|
|
850
|
+
var subProps = {
|
|
851
|
+
formStore: form,
|
|
852
|
+
data: store.data,
|
|
853
|
+
key: "".concat(control.name || '', "-").concat(control.type, "-").concat(key),
|
|
854
|
+
formInited: form.inited,
|
|
855
|
+
formSubmited: form.submited,
|
|
856
|
+
formMode: mode,
|
|
857
|
+
formHorizontal: horizontal,
|
|
858
|
+
formLabelAlign: labelAlign !== 'left' ? 'right' : labelAlign,
|
|
859
|
+
controlWidth: controlWidth,
|
|
860
|
+
disabled: disabled || control.disabled || form.loading,
|
|
861
|
+
btnDisabled: disabled || form.loading || form.validating,
|
|
862
|
+
onAction: this.handleAction,
|
|
863
|
+
onQuery: this.handleQuery,
|
|
864
|
+
onChange: this.handleChange,
|
|
865
|
+
onBulkChange: this.handleBulkChange,
|
|
866
|
+
addHook: this.addHook,
|
|
867
|
+
removeHook: this.removeHook,
|
|
868
|
+
renderFormItems: this.renderFormItems,
|
|
869
|
+
formItemDispatchEvent: this.formItemDispatchEvent(dispatchEvent),
|
|
870
|
+
formPristine: form.pristine
|
|
871
|
+
// value: (control as any)?.name
|
|
872
|
+
// ? getVariable(form.data, (control as any)?.name, canAccessSuperData)
|
|
873
|
+
// : (control as any)?.value,
|
|
874
|
+
// defaultValue: (control as any)?.value
|
|
875
|
+
};
|
|
876
|
+
var subSchema = tslib.__assign({}, control);
|
|
877
|
+
if (subSchema.$ref) {
|
|
878
|
+
subSchema = tslib.__assign(tslib.__assign({}, resolveDefinitions(subSchema.$ref)), subSchema);
|
|
879
|
+
}
|
|
880
|
+
lazyChange === false && (subSchema.changeImmediately = true);
|
|
881
|
+
return render("".concat(region ? "".concat(region, "/") : '').concat(key), subSchema, subProps);
|
|
882
|
+
};
|
|
883
|
+
Form.prototype.renderBody = function () {
|
|
884
|
+
var _a = this.props, body = _a.body, mode = _a.mode, className = _a.className, cx = _a.classnames, debug = _a.debug, $path = _a.$path, store = _a.store, columnCount = _a.columnCount, render = _a.render;
|
|
885
|
+
var restError = store.restError;
|
|
886
|
+
var WrapperComponent = this.props.wrapperComponent ||
|
|
887
|
+
(/(?:\/|^)form\//.test($path) ? 'div' : 'form');
|
|
888
|
+
var padDom = helper.repeatCount(columnCount && Array.isArray(body)
|
|
889
|
+
? columnCount - (body.length % columnCount)
|
|
890
|
+
: 0, function (index) { return (React__default["default"].createElement("div", { className: cx("Form-item Form-item--".concat(mode, " is-placeholder")), key: index })); });
|
|
891
|
+
return (React__default["default"].createElement(WrapperComponent, { className: cx("Form", "Form--".concat(mode || 'normal'), columnCount ? "Form--column Form--column-".concat(columnCount) : null, className), onSubmit: this.handleFormSubmit, noValidate: true },
|
|
892
|
+
React__default["default"].createElement("input", { type: "submit", style: { display: 'none' } }),
|
|
893
|
+
debug ? (React__default["default"].createElement("pre", null,
|
|
894
|
+
React__default["default"].createElement("code", null, JSON.stringify(store.data, null, 2)))) : null,
|
|
895
|
+
render('spinner', { type: 'spinner' }, {
|
|
896
|
+
overlay: true,
|
|
897
|
+
show: store.loading
|
|
898
|
+
}),
|
|
899
|
+
this.renderFormItems({
|
|
900
|
+
body: body
|
|
901
|
+
}),
|
|
902
|
+
padDom,
|
|
903
|
+
restError && restError.length ? (React__default["default"].createElement("ul", { className: cx('Form-restError', 'Form-feedback') }, restError.map(function (item, idx) { return (React__default["default"].createElement("li", { key: idx }, item)); }))) : null,
|
|
904
|
+
render('modal', tslib.__assign(tslib.__assign({}, (store.action &&
|
|
905
|
+
store.action.dialog)), { type: 'dialog' }), {
|
|
906
|
+
key: 'dialog',
|
|
907
|
+
data: store.dialogData,
|
|
908
|
+
onConfirm: this.handleDialogConfirm,
|
|
909
|
+
onClose: this.handleDialogClose,
|
|
910
|
+
show: store.dialogOpen
|
|
911
|
+
}),
|
|
912
|
+
render('modal', tslib.__assign(tslib.__assign({}, (store.action &&
|
|
913
|
+
store.action.drawer)), { type: 'drawer' }), {
|
|
914
|
+
key: 'drawer',
|
|
915
|
+
data: store.drawerData,
|
|
916
|
+
onConfirm: this.handleDrawerConfirm,
|
|
917
|
+
onClose: this.handleDrawerClose,
|
|
918
|
+
show: store.drawerOpen
|
|
919
|
+
})));
|
|
920
|
+
};
|
|
921
|
+
Form.prototype.render = function () {
|
|
922
|
+
var _a = this.props; _a.$path; _a.$schema; var wrapWithPanel = _a.wrapWithPanel, render = _a.render, title = _a.title, store = _a.store, panelClassName = _a.panelClassName, headerClassName = _a.headerClassName, footerClassName = _a.footerClassName, footerWrapClassName = _a.footerWrapClassName, actionsClassName = _a.actionsClassName, bodyClassName = _a.bodyClassName, cx = _a.classnames, affixFooter = _a.affixFooter, lazyLoad = _a.lazyLoad, __ = _a.translate, footer = _a.footer; _a.formStore;
|
|
923
|
+
var body = this.renderBody();
|
|
924
|
+
if (wrapWithPanel) {
|
|
925
|
+
body = render('body', {
|
|
926
|
+
type: 'panel',
|
|
927
|
+
title: __(title)
|
|
928
|
+
}, {
|
|
929
|
+
className: cx(panelClassName, 'Panel--form'),
|
|
930
|
+
formStore: this.props.store,
|
|
931
|
+
children: body,
|
|
932
|
+
actions: this.buildActions(),
|
|
933
|
+
onAction: this.handleAction,
|
|
934
|
+
onQuery: this.handleQuery,
|
|
935
|
+
disabled: store.loading,
|
|
936
|
+
btnDisabled: store.loading || store.validating,
|
|
937
|
+
headerClassName: headerClassName,
|
|
938
|
+
footer: footer,
|
|
939
|
+
footerClassName: footerClassName,
|
|
940
|
+
footerWrapClassName: footerWrapClassName,
|
|
941
|
+
actionsClassName: actionsClassName,
|
|
942
|
+
bodyClassName: bodyClassName,
|
|
943
|
+
affixFooter: affixFooter
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
if (lazyLoad) {
|
|
947
|
+
body = React__default["default"].createElement(LazyComponent["default"], null, body);
|
|
948
|
+
}
|
|
949
|
+
return body;
|
|
950
|
+
};
|
|
951
|
+
Form.defaultProps = {
|
|
952
|
+
title: 'Form.title',
|
|
953
|
+
submitText: 'Form.submit',
|
|
954
|
+
initFetch: true,
|
|
955
|
+
wrapWithPanel: true,
|
|
956
|
+
mode: 'normal',
|
|
957
|
+
collapsable: false,
|
|
958
|
+
controlWidth: 'full',
|
|
959
|
+
horizontal: {
|
|
960
|
+
left: 2,
|
|
961
|
+
right: 10,
|
|
962
|
+
offset: 2
|
|
963
|
+
},
|
|
964
|
+
columnCount: 0,
|
|
965
|
+
panelClassName: 'Panel--default',
|
|
966
|
+
messages: {
|
|
967
|
+
fetchFailed: 'fetchFailed',
|
|
968
|
+
saveSuccess: 'saveSuccess',
|
|
969
|
+
saveFailed: 'saveFailed'
|
|
970
|
+
},
|
|
971
|
+
wrapperComponent: '',
|
|
972
|
+
finishedField: 'finished',
|
|
973
|
+
initFinishedField: 'finished',
|
|
974
|
+
labelAlign: 'right'
|
|
975
|
+
};
|
|
976
|
+
Form.propsList = [
|
|
977
|
+
'title',
|
|
978
|
+
'header',
|
|
979
|
+
'controls',
|
|
980
|
+
'tabs',
|
|
981
|
+
'fieldSet',
|
|
982
|
+
'submitText',
|
|
983
|
+
'initFetch',
|
|
984
|
+
'wrapWithPanel',
|
|
985
|
+
'mode',
|
|
986
|
+
'columnCount',
|
|
987
|
+
'collapsable',
|
|
988
|
+
'horizontal',
|
|
989
|
+
'panelClassName',
|
|
990
|
+
'messages',
|
|
991
|
+
'wrapperComponent',
|
|
992
|
+
'resetAfterSubmit',
|
|
993
|
+
'clearAfterSubmit',
|
|
994
|
+
'submitOnInit',
|
|
995
|
+
'submitOnChange',
|
|
996
|
+
'onInit',
|
|
997
|
+
'onReset',
|
|
998
|
+
'onSubmit',
|
|
999
|
+
'onChange',
|
|
1000
|
+
'onFailed',
|
|
1001
|
+
'onFinished',
|
|
1002
|
+
'onSaved',
|
|
1003
|
+
'canAccessSuperData',
|
|
1004
|
+
'lazyChange',
|
|
1005
|
+
'formLazyChange',
|
|
1006
|
+
'lazyLoad',
|
|
1007
|
+
'formInited',
|
|
1008
|
+
'simpleMode',
|
|
1009
|
+
'inputOnly',
|
|
1010
|
+
'value',
|
|
1011
|
+
'actions',
|
|
1012
|
+
'multiple'
|
|
1013
|
+
];
|
|
1014
|
+
return Form;
|
|
1015
|
+
}(React__default["default"].Component));
|
|
1016
|
+
/** @class */ ((function (_super) {
|
|
1017
|
+
tslib.__extends(FormRenderer, _super);
|
|
1018
|
+
function FormRenderer(props, context) {
|
|
1019
|
+
var _this = _super.call(this, props) || this;
|
|
1020
|
+
var scoped = context;
|
|
1021
|
+
scoped.registerComponent(_this);
|
|
1022
|
+
return _this;
|
|
1023
|
+
}
|
|
1024
|
+
FormRenderer.prototype.componentDidMount = function () {
|
|
1025
|
+
_super.prototype.componentDidMount.call(this);
|
|
1026
|
+
if (this.props.autoFocus) {
|
|
1027
|
+
var scoped = this.context;
|
|
1028
|
+
var inputs = scoped.getComponents();
|
|
1029
|
+
var focuableInput_1 = find__default["default"](inputs, function (input) { return input.focus; });
|
|
1030
|
+
focuableInput_1 && setTimeout(function () { return focuableInput_1.focus(); }, 200);
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
FormRenderer.prototype.componentWillUnmount = function () {
|
|
1034
|
+
var scoped = this.context;
|
|
1035
|
+
scoped.unRegisterComponent(this);
|
|
1036
|
+
_super.prototype.componentWillUnmount.call(this);
|
|
1037
|
+
};
|
|
1038
|
+
FormRenderer.prototype.doAction = function (action, data, throwErrors) {
|
|
1039
|
+
if (data === void 0) { data = this.props.store.data; }
|
|
1040
|
+
if (throwErrors === void 0) { throwErrors = false; }
|
|
1041
|
+
return this.handleAction(undefined, action, data, throwErrors);
|
|
1042
|
+
};
|
|
1043
|
+
FormRenderer.prototype.handleAction = function (e, action, ctx, throwErrors, delegate) {
|
|
1044
|
+
if (throwErrors === void 0) { throwErrors = false; }
|
|
1045
|
+
// 禁用了不要做任何动作。@先注释掉,会引起其他问题
|
|
1046
|
+
// if (this.props.disabled) {
|
|
1047
|
+
// return;
|
|
1048
|
+
// }
|
|
1049
|
+
if (action.target && action.actionType !== 'reload') {
|
|
1050
|
+
var scoped_1 = this.context;
|
|
1051
|
+
return Promise.all(action.target.split(',').map(function (name) {
|
|
1052
|
+
var target = scoped_1.getComponentByName(name);
|
|
1053
|
+
return (target &&
|
|
1054
|
+
target.doAction &&
|
|
1055
|
+
target.doAction(tslib.__assign(tslib.__assign({}, action), { target: undefined }), ctx, throwErrors));
|
|
1056
|
+
}));
|
|
1057
|
+
}
|
|
1058
|
+
else {
|
|
1059
|
+
return _super.prototype.handleAction.call(this, e, action, ctx, throwErrors, delegate);
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
FormRenderer.prototype.handleDialogConfirm = function (values, action, ctx, targets) {
|
|
1063
|
+
_super.prototype.handleDialogConfirm.call(this, values, action, ctx, targets);
|
|
1064
|
+
var store = this.props.store;
|
|
1065
|
+
var scoped = this.context;
|
|
1066
|
+
if (action.reload) {
|
|
1067
|
+
scoped.reload(action.reload, ctx);
|
|
1068
|
+
}
|
|
1069
|
+
else if (store.action && store.action.reload) {
|
|
1070
|
+
scoped.reload(store.action.reload, ctx);
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
FormRenderer.prototype.submitToTarget = function (target, values) {
|
|
1074
|
+
var scoped = this.context;
|
|
1075
|
+
scoped.send(target, values);
|
|
1076
|
+
};
|
|
1077
|
+
FormRenderer.prototype.reloadTarget = function (target, data) {
|
|
1078
|
+
var scoped = this.context;
|
|
1079
|
+
scoped.reload(target, data);
|
|
1080
|
+
};
|
|
1081
|
+
FormRenderer.prototype.closeTarget = function (target) {
|
|
1082
|
+
var scoped = this.context;
|
|
1083
|
+
scoped.close(target);
|
|
1084
|
+
};
|
|
1085
|
+
FormRenderer.prototype.reload = function (target, query, ctx, silent) {
|
|
1086
|
+
if (query) {
|
|
1087
|
+
return this.receive(query);
|
|
1088
|
+
}
|
|
1089
|
+
var scoped = this.context;
|
|
1090
|
+
var subPath = '';
|
|
1091
|
+
var idx;
|
|
1092
|
+
var subQuery = null;
|
|
1093
|
+
if (target && ~(idx = target.indexOf('.'))) {
|
|
1094
|
+
subPath = target.substring(idx + 1);
|
|
1095
|
+
target = target.substring(0, idx);
|
|
1096
|
+
}
|
|
1097
|
+
var idx2 = target ? target.indexOf('?') : -1;
|
|
1098
|
+
if (~idx2) {
|
|
1099
|
+
subQuery = dataMapping.dataMapping(helper.qsparse(target.substring(idx2 + 1)), ctx);
|
|
1100
|
+
target = target.substring(0, idx2);
|
|
1101
|
+
}
|
|
1102
|
+
var component;
|
|
1103
|
+
if (target &&
|
|
1104
|
+
(component = scoped.getComponentByName(target)) &&
|
|
1105
|
+
component.reload) {
|
|
1106
|
+
component.reload(subPath, subQuery, ctx);
|
|
1107
|
+
}
|
|
1108
|
+
else if (target === '*') {
|
|
1109
|
+
_super.prototype.reload.call(this, target, query, ctx, silent);
|
|
1110
|
+
var components = scoped.getComponents();
|
|
1111
|
+
components.forEach(function (component) {
|
|
1112
|
+
return component.reload && component.reload('', subQuery, ctx);
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
_super.prototype.reload.call(this, target, query, ctx, silent);
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
FormRenderer.prototype.receive = function (values, name) {
|
|
1120
|
+
if (name) {
|
|
1121
|
+
var scoped = this.context;
|
|
1122
|
+
var idx = name.indexOf('.');
|
|
1123
|
+
var subPath = '';
|
|
1124
|
+
if (~idx) {
|
|
1125
|
+
subPath = name.substring(1 + idx);
|
|
1126
|
+
name = name.substring(0, idx);
|
|
1127
|
+
}
|
|
1128
|
+
var component = scoped.getComponentByName(name);
|
|
1129
|
+
component && component.receive && component.receive(values, subPath);
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
return _super.prototype.receive.call(this, values);
|
|
1133
|
+
};
|
|
1134
|
+
FormRenderer.prototype.setData = function (values) {
|
|
1135
|
+
return _super.prototype.setValues.call(this, values);
|
|
1136
|
+
};
|
|
1137
|
+
FormRenderer.contextType = Scoped.ScopedContext;
|
|
1138
|
+
FormRenderer = tslib.__decorate([
|
|
1139
|
+
factory.Renderer({
|
|
1140
|
+
type: 'form',
|
|
1141
|
+
storeType: form.FormStore.name,
|
|
1142
|
+
isolateScope: true,
|
|
1143
|
+
storeExtendsData: function (props) { return props.inheritData; },
|
|
1144
|
+
shouldSyncSuperStore: function (store, props, prevProps) {
|
|
1145
|
+
var _a, _b;
|
|
1146
|
+
// 如果是 QuickEdit,让 store 同步 __super 数据。
|
|
1147
|
+
if (props.quickEditFormRef &&
|
|
1148
|
+
props.onQuickChange &&
|
|
1149
|
+
(helper.isObjectShallowModified(prevProps.data, props.data) ||
|
|
1150
|
+
helper.isObjectShallowModified(prevProps.data.__super, props.data.__super) ||
|
|
1151
|
+
helper.isObjectShallowModified((_a = prevProps.data.__super) === null || _a === void 0 ? void 0 : _a.__super, (_b = props.data.__super) === null || _b === void 0 ? void 0 : _b.__super))) {
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
return undefined;
|
|
1155
|
+
}
|
|
1156
|
+
}),
|
|
1157
|
+
tslib.__metadata("design:paramtypes", [Object, Object])
|
|
1158
|
+
], FormRenderer);
|
|
1159
|
+
return FormRenderer;
|
|
1160
|
+
})(Form));
|
|
1161
|
+
|
|
1162
|
+
exports["default"] = Form;
|