Eldropdown.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. o2.xDesktop.requireApp("process.Xform", "$Elinput", null, false);
  2. /** @class Eldropdown 基于Element UI的下拉菜单组件。本组件不往后台存数据。
  3. * @o2cn 下拉菜单
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var input = this.form.get("name"); //获取组件
  8. * //方法2
  9. * var input = this.target; //在组件事件脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process|CMS|Portal}
  13. * @hideconstructor
  14. * @see {@link https://element.eleme.cn/#/zh-CN/component/dropdown|Element UI Dropdown 下拉菜单}
  15. */
  16. MWF.xApplication.process.Xform.Eldropdown = MWF.APPEldropdown = new Class(
  17. /** @lends o2.xApplication.process.Xform.Eldropdown# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APP$Elinput,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad"],
  23. /**
  24. * split-button 为 true 时,点击左侧按钮的回调
  25. * @event MWF.xApplication.process.Xform.Eldropdown#click
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/dropdown|下拉菜单组件的Events章节}
  27. */
  28. /**
  29. * 点击菜单项触发的事件回调。this.event[0]指向dropdown-item 的指令(选项的command值)
  30. * @event MWF.xApplication.process.Xform.Eldropdown#focus
  31. * @see {@link https://element.eleme.cn/#/zh-CN/component/dropdown|下拉菜单组件的Events章节}
  32. */
  33. /**
  34. * 下拉框出现/隐藏时触发。出现则this.event[0]为 true,隐藏则this.event[0]为 false
  35. * @event MWF.xApplication.process.Xform.Eldropdown#change
  36. * @see {@link https://element.eleme.cn/#/zh-CN/component/dropdown|下拉菜单组件的Events章节}
  37. */
  38. "elEvents": ["click", "command", "visible-change"]
  39. },
  40. __setReadonly: function(data){
  41. if (this.isReadonly()) {
  42. this.node.set("text", data);
  43. if( this.json.elProperties ){
  44. this.node.set(this.json.elProperties );
  45. }
  46. if (this.json.elStyles){
  47. this.node.setStyles( this._parseStyles(this.json.elStyles) );
  48. }
  49. }
  50. },
  51. _loadNode: function(){
  52. if (this.isReadonly()) this.json.disabled = true;
  53. this._loadNodeEdit();
  54. },
  55. _loadNodeEdit: function(){
  56. var id = (this.json.id.indexOf("..")!==-1) ? this.json.id.replace(/\.\./g, "_") : this.json.id;
  57. this.json["$id"] = (id.indexOf("-")!==-1) ? id.replace(/-/g, "_") : id;
  58. this.node.appendHTML(this._createElementHtml(), "before");
  59. var input = this.node.getPrevious();
  60. this.node.destroy();
  61. this.node = input;
  62. this.node.setStyle("opacity", 0);
  63. this.node.set({
  64. "id": this.json.id,
  65. "MWFType": this.json.type
  66. });
  67. this.node.addClass("o2_vue");
  68. this._createVueApp();
  69. },
  70. _appendVueData: function(){
  71. if (!this.json.size) this.json.size = "";
  72. if (!this.json.placement) this.json.placement = "bottom-end";
  73. if (!this.json.trigger) this.json.trigger = "hover";
  74. if (o2.typeOf(this.json.hideOnClick)!=="boolean") this.json.hideOnClick = true;
  75. if (o2.typeOf(this.json.splitButton)!=="boolean") this.json.splitButton = false;
  76. if (!this.json.buttonType) this.json.buttonType = "";
  77. if (!this.json.showTimeout) this.json.showTimeout = 250;
  78. if (!this.json.hideTimeout) this.json.hideTimeout = 150;
  79. // if(o2.typeOf(this.json.disabled)!=="boolean")this.json.disabled = this.isReadonly();
  80. },
  81. _afterMounted: function(el){
  82. this.node = el;
  83. this.node.setStyle("opacity", 1);
  84. this.node.set({
  85. "id": this.json.id,
  86. "MWFType": this.json.type
  87. });
  88. this._loadVueCss();
  89. this._loadDomEvents();
  90. this._afterLoaded();
  91. this.fireEvent("postLoad");
  92. this.fireEvent("load");
  93. },
  94. _createElementHtml: function() {
  95. var html = "<el-dropdown";
  96. // html += " :readonly=\"readonly\"";
  97. html += " :placement=\"placement\"";
  98. html += " :trigger=\"trigger\"";
  99. html += " :hide-on-click=\"hideOnClick\"";
  100. html += " :size=\"size\"";
  101. html += " :disabled=\"disabled\"";
  102. if( this.json.showButton && this.json.splitButton ){
  103. html += " :split-button=\"splitButton\"";
  104. html += " :type=\"buttonType\"";
  105. }
  106. this.options.elEvents.forEach(function(k){
  107. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  108. });
  109. if (this.json.elProperties){
  110. Object.keys(this.json.elProperties).forEach(function(k){
  111. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  112. }, this);
  113. }
  114. if (this.json.elStyles) html += " :style=\"elStyles\"";
  115. html += ">";
  116. if (this.json.vueSlot){
  117. html += this.json.vueSlot;
  118. }else{
  119. html += this.getButtonHtml();
  120. }
  121. html += this.getItemHtml();
  122. html += "</el-dropdown>";
  123. return html;
  124. },
  125. getItemHtml: function(){
  126. var html = " <el-dropdown-menu slot=\"dropdown\">";
  127. var datToHtml = function (data) {
  128. var command = data.command ? (" command=\""+data.command+"\"") : "";
  129. var disabled = ( data.disabled && (data.disabled==="true" || data.disabled===true) ) ? " disabled" : "";
  130. var divided = ( data.divided && (data.divided==="true" || data.divided===true) ) ? " divided" : "";
  131. var icon = data.icon ? (" icon=\""+data.icon+"\"") : "";
  132. html += " <el-dropdown-item" + command + disabled + divided + icon + ">"+data.label+"</el-dropdown-item>";
  133. };
  134. if(this.json.dataType === "json"){
  135. this.json.dataJson.each(function(d){
  136. datToHtml(d)
  137. })
  138. }else if(this.json.dataScript && this.json.dataScript.code){
  139. var data = this.form.Macro.exec(((this.json.dataScript) ? this.json.dataScript.code : ""), this);
  140. if( data && o2.typeOf(data) !== "array" )data = [data];
  141. if( data )data.each(function(d){
  142. datToHtml(d)
  143. })
  144. }
  145. html += "</el-dropdown-menu>";
  146. return html;
  147. },
  148. getButtonHtml: function(){
  149. if( this.json.showButton ){
  150. if( this.json.splitButton ) {
  151. return this.json.text || MWF.xApplication.process.Xform.LP.pleaseSelect;
  152. }else{
  153. return "<el-button type=\""+this.json.buttonType+"\" size=\""+this.json.size+"\">"+ ( this.json.text || MWF.xApplication.process.Xform.LP.pleaseSelect ) +
  154. "<i class=\"el-icon-arrow-down el-icon--right\"></i>"+
  155. "</el-button>";
  156. }
  157. }else{
  158. return " <span class=\"el-dropdown-link\">"+ ( this.json.text || MWF.xApplication.process.Xform.LP.pleaseSelect ) +
  159. "<i class=\"el-icon-arrow-down el-icon--right\"></i>"+
  160. "</span>";
  161. }
  162. }
  163. });