Elswitch.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 o2.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. // debugger;
  51. // if (this.isReadonly()) this.json.disabled = true;
  52. // this._loadNodeEdit();
  53. // },
  54. _appendVueData: function(){
  55. this.form.Macro.environment.data.check(this.json.id);
  56. this.json[this.json.id] = this._getBusinessData();
  57. if (!this.json.width || !this.json.width.toFloat()) this.json.width = 40;
  58. if (!this.json.activeText) this.json.activeText = "";
  59. if (!this.json.inactiveText) this.json.inactiveText = "";
  60. if (!this.json.activeColor) this.json.activeColor = "#409EFF";
  61. if (!this.json.inactiveColor) this.json.inactiveColor = "#C0CCDA";
  62. if (!this.json.activeIconClass) this.json.activeIconClass = "";
  63. if (!this.json.inactiveIconClass) this.json.inactiveIconClass = "";
  64. if (!this.json.readonly) this.json.readonly = false;
  65. if (!this.json.description) this.json.description = "";
  66. if (!this.json.disabled) this.json.disabled = false;
  67. this._loadActiveJson();
  68. },
  69. _loadActiveJson: function(){
  70. if (!this.json.valueType) this.json.activeValueType = "boolean";
  71. switch(this.json.valueType){
  72. case "boolean":
  73. this.json.activeValue = true;
  74. this.json.inactiveValue = false;
  75. break;
  76. case "string":
  77. if (!this.json.activeValue) this.json.activeValue = "1";
  78. if (!this.json.inactiveValue) this.json.inactiveValue = "0";
  79. break;
  80. case "number":
  81. if (!this.json.activeValue) this.json.activeValue = 1;
  82. if (!this.json.inactiveValue) this.json.inactiveValue = 0;
  83. this.json.activeValue = this.json.activeValue.toFloat();
  84. this.json.inactiveValue = this.json.inactiveValue.toFloat();
  85. break;
  86. default:
  87. this.json.activeValue = true;
  88. this.json.inactiveValue = false;
  89. }
  90. },
  91. // appendVueExtend: function(app){
  92. // if (!app.methods) app.methods = {};
  93. // app.methods.$loadElEvent = function(ev){
  94. // this.validationMode();
  95. // if (ev==="change") this._setBusinessData(this.getInputData());
  96. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  97. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  98. // }
  99. // }.bind(this);
  100. // },
  101. _createElementHtml: function(){
  102. var html = "<el-switch";
  103. html += " v-model=\""+this.json.$id+"\"";
  104. html += " :width=\"width\"";
  105. html += " :active-text=\"activeText\"";
  106. html += " :inactive-text=\"inactiveText\"";
  107. html += " :active-color=\"activeColor\"";
  108. html += " :inactive-color=\"inactiveColor\"";
  109. html += " :disabled=\"disabled\"";
  110. html += " :active-icon-class=\"activeIconClass\"";
  111. html += " :inactive-icon-class=\"inactiveIconClass\"";
  112. html += " :active-value=\"activeValue\"";
  113. html += " :inactive-value=\"inactiveValue\"";
  114. this.options.elEvents.forEach(function(k){
  115. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  116. });
  117. // this.options.elEvents.forEach(function(k){
  118. // html += " @"+k+"=\"$loadElEvent('"+k+"')\"";
  119. // });
  120. if (this.json.elProperties){
  121. Object.keys(this.json.elProperties).forEach(function(k){
  122. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  123. }, this);
  124. }
  125. if (this.json.elStyles) html += " :style=\"elStyles\"";
  126. // if (this.json.elStyles){
  127. // var style = "";
  128. // Object.keys(this.json.elStyles).forEach(function(k){
  129. // if (this.json.elStyles[k]) style += k+":"+this.json.elStyles[k]+";";
  130. // }, this);
  131. // html += " style=\""+style+"\"";
  132. // }
  133. html += ">";
  134. html += "</el-switch>";
  135. return html;
  136. },
  137. __setReadonly: function(data){
  138. if (this.isReadonly()){
  139. if (data==="" || data){
  140. this.node.set("text", (this.json.activeText || "true"));
  141. }else{
  142. this.node.set("text", (this.json.inactiveText || "false"));
  143. }
  144. if( this.json.elProperties ){
  145. this.node.set(this.json.elProperties );
  146. }
  147. if (this.json.elStyles){
  148. this.node.setStyles( this._parseStyles(this.json.elStyles) );
  149. }
  150. this.fireEvent("load");
  151. this.isLoaded = true;
  152. }
  153. },
  154. getExcelData: function(){
  155. var data = this.json[this.json.$id];
  156. if (data==="" || data){
  157. return this.json.activeText || "true";
  158. }else{
  159. return this.json.inactiveText || "false";
  160. }
  161. },
  162. setExcelData: function(d){
  163. var data = true;
  164. this.excelData = d;
  165. if ( (d || "").toString === ( this.json.inactiveText || "false" ) ){
  166. data = false;
  167. }
  168. this.setData(data, true);
  169. }
  170. });