Tree.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /**树组件数据结构
  3. * @typedef {Object} TreeData
  4. * @example
  5. * [
  6. * {
  7. * "expand": true, //是否默认展开
  8. * "title": "", //鼠标移上叶子节点的文字
  9. * "text": "根节点", //叶子节点的文字
  10. * "action": "", //执行的脚本
  11. * "default": true, //是否默认选中
  12. * "icon": "folder.png", //图标
  13. * "sub": [ //改节点的子节点
  14. * {
  15. * "expand": true,
  16. * "title": "",
  17. * "text": "[none]",
  18. * "action": "",
  19. * "default": false,
  20. * "icon": "folder.png",
  21. * "sub": []
  22. * },
  23. * ...
  24. * ]
  25. * }
  26. * ]
  27. */
  28. /** @class Tree 树组件。
  29. * @example
  30. * //可以在脚本中获取该组件
  31. * //方法1:
  32. * var datagrid = this.form.get("name"); //获取组件
  33. * //方法2
  34. * var datagrid = this.target; //在组件事件脚本中获取
  35. * @see {@link TreeData|树组件数据结构}
  36. * @extends MWF.xApplication.process.Xform.$Module
  37. * @category FormComponents
  38. * @hideconstructor
  39. */
  40. MWF.xApplication.process.Xform.Tree = MWF.APPTree = new Class(
  41. /** @lends MWF.xApplication.process.Xform.Tree# */
  42. {
  43. Extends: MWF.APP$Module,
  44. options: {
  45. /**
  46. * 异步加载树前执行。this.target指向当前组件。
  47. * @event MWF.xApplication.process.Xform.Tree#beforeLoadTree
  48. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  49. */
  50. /**
  51. * 异步加载树后执行。this.target指向当前组件。
  52. * @event MWF.xApplication.process.Xform.Tree#afterLoadTree
  53. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  54. */
  55. /**
  56. * 加载树的叶子前执行。this.target指向加载的叶子。
  57. * @event MWF.xApplication.process.Xform.Tree#beforeLoadTreeNode
  58. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  59. */
  60. /**
  61. * 加载树的叶子后执行。this.target指向加载的叶子。
  62. * @event MWF.xApplication.process.Xform.Tree#afterLoadTreeNode
  63. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  64. */
  65. /**
  66. * 加载树的叶子后执行。this.target指向加载的叶子。
  67. * @event MWF.xApplication.process.Xform.Tree#expand
  68. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  69. */
  70. /**
  71. * 折叠节点的时候执行。this.target指向被折叠的节点。
  72. * @event MWF.xApplication.process.Xform.Tree#collapse
  73. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  74. */
  75. /**
  76. * 选中节点前执行。此时原来被选中的节点还未取消。this.target指向选中的节点。
  77. * @event MWF.xApplication.process.Xform.Tree#beforeSelect
  78. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  79. */
  80. /**
  81. * 选中节点后执行。this.target指向选中的节点。
  82. * @event MWF.xApplication.process.Xform.Tree#afterSelect
  83. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  84. */
  85. "moduleEvents": ["load", "queryLoad", "postLoad", "beforeLoadTree", "afterLoadTree", "beforeLoadTreeNode", "afterLoadTreeNode", "expand", "collapse", "beforeSelect", "afterSelect"]
  86. },
  87. _loadUserInterface: function(){
  88. this.node.empty();
  89. MWF.require("MWF.widget.Tree", function(){
  90. var options = {"style":"form"};
  91. if( this.json.events && typeOf(this.json.events) === "object" ){
  92. [
  93. { "beforeLoadTree" : "onQueryLoad" },
  94. { "afterLoadTree" : "onPostLoad" },
  95. { "beforeLoadTreeNode" : "onBeforeLoadTreeNode" },
  96. { "afterLoadTreeNode" : "onAfterLoadTreeNode" },
  97. { "expand" : "onPostExpand" },
  98. { "collapse" : "onPostCollapse" },
  99. { "beforeSelect" : "onBeforeSelect" },
  100. { "afterSelect" : "onAfterSelect" }
  101. ].each( function (obj) {
  102. var moduleEvent = Object.keys(obj)[0];
  103. var treeEvent = obj[moduleEvent];
  104. if( this.json.events[moduleEvent] && this.json.events[moduleEvent].code ){
  105. options[treeEvent] = function( target ){
  106. return this.form.Macro.fire(this.json.events[moduleEvent].code, target || this);
  107. }.bind(this)
  108. }
  109. }.bind(this));
  110. }
  111. /**
  112. * @summary 树组件,平台使用该组件实现树的功能,该组件为异步加载
  113. * @member {o2.widget.Tree}
  114. * @example
  115. * //可以在脚本中获取该组件
  116. * var tree = this.form.get("fieldId").tree; //获取组件对象
  117. * var children = tree.children[]; //获取第一层树叶
  118. */
  119. this.tree = new MWF.widget.Tree(this.node, options);
  120. this.tree.form = this.form;
  121. this._setTreeWidgetStyles();
  122. var treeData = this.json.data;
  123. if (this.json.dataType == "script") treeData = this.form.Macro.exec(((this.json.dataScript) ? this.json.dataScript.code : ""), this);
  124. this.tree.load(treeData);
  125. }.bind(this));
  126. },
  127. _setTreeWidgetStyles: function(){
  128. this.tree.css.areaNode = this.json.areaNodeStyle;
  129. this.tree.css.treeItemNode = this.json.treeItemNodeStyle;
  130. this.tree.css.textDivNode = this.json.textDivNodeStyle;
  131. this.tree.css.textDivNodeSelected = this.json.textDivNodeSelectedStyle;
  132. }
  133. });