Elswitch.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. o2.xDesktop.requireApp("process.Xform", "$Elinput", null, false);
  2. /** @class Elinput 基于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/switch|Element UI Switch 开关}
  15. */
  16. MWF.xApplication.process.Xform.Elswitch = MWF.APPElswitch = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Elswitch# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APP$Elinput,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad"],
  23. /**
  24. * switch 状态发生变化时的回调函数。this.event[0]为新状态的值
  25. * @event MWF.xApplication.process.Xform.Elswitch#change
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/switch|开关组件的的 Events章节}
  27. */
  28. "elEvents": ["change"]
  29. },
  30. _loadMergeReadContentNode: function( contentNode, data ){
  31. this._loadActiveJson();
  32. if (data.data==="" || data.data){
  33. contentNode.set("text", (this.json.activeText || "true"));
  34. }else{
  35. contentNode.set("text", (this.json.inactiveText || "false"));
  36. }
  37. },
  38. /**
  39. * @summary 组件的配置信息,同时也是Vue组件的data。
  40. * @member MWF.xApplication.process.Xform.Elinput#json {JsonObject}
  41. * @example
  42. * //可以在脚本中获取此对象,下面两行代码是等价的,它们获取的是同一个对象
  43. * var json = this.form.get("elinput").json; //获取组件的json对象
  44. * var json = this.form.get("elinput").vm.$data; //获取Vue组件的data数据,
  45. *
  46. * //通过json对象操作Element组件
  47. * json.disabled = true; //设置输入框为禁用
  48. */
  49. // _loadNode: function(){
  50. // if (this.isReadonly()) this.json.disabled = true;
  51. // this._loadNodeEdit();
  52. // },
  53. _appendVueData: function(){
  54. this.form.Macro.environment.data.check(this.json.id);
  55. this.json[this.json.id] = this._getBusinessData();
  56. if (!this.json.width || !this.json.width.toFloat()) this.json.width = 40;
  57. if (!this.json.activeText) this.json.activeText = "";
  58. if (!this.json.inactiveText) this.json.inactiveText = "";
  59. if (!this.json.activeColor) this.json.activeColor = "#409EFF";
  60. if (!this.json.inactiveColor) this.json.inactiveColor = "#C0CCDA";
  61. if (!this.json.activeIconClass) this.json.activeIconClass = "";
  62. if (!this.json.inactiveIconClass) this.json.inactiveIconClass = "";
  63. if (!this.json.readonly) this.json.readonly = false;
  64. if (!this.json.description) this.json.description = "";
  65. if (!this.json.disabled) this.json.disabled = false;
  66. this._loadActiveJson();
  67. },
  68. _loadActiveJson: function(){
  69. if (!this.json.valueType) this.json.activeValueType = "boolean";
  70. switch(this.json.valueType){
  71. case "boolean":
  72. this.json.activeValue = true;
  73. this.json.inactiveValue = false;
  74. break;
  75. case "string":
  76. if (!this.json.activeValue) this.json.activeValue = "1";
  77. if (!this.json.inactiveValue) this.json.inactiveValue = "0";
  78. break;
  79. case "number":
  80. if (!this.json.activeValue) this.json.activeValue = 1;
  81. if (!this.json.inactiveValue) this.json.inactiveValue = 0;
  82. this.json.activeValue = this.json.activeValue.toFloat();
  83. this.json.inactiveValue = this.json.inactiveValue.toFloat();
  84. break;
  85. default:
  86. this.json.activeValue = true;
  87. this.json.inactiveValue = false;
  88. }
  89. },
  90. // appendVueExtend: function(app){
  91. // if (!app.methods) app.methods = {};
  92. // app.methods.$loadElEvent = function(ev){
  93. // this.validationMode();
  94. // if (ev==="change") this._setBusinessData(this.getInputData());
  95. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  96. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  97. // }
  98. // }.bind(this);
  99. // },
  100. _createElementHtml: function(){
  101. var html = "<el-switch";
  102. html += " v-model=\""+this.json.$id+"\"";
  103. html += " :width=\"width\"";
  104. html += " :active-text=\"activeText\"";
  105. html += " :inactive-text=\"inactiveText\"";
  106. html += " :active-color=\"activeColor\"";
  107. html += " :inactive-color=\"inactiveColor\"";
  108. html += " :disabled=\"disabled\"";
  109. html += " :active-icon-class=\"activeIconClass\"";
  110. html += " :inactive-icon-class=\"inactiveIconClass\"";
  111. html += " :active-value=\"activeValue\"";
  112. html += " :inactive-value=\"inactiveValue\"";
  113. this.options.elEvents.forEach(function(k){
  114. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  115. });
  116. // this.options.elEvents.forEach(function(k){
  117. // html += " @"+k+"=\"$loadElEvent('"+k+"')\"";
  118. // });
  119. if (this.json.elProperties){
  120. Object.keys(this.json.elProperties).forEach(function(k){
  121. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  122. }, this);
  123. }
  124. if (this.json.elStyles) html += " :style=\"elStyles\"";
  125. // if (this.json.elStyles){
  126. // var style = "";
  127. // Object.keys(this.json.elStyles).forEach(function(k){
  128. // if (this.json.elStyles[k]) style += k+":"+this.json.elStyles[k]+";";
  129. // }, this);
  130. // html += " style=\""+style+"\"";
  131. // }
  132. html += ">";
  133. html += "</el-switch>";
  134. return html;
  135. },
  136. __setReadonly: function(data){
  137. if (this.isReadonly()){
  138. if (data==="" || data){
  139. this.node.set("text", (this.json.activeText || "true"));
  140. }else{
  141. this.node.set("text", (this.json.inactiveText || "false"));
  142. }
  143. if( this.json.elProperties ){
  144. this.node.set(this.json.elProperties );
  145. }
  146. if (this.json.elStyles){
  147. this.node.setStyles( this._parseStyles(this.json.elStyles) );
  148. }
  149. if( !this.eventLoaded ){
  150. this._loadDomEvents();
  151. this.eventLoaded = true;
  152. }
  153. this.fireEvent("load");
  154. this.isLoaded = true;
  155. }
  156. },
  157. getExcelData: function(){
  158. var data = this.json[this.json.$id];
  159. if (data==="" || data){
  160. return this.json.activeText || "true";
  161. }else{
  162. return this.json.inactiveText || "false";
  163. }
  164. },
  165. setExcelData: function(d){
  166. var data = true;
  167. this.excelData = d;
  168. if ( (d || "").toString === ( this.json.inactiveText || "false" ) ){
  169. data = false;
  170. }
  171. this.setData(data, true);
  172. }
  173. });