Tree.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * @o2category FormComponents
  38. * @o2range {Process|CMS|Portal}
  39. * @hideconstructor
  40. */
  41. MWF.xApplication.process.Xform.Tree = MWF.APPTree = new Class(
  42. /** @lends MWF.xApplication.process.Xform.Tree# */
  43. {
  44. Extends: MWF.APP$Module,
  45. options: {
  46. /**
  47. * 异步加载树前执行。this.target指向当前组件。
  48. * @event MWF.xApplication.process.Xform.Tree#beforeLoadTree
  49. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  50. */
  51. /**
  52. * 异步加载树后执行。this.target指向当前组件。
  53. * @event MWF.xApplication.process.Xform.Tree#afterLoadTree
  54. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  55. */
  56. /**
  57. * 加载树的叶子前执行。this.target指向加载的叶子。
  58. * @event MWF.xApplication.process.Xform.Tree#beforeLoadTreeNode
  59. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  60. */
  61. /**
  62. * 加载树的叶子后执行。this.target指向加载的叶子。
  63. * @event MWF.xApplication.process.Xform.Tree#afterLoadTreeNode
  64. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  65. */
  66. /**
  67. * 加载树的叶子后执行。this.target指向加载的叶子。
  68. * @event MWF.xApplication.process.Xform.Tree#expand
  69. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  70. */
  71. /**
  72. * 折叠节点的时候执行。this.target指向被折叠的节点。
  73. * @event MWF.xApplication.process.Xform.Tree#collapse
  74. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  75. */
  76. /**
  77. * 选中节点前执行。此时原来被选中的节点还未取消。this.target指向选中的节点。
  78. * @event MWF.xApplication.process.Xform.Tree#beforeSelect
  79. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  80. */
  81. /**
  82. * 选中节点后执行。this.target指向选中的节点。
  83. * @event MWF.xApplication.process.Xform.Tree#afterSelect
  84. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  85. */
  86. "moduleEvents": ["load", "queryLoad", "postLoad", "beforeLoadTree", "afterLoadTree", "beforeLoadTreeNode", "afterLoadTreeNode", "expand", "collapse", "beforeSelect", "afterSelect"]
  87. },
  88. _loadUserInterface: function(){
  89. this.node.empty();
  90. MWF.require("MWF.widget.Tree", function(){
  91. var options = {"style":"form"};
  92. if( this.json.events && typeOf(this.json.events) === "object" ){
  93. [
  94. { "beforeLoadTree" : "onQueryLoad" },
  95. { "afterLoadTree" : "onPostLoad" },
  96. { "beforeLoadTreeNode" : "onBeforeLoadTreeNode" },
  97. { "afterLoadTreeNode" : "onAfterLoadTreeNode" },
  98. { "expand" : "onPostExpand" },
  99. { "collapse" : "onPostCollapse" },
  100. { "beforeSelect" : "onBeforeSelect" },
  101. { "afterSelect" : "onAfterSelect" }
  102. ].each( function (obj) {
  103. var moduleEvent = Object.keys(obj)[0];
  104. var treeEvent = obj[moduleEvent];
  105. if( this.json.events[moduleEvent] && this.json.events[moduleEvent].code ){
  106. options[treeEvent] = function( target ){
  107. return this.form.Macro.fire(this.json.events[moduleEvent].code, target || this);
  108. }.bind(this)
  109. }
  110. }.bind(this));
  111. }
  112. /**
  113. * @summary 树组件,平台使用该组件实现树的功能,该组件为异步加载
  114. * @member {o2.widget.Tree}
  115. * @example
  116. * //可以在脚本中获取该组件
  117. * var tree = this.form.get("fieldId").tree; //获取组件对象
  118. * var children = tree.children[]; //获取第一层树叶
  119. */
  120. this.tree = new MWF.widget.Tree(this.node, options);
  121. this.tree.form = this.form;
  122. this._setTreeWidgetStyles();
  123. var treeData = this.json.data;
  124. if (this.json.dataType == "script") treeData = this.form.Macro.exec(((this.json.dataScript) ? this.json.dataScript.code : ""), this);
  125. this.tree.load(treeData);
  126. }.bind(this));
  127. },
  128. _setTreeWidgetStyles: function(){
  129. this.tree.css.areaNode = this.json.areaNodeStyle;
  130. this.tree.css.treeItemNode = this.json.treeItemNodeStyle;
  131. this.tree.css.textDivNode = this.json.textDivNodeStyle;
  132. this.tree.css.textDivNodeSelected = this.json.textDivNodeSelectedStyle;
  133. }
  134. });