index.js 1.43 KB
define(["mec/score"], function (score) {
    'use strict';
    var req = new XMLHttpRequest();
    var result;
    
    req.open("GET", "/api/mobilemode/admin/designer/getModelAndViews", false); // 同步请求
    req.send(null);
    result = JSON.parse(req.responseText).data;
    
    var models = result.models; // 插件
    var views = result.views; // 需要特殊处理的插件view
    var paths = {}; // 插件路径配置

    models.forEach(function (type) {
        var modName = "mec/plugin/model/" + type;
        var path = "./appdesigner/mec/plugin/model/" + type;

        paths[modName] = path;
    });

    views.forEach(function (type) {
        var viewModName = "mec/plugin/view/" + type;
        var viewpath = "./appdesigner/mec/plugin/view/" + type;

        paths[viewModName] = viewpath;
    });

    require.config(paths);

    // 实例化配置
    var ioc = score.init({
        controller: "mec/plugin/controller",
        model: {
            module: function (compType) {
                if (!~models.indexOf(compType)) return "mec/plugin/model";

                return "mec/plugin/model/" + compType;
            },
            inherit: "mec/plugin/model"
        },
        view: {
            module: function (compType) {
                if (!~views.indexOf(compType)) return "";

                return "mec/plugin/view/" + compType;
            },
            inherit: "mec/plugin/view"

        }
    });

    return ioc;
});