Stat.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.xDesktop.requireApp("process.Xform", "widget.View", null, false);
  3. /** @class Stat 统计组件。
  4. * @o2cn 统计组件
  5. * @example
  6. * //可以在脚本中获取该组件
  7. * //方法1:
  8. * var stat = this.form.get("fieldId"); //获取组件
  9. * //方法2
  10. * var stat = this.target; //在组件本身的脚本中获取
  11. * @extends MWF.xApplication.process.Xform.$Module
  12. * @o2category FormComponents
  13. * @o2range {Process|CMS|Portal}
  14. * @hideconstructor
  15. */
  16. MWF.xApplication.process.Xform.Stat = MWF.APPStat = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Stat# */
  18. {
  19. Extends: MWF.APP$Module,
  20. options: {
  21. /**
  22. * 组件异步加载完成触发.
  23. * @event MWF.xApplication.process.Xform.Stat#loadStat
  24. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  25. */
  26. /**
  27. * 图表加载完成触发.
  28. * @event MWF.xApplication.process.Xform.Stat#afterLoadStat
  29. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  30. */
  31. "moduleEvents": ["load", "queryLoad", "postLoad", "loadStat", "loadChart"]
  32. },
  33. _loadUserInterface: function(){
  34. this.node.empty();
  35. },
  36. _afterLoaded: function(){
  37. this.node.setStyle("min-height", "100px");
  38. this.loadStat();
  39. },
  40. active: function(){
  41. if (this.stat) this.stat.loadStatData();
  42. },
  43. reload: function(){
  44. this.active();
  45. },
  46. loadStat: function( json ){
  47. var viewJson = Object.merge(this.getDefaultJson(), json || {});
  48. if ( viewJson.application && viewJson.statName ){
  49. MWF.xDesktop.requireApp("query.Query", "Statistician", function(){
  50. /**
  51. * @summary Statistician组件,平台使用该组件执行统计的逻辑
  52. * @member {MWF.xApplication.query.Query.Statistician}
  53. * @example
  54. * //可以在脚本中获取该组件
  55. * var field = this.form.get("fieldId").stat; //获取组件对象
  56. */
  57. this.stat = new MWF.xApplication.query.Query.Statistician(this.form.app, this.node, viewJson, {
  58. "resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  59. "onLoaded": function(){
  60. this.fireEvent("loadStat");
  61. }.bind(this),
  62. "onLoadChart": function(){
  63. this.fireEvent("loadChart");
  64. }.bind(this)
  65. });
  66. }.bind(this));
  67. }
  68. },
  69. getDefaultJson: function(){
  70. if( this.json.queryStat ){
  71. return {
  72. "application": this.json.queryStat.appName,
  73. "statName": this.json.queryStat.name,
  74. "isChart": (this.json.isChart!=="no"),
  75. "isLegend": (this.json.isLegend!=="no"),
  76. "isTable": (this.json.isTable!=="no"),
  77. "isRowToColumn": (this.json.isRowToColumn!=="no"),
  78. "tableNodeStyles": this.json.tableNodeStyles,
  79. "chartNodeStyles": this.json.chartNodeStyles
  80. };
  81. }else{
  82. return {};
  83. }
  84. },
  85. /**
  86. * @summary 重新加载统计。
  87. * @param json {Object} 加载选项
  88. * <pre><code class='language-js'>[{
  89. * "application": "", //数据中心应用名称
  90. * "statName": "", //统计名称
  91. * "isChart": true, //是否显示图表
  92. * "isLegend": true, //是否显示图例
  93. * "isTable": true, //是否显示表格
  94. * "isRowToColumn": true, //是否显示行列转换
  95. * }]</code></pre>
  96. * @example
  97. * this.form.get("fieldId").reloadStat({
  98. * "application": "数据中心应用名称",
  99. * "statName": "统计名称"
  100. * });
  101. * @return {Boolean} 是否通过校验
  102. */
  103. reloadStat: function(json){
  104. var viewJson = Object.merge(this.getDefaultJson(), json || {});
  105. if( viewJson.application && viewJson.statName ){
  106. if( this.stat ){
  107. this.stat.reload(viewJson);
  108. }else{
  109. this.loadStat(viewJson);
  110. }
  111. }
  112. },
  113. /**
  114. * @summary 获取统计数据。
  115. * @return {Ojbect} 统计数据.
  116. * @example
  117. * var data = this.form.get("fieldId").getData();
  118. * @return {Boolean} 是否通过校验
  119. */
  120. getData: function(){
  121. if (!this.stat) return null;
  122. if (!this.stat.stat) return null;
  123. return this.stat.stat.data;
  124. }
  125. });