Stat.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.xDesktop.requireApp("process.Xform", "widget.View", null, false);
  3. /** @class Stat 统计组件。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var stat = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var stat = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process|CMS|Portal}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.Stat = MWF.APPStat = new Class(
  16. /** @lends MWF.xApplication.process.Xform.Stat# */
  17. {
  18. Extends: MWF.APP$Module,
  19. options: {
  20. /**
  21. * 组件异步加载完成触发.
  22. * @event MWF.xApplication.process.Xform.Stat#loadStat
  23. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  24. */
  25. "moduleEvents": ["load", "queryLoad", "postLoad", "loadStat"]
  26. },
  27. _loadUserInterface: function(){
  28. this.node.empty();
  29. },
  30. _afterLoaded: function(){
  31. this.node.setStyle("min-height", "100px");
  32. this.loadStat();
  33. },
  34. active: function(){
  35. if (this.stat) this.stat.loadStatData();
  36. },
  37. reload: function(){
  38. this.active();
  39. },
  40. loadStat: function(){
  41. if (this.json.queryStat){
  42. var viewJson = {
  43. "application": this.json.queryStat.appName,
  44. "statName": this.json.queryStat.name,
  45. "isChart": (this.json.isChart!="no"),
  46. "isLegend": (this.json.isLegend!="no"),
  47. "isTable": (this.json.isTable!="no")
  48. };
  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. });
  63. }.bind(this));
  64. }
  65. },
  66. /**
  67. * @summary 获取统计数据。
  68. * @return {Ojbect} 统计数据.
  69. * @example
  70. * var data = this.form.get("fieldId").getData();
  71. * @return {Boolean} 是否通过校验
  72. */
  73. getData: function(){
  74. if (!this.stat) return null;
  75. if (!this.stat.stat) return null;
  76. return this.stat.stat.data;
  77. }
  78. });