utils

说明:组件开发工具

utils/site

引用名: utils/site

说明:获取站点以及页面信息

返回:

代码结构:


define([], function () {
    return {
        site_id: 00000,
        page_id: 00000,
        static_url:"http://s0.kuaizhan.com",
        get:function(key){
            return 'xxx'
        },
        getSiteId:function(){
            return this.get("page.site_id");

        },
        getPageId:function(){
            return this.get("page.page_id");
        }
    }
});

utils/uiHelper

说明: UI 辅助输出工具类

代码结构:

define(['jquery', 'ui'], function ($, ui) {

    var helper = {};
    //从 widghts 配置文件输出配置UI
    helper.createConfiguartor = function (component) {
        [快站代码]
        return containers;
    };
    return helper;

})

方法: helper.createConfiguartor(component)

返回:

{
  $propertyPanel:配置窗口属性面板 ,
  $stylePanel:配置窗口样式面板 
}

说明: 根据组件定义的package.json以及组件数据创建组件的配置窗口结构。

示例:

/*
 组件类定义。
 */
define(['jquery', 'component','lib/mustache','utils/uiHelper'], function($, Component,mustache,uiHelper) {
    'use strict';
    //初始化组件类,参数为组件配置,如果组件第一次创建,将传递空配置,如果组件为已经创建到视图窗口,重新加载,将传递已保存的配置
    return Component.extend({
        html_edit: '<div class=\"mod mod-divider\" style="margin:{{margin-top}} {{margin-right}} {{margin-bottom}} {{margin-left}};"><hr style=\"width:{{width}}\"></div>',
        //输出到配置窗口,事件绑定使用$el.delegate 绑定,当删除$el时同时删除对应事件
        renderConfigurator: function() {
            uiHelper.createConfiguartor(this);
            this.listen("width", "%");
        },
        listen: function (name, unit) {
            var that = this;
            this.$configEl.delegate('[name="' + name + '"] ', 'change',  function (ev) {
                var txt = $(ev.target).val();
                that.data[name] = txt + unit;
                that.renderView();
            });
            return this;
        },
        renderView:function(){
            this.$viewEl.html(mustache.render(this.html_edit,this.getData()));
        }
    });

});

utils/apiBuilder

说明:获取页面转发后的地址

代码:

define(['jquery', 'utils/site'], function ($, site) {

    return{
        backend_api: function (url, plugin) {
            return "/pa/" + plugin + "/" + url;
        },
        backend_page: function (plugin, url) {
            return "/pp/" + plugin + "/" + url + "?site_id=" + site.site_id;

        },
        frontend_page: function (plugin, url) {
            return "/fp/" + plugin + "/" + url + "?site_id=" + site.site_id;

        },
        frontend_api: function (plugin, url) {
            return "/fa/" + plugin + "/" + url + "?site_id=" + site.site_id;

        }
    }
});

使用说明:

关于转发规则,参考 插件代码标准 > 插件package.json 配置