mutants-appfx
Version:
appfx module
469 lines (384 loc) • 14.3 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _defineProperty = require('babel-runtime/core-js/object/define-property');
var _defineProperty2 = _interopRequireDefault(_defineProperty);
var _getOwnPropertyDescriptor = require('babel-runtime/core-js/object/get-own-property-descriptor');
var _getOwnPropertyDescriptor2 = _interopRequireDefault(_getOwnPropertyDescriptor);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _desc, _value, _class, _descriptor, _descriptor2;
var _mutantsMicrofx = require('mutants-microfx');
var _mobx = require('mobx');
var _UIFunction = require('../UIFunction');
var _UIFunction2 = _interopRequireDefault(_UIFunction);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _initDefineProp(target, property, descriptor, context) {
if (!descriptor) return;
(0, _defineProperty2.default)(target, property, {
enumerable: descriptor.enumerable,
configurable: descriptor.configurable,
writable: descriptor.writable,
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
});
}
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
function _initializerWarningHelper(descriptor, context) {
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}
var ViewController = (_class = function () {
(0, _createClass3.default)(ViewController, [{
key: 'viewModel',
// 统一的UI控制器
get: function get() {
var _this = this;
var vo = this.viewModels.find(function (it) {
return it.iid === _this._iid;
});
if (!vo) {
return null;
}
return vo.viewModel;
}
}, {
key: 'uifunction',
get: function get() {
return this.viewModel ? _UIFunction2.default.get(this.viewModel.mid) : null;
}
}, {
key: 'clientType',
get: function get() {
return _mutantsMicrofx.clientType;
}
}]);
function ViewController(module, viewModels, dataModel, ui, controller, blocks) {
(0, _classCallCheck3.default)(this, ViewController);
_initDefineProp(this, '_pid', _descriptor, this);
_initDefineProp(this, '_iid', _descriptor2, this);
this.module = module;
this.ui = ui;
this.controller = controller;
this.blocks = blocks;
if (viewModels) {
this._init(viewModels);
}
if (dataModel) {
this._initData(dataModel);
}
}
(0, _createClass3.default)(ViewController, [{
key: '_curView',
value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(iid, pid) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(this._iid !== iid)) {
_context.next = 5;
break;
}
this._pid = pid;
this._iid = iid;
_context.next = 5;
return this.loadView(this.viewModel);
case 5:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function _curView(_x, _x2) {
return _ref.apply(this, arguments);
}
return _curView;
}()
}, {
key: '_init',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(viewModels) {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
this.viewModels = viewModels;
case 1:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function _init(_x3) {
return _ref2.apply(this, arguments);
}
return _init;
}()
}, {
key: '_initData',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(dataModel) {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
// 加载表单数据
this.data = dataModel;
_context3.next = 3;
return this.init();
case 3:
if (!this.data.ID) {
_context3.next = 6;
break;
}
_context3.next = 6;
return this.load();
case 6:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function _initData(_x4) {
return _ref3.apply(this, arguments);
}
return _initData;
}()
}, {
key: 'executeBlock',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(name, ctx) {
var block, processors, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, processor;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
block = this.blocks[name];
if (block) {
_context4.next = 3;
break;
}
throw new Error(name + ' block not found');
case 3:
if (!(typeof block.execute === 'function')) {
_context4.next = 9;
break;
}
_context4.next = 6;
return block.execute(ctx);
case 6:
return _context4.abrupt('return');
case 9:
if (!(typeof block === 'function')) {
_context4.next = 39;
break;
}
processors = block({
data: this.data,
viewModel: this.viewModel
}).asyncProcessors;
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context4.prev = 14;
_iterator = (0, _getIterator3.default)(processors);
case 16:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context4.next = 23;
break;
}
processor = _step.value;
_context4.next = 20;
return processor.init(ctx).doExecute();
case 20:
_iteratorNormalCompletion = true;
_context4.next = 16;
break;
case 23:
_context4.next = 29;
break;
case 25:
_context4.prev = 25;
_context4.t0 = _context4['catch'](14);
_didIteratorError = true;
_iteratorError = _context4.t0;
case 29:
_context4.prev = 29;
_context4.prev = 30;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 32:
_context4.prev = 32;
if (!_didIteratorError) {
_context4.next = 35;
break;
}
throw _iteratorError;
case 35:
return _context4.finish(32);
case 36:
return _context4.finish(29);
case 37:
_context4.next = 40;
break;
case 39:
throw new Error(name + ' block not support!');
case 40:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[14, 25, 29, 37], [30,, 32, 36]]);
}));
function executeBlock(_x5, _x6) {
return _ref4.apply(this, arguments);
}
return executeBlock;
}()
}, {
key: 'init',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function init() {
return _ref5.apply(this, arguments);
}
return init;
}()
}, {
key: 'load',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
case 'end':
return _context6.stop();
}
}
}, _callee6, this);
}));
function load() {
return _ref6.apply(this, arguments);
}
return load;
}()
}, {
key: 'loadView',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
case 'end':
return _context7.stop();
}
}
}, _callee7, this);
}));
function loadView() {
return _ref7.apply(this, arguments);
}
return loadView;
}()
}, {
key: 'closeView',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(closedViewModel) {
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
case 'end':
return _context8.stop();
}
}
}, _callee8, this);
}));
function closeView(_x7) {
return _ref8.apply(this, arguments);
}
return closeView;
}()
}, {
key: 'openUrl',
value: function openUrl(_ref9) {
var url = _ref9.url;
_mutantsMicrofx.history.push(url);
}
}, {
key: 'changePage',
value: function changePage(_ref10) {
var pid = _ref10.pid,
state = _ref10.state;
var _module = this.module,
sysid = _module.sysid,
mid = _module.mid;
var vi = this.module.views[pid] || this.module.view;
if (vi.mode === 'multi') {
_mutantsMicrofx.history.push('/' + sysid + '/' + mid + '?pid=' + pid, state);
return;
}
if (this._pid === pid) {
_mutantsMicrofx.history.replace('/' + sysid + '/' + mid + '?pid=' + pid, state);
} else {
_mutantsMicrofx.history.push('/' + sysid + '/' + mid + '?pid=' + pid, state);
}
}
}]);
return ViewController;
}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, '_pid', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, '_iid', [_mobx.observable], {
enumerable: true,
initializer: null
}), _applyDecoratedDescriptor(_class.prototype, 'viewModel', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'viewModel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_curView', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, '_curView'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'init', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'init'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'load', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'load'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'loadView', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'loadView'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'closeView', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'closeView'), _class.prototype)), _class);
exports.default = ViewController;
//# sourceMappingURL=ViewController.js.map