mwf.xdesktop.requireapp("process.xform", "$module", null, false);
//mwf.xdesktop.requireapp("process.xform", "widget.view", null, false);
/** @class stat 统计组件。
* @o2cn 统计组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var stat = this.form.get("fieldid"); //获取组件
* //方法2
* var stat = this.target; //在组件本身的脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.stat = mwf.appstat = new class(
/** @lends mwf.xapplication.process.xform.stat# */
{
extends: mwf.app$module,
options: {
/**
* 组件异步加载完成触发.
* @event mwf.xapplication.process.xform.stat#loadstat
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 图表加载完成触发.
* @event mwf.xapplication.process.xform.stat#afterloadstat
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["load", "queryload", "postload", "loadstat", "loadchart"]
},
_loaduserinterface: function(){
this.node.empty();
},
_afterloaded: function(){
this.node.setstyle("min-height", "100px");
this.loadstat();
},
active: function(){
if (this.stat) this.stat.loadstatdata();
},
reload: function(){
this.active();
},
loadstat: function( json ){
var viewjson = object.merge(this.getdefaultjson(), json || {});
if ( viewjson.application && viewjson.statname ){
mwf.xdesktop.requireapp("query.query", "statistician", function(){
/**
* @summary statistician组件,平台使用该组件执行统计的逻辑
* @member {mwf.xapplication.query.query.statistician}
* @example
* //可以在脚本中获取该组件
* var field = this.form.get("fieldid").stat; //获取组件对象
*/
this.stat = new mwf.xapplication.query.query.statistician(this.form.app, this.node, viewjson, {
"resizenode": (this.node.getstyle("height").tostring().tolowercase()!=="auto" && this.node.getstyle("height").toint()>0),
"onloaded": function(){
this.fireevent("loadstat");
}.bind(this),
"onloadchart": function(){
this.fireevent("loadchart");
}.bind(this)
});
}.bind(this));
}
},
getdefaultjson: function(){
if( this.json.querystat ){
return {
"application": this.json.querystat.appname,
"statname": this.json.querystat.name,
"ischart": (this.json.ischart!=="no"),
"islegend": (this.json.islegend!=="no"),
"istable": (this.json.istable!=="no"),
"isrowtocolumn": (this.json.isrowtocolumn!=="no"),
"tablenodestyles": this.json.tablenodestyles,
"chartnodestyles": this.json.chartnodestyles
};
}else{
return {};
}
},
/**
* @summary 重新加载统计。
* @param json {object} 加载选项
* [{
* "application": "", //数据中心应用名称
* "statname": "", //统计名称
* "ischart": true, //是否显示图表
* "islegend": true, //是否显示图例
* "istable": true, //是否显示表格
* "isrowtocolumn": true, //是否显示行列转换
* }]
* @example
* this.form.get("fieldid").reloadstat({
* "application": "数据中心应用名称",
* "statname": "统计名称"
* });
* @return {boolean} 是否通过校验
*/
reloadstat: function(json){
var viewjson = object.merge(this.getdefaultjson(), json || {});
if( viewjson.application && viewjson.statname ){
if( this.stat ){
this.stat.reload(viewjson);
}else{
this.loadstat(viewjson);
}
}
},
/**
* @summary 获取统计数据。
* @return {ojbect} 统计数据.
* @example
* var data = this.form.get("fieldid").getdata();
* @return {boolean} 是否通过校验
*/
getdata: function(){
if (!this.stat) return null;
if (!this.stat.stat) return null;
return this.stat.stat.data;
}
});
source