Stat.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @category FormComponents
  12. * @hideconstructor
  13. */
  14. MWF.xApplication.process.Xform.Stat = MWF.APPStat = new Class(
  15. /** @lends MWF.xApplication.process.Xform.Stat# */
  16. {
  17. Extends: MWF.APP$Module,
  18. options: {
  19. /**
  20. * 组件异步加载完成触发.
  21. * @event MWF.xApplication.process.Xform.Stat#loadStat
  22. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  23. */
  24. "moduleEvents": ["load", "queryLoad", "postLoad", "loadStat"]
  25. },
  26. _loadUserInterface: function(){
  27. this.node.empty();
  28. },
  29. _afterLoaded: function(){
  30. this.node.setStyle("min-height", "100px");
  31. this.loadStat();
  32. },
  33. active: function(){
  34. if (this.stat) this.stat.loadStatData();
  35. },
  36. reload: function(){
  37. this.active();
  38. },
  39. loadStat: function(){
  40. if (this.json.queryStat){
  41. var viewJson = {
  42. "application": this.json.queryStat.appName,
  43. "statName": this.json.queryStat.name,
  44. "isChart": (this.json.isChart!="no"),
  45. "isLegend": (this.json.isLegend!="no"),
  46. "isTable": (this.json.isTable!="no")
  47. };
  48. MWF.xDesktop.requireApp("query.Query", "Statistician", function(){
  49. /**
  50. * @summary Statistician组件,平台使用该组件执行统计的逻辑
  51. * @member {MWF.xApplication.query.Query.Statistician}
  52. * @example
  53. * //可以在脚本中获取该组件
  54. * var field = this.form.get("moduleId").stat; //获取组件对象
  55. */
  56. this.stat = new MWF.xApplication.query.Query.Statistician(this.form.app, this.node, viewJson, {
  57. "resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  58. "onLoaded": function(){
  59. this.fireEvent("loadStat");
  60. }.bind(this)
  61. });
  62. }.bind(this));
  63. }
  64. },
  65. /**
  66. * @summary 获取统计数据。
  67. * @return {Ojbect} 统计数据.
  68. * @example
  69. * var data = this.form.get("fieldId").getData();
  70. * @return {Boolean} 是否通过校验
  71. */
  72. getData: function(){
  73. if (!this.stat) return null;
  74. if (!this.stat.stat) return null;
  75. return this.stat.stat.data;
  76. }
  77. });