Elinput.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/input|Element UI Input 输入框}
  15. */
  16. MWF.xApplication.process.Xform.Elinput = MWF.APPElinput = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Elinput# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APP$Elinput,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad"],
  23. /**
  24. * 当 input 获得焦点时触发。this.event[0]指向Event
  25. * @event MWF.xApplication.process.Xform.Elinput#focus
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/input|输入组件的Input Events章节}
  27. */
  28. /**
  29. * 当 input 失去焦点时触发。this.event[0]指向Event
  30. * @event MWF.xApplication.process.Xform.Elinput#blur
  31. * @see {@link https://element.eleme.cn/#/zh-CN/component/input|输入组件的Input Events章节}
  32. */
  33. /**
  34. * 仅在输入框失去焦点或用户按下回车时触发。this.event[0]为组件的value
  35. * @event MWF.xApplication.process.Xform.Elinput#change
  36. * @see {@link https://element.eleme.cn/#/zh-CN/component/input|输入组件的Input Events章节}
  37. */
  38. /**
  39. * 在 Input 值改变时触发。this.event[0]为组件的value
  40. * @event MWF.xApplication.process.Xform.Elinput#input
  41. * @see {@link https://element.eleme.cn/#/zh-CN/component/input|输入组件的Input Events章节}
  42. */
  43. /**
  44. * 在点击由 clearable 属性生成的清空按钮时触发
  45. * @event MWF.xApplication.process.Xform.Elinput#clear
  46. * @see {@link https://element.eleme.cn/#/zh-CN/component/input|输入组件的Input Events章节}
  47. */
  48. "elEvents": ["focus", "blur", "change", "input", "clear"]
  49. },
  50. _appendVueData: function(){
  51. if (!this.json.maxlength) this.json.maxlength = "";
  52. if (!this.json.minlength) this.json.minlength = "";
  53. if (!this.json.max) this.json.max = "";
  54. if (!this.json.min) this.json.min = "";
  55. if (!this.json.showWordLimit) this.json.showWordLimit = false;
  56. if (!this.json.showPassword) this.json.showPassword = false;
  57. if (!this.json.disabled) this.json.disabled = false;
  58. if (!this.json.clearable) this.json.clearable = false;
  59. if (!this.json.size) this.json.size = "";
  60. if (!this.json.prefixIcon) this.json.prefixIcon = "";
  61. if (!this.json.suffixIcon) this.json.suffixIcon = "";
  62. if (!this.json.rows) this.json.rows = 2;
  63. if (!this.json.autosize) this.json.autosize = false;
  64. if (!this.json.readonly) this.json.readonly = false;
  65. if (!this.json.resize) this.json.resize = "none";
  66. if (!this.json.description) this.json.description = "";
  67. if (this.json.minRows && this.json.maxRows){
  68. this.json.autosize = {minRows: this.json.minRows.toInt(), maxRows: this.json.maxRows.toInt()}
  69. }
  70. },
  71. // appendVueExtend: function(app){
  72. // if (!app.methods) app.methods = {};
  73. // app.methods.$loadElEvent = function(ev){
  74. // this.validationMode();
  75. // if (ev==="change") this._setBusinessData(this.getInputData());
  76. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  77. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  78. // }
  79. // }.bind(this);
  80. // },
  81. _createElementHtml: function(){
  82. //var numberStr = (this.json.inputType === "number" && this.json.resultType === "number" ) ? ".number" : "";
  83. var html = "<el-input";
  84. html += " v-model"+"=\""+this.json.$id+"\"";
  85. if( this.json.inputType === 'number' ){
  86. html += " :max=\"max\"";
  87. html += " :min=\"min\"";
  88. }else{
  89. html += " :maxlength=\"maxlength\"";
  90. html += " :minlength=\"minlength\"";
  91. }
  92. html += " :show-word-limit=\"showWordLimit\"";
  93. html += " :show-password=\"showPassword\"";
  94. html += " :disabled=\"disabled\"";
  95. html += " :size=\"size\"";
  96. html += " :prefix-icon=\"prefixIcon\"";
  97. html += " :suffix-icon=\"suffixIcon\"";
  98. html += " :rows=\"rows\"";
  99. html += " :autosize=\"autosize\"";
  100. html += " :readonly=\"readonly\"";
  101. html += " :resize=\"resize\"";
  102. html += " :clearable=\"clearable\"";
  103. html += " :type=\"inputType\"";
  104. html += " :placeholder=\"description\"";
  105. // this.options.elEvents.forEach(function(k){
  106. // html += " @"+k+"=\"$loadElEvent('"+k+"')\"";
  107. // });
  108. this.options.elEvents.forEach(function(k){
  109. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  110. });
  111. if (this.json.elProperties){
  112. Object.keys(this.json.elProperties).forEach(function(k){
  113. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  114. }, this);
  115. }
  116. if (this.json.elStyles) html += " :style=\"elStyles\"";
  117. // if (this.json.elStyles){
  118. // var style = "";
  119. // Object.keys(this.json.elStyles).forEach(function(k){
  120. // if (this.json.elStyles[k]) style += k+":"+this.json.elStyles[k]+";";
  121. // }, this);
  122. // html += " style=\""+style+"\"";
  123. // }
  124. html += ">";
  125. if (this.json.vueSlot) html += this.json.vueSlot;
  126. html += "</el-input>";
  127. return html;
  128. },
  129. _createEventFunction: function(methods, k){
  130. methods["$loadElEvent_"+k.camelCase()] = function(){
  131. var flag = true;
  132. if (k==="change"){
  133. if(this.json.inputType === "number" ){
  134. if( this.json.resultType === "number" ){
  135. if( parseFloat(arguments[0]).toString() !== "NaN" ){
  136. this.json[this.json.$id] = parseFloat(arguments[0]);
  137. }
  138. }
  139. var value = this.getMin( this.getMax( this.json[this.json.$id] ) );
  140. if( value !== this.json[this.json.$id] ){
  141. this.json[this.json.$id] = value;
  142. }
  143. }
  144. this.validationMode();
  145. this._setBusinessData(this.getInputData());
  146. if( !this.validation() )flag = false;
  147. }
  148. if (this.json.events && this.json.events[k] && this.json.events[k].code){
  149. this.form.Macro.fire(this.json.events[k].code, this, arguments);
  150. }
  151. if( flag )this.fireEvent(k, arguments);
  152. }.bind(this);
  153. },
  154. getMax: function( value ){
  155. if( isNaN(value) )return value;
  156. if( typeOf( value ) === "string" )value = parseFloat(value);
  157. if( typeOf(this.json.max)!=='null' && !isNaN( this.json.max )){
  158. var max = this.json.max;
  159. if( typeOf( max ) === "string" )max = parseFloat(max);
  160. return isNaN(max) ? value : Math.min( max, value );
  161. }else{
  162. return value;
  163. }
  164. },
  165. getMin: function( value ){
  166. if( isNaN(value) )return value;
  167. if( typeOf( value ) === "string" )value = parseFloat(value);
  168. if( typeOf(this.json.min)!=='null' && !isNaN( this.json.min )){
  169. var min = this.json.min;
  170. if( typeOf( min ) === "string" )min = parseFloat(min);
  171. return isNaN(min) ? value : Math.max( min, value );
  172. }else{
  173. return value;
  174. }
  175. },
  176. getValue: function(){
  177. if (this.moduleValueAG) return this.moduleValueAG;
  178. var value = this._getBusinessData();
  179. if( this.json.inputType === "number" ){
  180. if (value || value===0 ){
  181. return this.json.resultType === "string" ? value.toString() : value;
  182. }else{
  183. value = this._computeValue();
  184. value = (o2.typeOf(value)!=="null") ? value : "";
  185. return this.json.resultType === "string" ? value.toString() : value;
  186. }
  187. }else{
  188. if (value || value===0 || value === false){
  189. return value;
  190. }else{
  191. value = this._computeValue();
  192. return (o2.typeOf(value)!=="null") ? value : "";
  193. }
  194. }
  195. }
  196. });