UNPKG

mutants-appfx

Version:

appfx module

104 lines (87 loc) 1.95 kB
import { clientType } from 'mutants-microfx'; import { action, computed, observable } from 'mobx'; import uifunction from '../UIFunction'; export default class BizController { module; viewType; // TODO 即将废弃 viewModels; data; blocks; ui; // 统一的UI控制器 @observable _pid; @observable _iid; @computed get viewModel() { const vo = this.viewModels.find(it => it.iid === this._iid); if (!vo) { return null; } return vo.viewModel; } get uifunction() { return this.viewModel ? uifunction.get(this.viewModel.mid) : null; } get clientType() { return clientType; } constructor(module, dataModel, ui, viewType, viewModels, blocks) { this.module; this.ui = ui; this.viewType = viewType; this.blocks = blocks; if (viewModels) { this._init(viewModels); } if (dataModel) { this._initData(dataModel); } } @action async _curView(iid, pid) { if (this._iid !== iid) { this._pid = pid; this._iid = iid; await this.loadView(); } } async _init(viewModels) { this.viewModels = viewModels; } async _initData(dataModel) { // 加载表单数据 this.data = dataModel; await this.init(); if (this.data.ID) { await this.load(); } } async executeBlock(name, ctx) { const block = this.blocks[name]; if (!block) { throw new Error(name + ' block not found'); } if (typeof block.execute === 'function') { await block.execute(ctx); return; } else if (typeof block === 'function') { const processors = block({ data: this.data }).asyncProcessors; for (const processor of processors) { await processor.init(ctx).doExecute(); } } else { throw new Error(name + ' block not support!'); } } @action async init() { } @action async load() { } @action async loadView() { } }