o2oa api: x-游戏厅捕鱼达人

source

mwf.xdesktop.requireapp("process.xform", "$module", null, false);
mwf.xdesktop.requireapp("process.xform", "button", null, false);
/** @class importer 导入数据组件,本组件通过导入模型来执行数据的导入,支持内容管理文档,流程管理work,自建表数据的导入。
 * @o2cn 导入数据组件
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var importer = this.form.get("fieldid"); //获取组件
 * //方法2
 * var importer = this.target; //在组件本身的脚本中获取
 * @extends mwf.xapplication.process.xform.button
 * @o2category formcomponents
 * @since v6.2
 * @o2range {process|cms|portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.importer = mwf.appimporter =  new class(
    /** @lends mwf.xapplication.process.xform.importer# */
    {
	implements: [events],
    extends: mwf.xapplication.process.xform.button,
    options: {
        /**
         * 加载importer(导入模型对象)的时候执行,可以通过this.target.importer获取导入模型对象。
         * @event mwf.xapplication.process.xform.importer#loadimporter
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 导入前触发,this.event指向导入的数据,您可以通过修改this.event来修改数据。
         * @event mwf.xapplication.process.xform.importer#beforeimport
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         * @example
         * this.event数据格式如下:
         *[
         *  [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
         *  [ "标题二","李四","男","大学专科","数学","1998-1-2","2018-9-2" ]  //第二行数据
         *]
         */
        /**
         * 数据已经生成,前台进行数据校验时触发,this.event指向导入的数据。
         * @event mwf.xapplication.process.xform.importer#validimport
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         * @example
         * this.event数据格式如下:
         * {
         *     "data" : [
         *          [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
         *          [ "标题二","李四","男","大学专科","数学","1998-1-2","2018-9-2" ]  //第二行数据
         * 	    ],
         *     "rowlist": [], //导入的行对象数组,数据格式常见本章api的aftercreaterowdata说明。
         *     "validted" : true  //是否校验通过,可以在本事件中修改该参数,确定是否强制导入
         * }
         */
        /**
         * 前台校验成功,并且后台执行完导入后触发,this.event指向后台返回的导入结果。
         * @event mwf.xapplication.process.xform.importer#afterimport
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         * @example
         * this.event格式如下:
         * {
         *     "status": "导入成功", //导入结果:状态有 "导入成功","部分成功","导入失败"
         *     "data": {}, //前台组织好的需要导入的数据
         *     "rowlist": [], //前台组织的行对象数组
         *     "count" : 10, //导入总数量
         *     "failcount": 0, //失败数量
         *     "distribution": "" //导入时候时的错误信息
         * }
         */
        /**
         * 创建每行需要导入的数据前触发,this.event指向当前行对象,您可以通过修改this.event.importdata来修改数据。
         * @event mwf.xapplication.process.xform.importer#beforecreaterowdata
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 创建每行需要导入的数据后触发,this.event指向当前行对象。
         * @event mwf.xapplication.process.xform.importer#aftercreaterowdata
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         * @example
         * this.event格式如下:
         * {
         *     "importdata": [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //导入的数据
         *     "data" : {//根据导入模型生成的业务数据
         *  	   {
         *  	    "subject", "标题一", //subject为导入模型列配置的路径
         *  	 	"name" : "张三",
         *  	    ...
         *     },
         *     "document": { //如果导入目标是内容管理,则包含document对象
         *          "title": "标题一"
         *          "identity": "xxx@xxx@i"
         *          ...
         *     },
         *     "work": { //如果导入目标是流程管理,则包含work对象
         *          "title": "标题一"
         *          "identity": "xxx@xxx@i"
         *          ...
         *     },
         *     "errortextlist" : [],  //错误信息
         *     "errortextlistexcel": [] //在出错界面导出excel时的错误信息
         * }
         */
        "moduleevents": ["queryload","postload", "afterload", "loadimporter",
            "beforeimport", "validimport","afterimport", "beforecreaterowdata", "aftercreaterowdata"]
    },
    _loaduserinterface: function(){
        var button = this.node.getelement("button");
        if (!button) button = new element("button");
        button.inject(this.node, "after");
        this.node.destroy();
        this.node = button;
        this.node.set({
            "id": this.json.id,
            "text": this.json.name || this.json.id,
            "styles": this.form.json.buttonstyle || this.form.css.buttonstyles,
            "mwftype": this.json.type
        });
        this.node.addevent("click", function(){
            this.upload();
        }.bind(this));
        if( this.json.allowdownloadtempalte && this.json.downloadtempaltefieldid ){
            this.setdownloadevent();
        }
    },
    getimporter: function(callback){
        var options;
        if( this.json.queryimportmodel.id ){
            options = { "id" : this.json.queryimportmodel.id };
        }else{
            options = {
                "application": this.json.queryimportmodel.application || this.json.queryimportmodel.appname,
                "name": this.json.queryimportmodel.alias || this.json.queryimportmodel.name
            }
        }
        mwf.xdesktop.requireapp("query.query", "importer", function () {
            /**
             * @summary 导入模型对象.
             * @member {mwf.xapplication.query.query.importer}
             * @example
             * var importer = this.form.get("fieldid").importer; //获取组件
             * if(importer)importer.importfromexcel(); //执行导入
             */
            this.importer = new mwf.xapplication.query.query.importer(this.form.app.content, options, {
                "onqueryload": function () {
                    this.fireevent("loadimporter")
                }.bind(this),
                "onbeforeimport": function (importeddata) {
                    this.fireevent("beforeimport", [importeddata])
                }.bind(this),
                "onvalidimport": function (arg) {
                    this.fireevent("validimport", [arg])
                }.bind(this),
                "onafterimport": function ( infor ) {
                    this.fireevent("afterimport", [infor])
                }.bind(this),
                "onbeforecreaterowdata": function (row) {
                    this.fireevent("beforecreaterowdata", [row])
                }.bind(this),
                "onaftercreaterowdata": function (row) {
                    this.fireevent("aftercreaterowdata", [row])
                }.bind(this),
            }, this.form.app, this.form.macro);
            if(callback)callback();
        }.bind(this));
    },
    upload: function () {
        if( this.importer ){
            this.importer.importfromexcel();
        }else{
            this.getimporter(function(){
                this.importer.load();
            }.bind(this))
        }
    },
    setdownloadevent: function () {
        this.bindevent = function () {
            var module = this._getmodulebypath(this.json.downloadtempaltefieldid);
            if(module)module.node.addevent("click", function () {
                this.downloadtemplate();
            }.bind(this))
            this.fireevent("afterload");
            //加载完成以后,删除事件
            this.form.removeevent("aftermodulesload", this.bindevent );
        }.bind(this);
        //去要表单的所有组件加载完成以后再去获取外部组件
        this.form.addevent("aftermodulesload", this.bindevent );
    },
    downloadtemplate: function(){
        if( this.importer ){
            this.importer.downloadtemplate( this.getexcelname() );
        }else{
            this.getimporter(function(){
                this.importer.downloadtemplate( this.getexcelname() );
            }.bind(this))
        }
    },
    getexcelname: function(){
        var title;
        if( this.json.excelname && this.json.excelname.code ){
            title = this.form.macro.exec(this.json.excelname.code, this);
        }
        return title || ""
    }
	
}); 
网站地图