@lvxiaowu/antd4
Version:
antd4-components
105 lines (80 loc) • 3.59 kB
JavaScript
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
import { action, makeObservable } from 'mobx';
import { overrideStore, FORM_MODAL_STORE, resetStore } from '../utils';
import ModalStore from '../Modal/store';
var FormModalStore = /*#__PURE__*/_createClass(function FormModalStore(overrides) {
var _this = this;
_classCallCheck(this, FormModalStore);
this.$storeName = FORM_MODAL_STORE;
this.$modalStore = new ModalStore({
onOk: function onOk(openValues) {
return _this.submit(openValues);
},
onOpen: function onOpen(data) {
return _this.onOpen(data);
}
});
this.getModalStore = function () {
return _this.$modalStore;
};
this.open = function (data) {
return _this.$modalStore.open(data);
};
this.onOpen = function (data) {
return data;
};
this.close = function () {
_this.$modalStore.close();
};
this.form = void 0;
this.setFormInstance = function (form) {
_this.form = form;
};
this.getFormInstance = function () {
return _this.form;
};
this.onFinish = function () {};
this.submit = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(openValues) {
var values;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return _this.form.validateFields();
case 2:
values = _context.sent;
if (!_this.onFinish) {
_context.next = 6;
break;
}
_context.next = 6;
return _this.onFinish(values, openValues);
case 6:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
this.resetStore = function () {
resetStore(_this, FormModalStore);
};
overrideStore(this, overrides);
makeObservable(this, {
open: action,
onOpen: action,
close: action,
submit: action
});
});
export { FormModalStore as default };