Elinput.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 o2.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.showWordLimit) this.json.showWordLimit = false;
  54. if (!this.json.showPassword) this.json.showPassword = false;
  55. if (!this.json.disabled) this.json.disabled = false;
  56. if (!this.json.clearable) this.json.clearable = false;
  57. if (!this.json.size) this.json.size = "";
  58. if (!this.json.prefixIcon) this.json.prefixIcon = "";
  59. if (!this.json.suffixIcon) this.json.suffixIcon = "";
  60. if (!this.json.rows) this.json.rows = 2;
  61. if (!this.json.autosize) this.json.autosize = false;
  62. if (!this.json.readonly) this.json.readonly = false;
  63. if (!this.json.resize) this.json.resize = "none";
  64. if (!this.json.description) this.json.description = "";
  65. if (this.json.minRows && this.json.maxRows){
  66. this.json.autosize = {minRows: this.json.minRows.toInt(), maxRows: this.json.maxRows.toInt()}
  67. }
  68. },
  69. // appendVueExtend: function(app){
  70. // if (!app.methods) app.methods = {};
  71. // app.methods.$loadElEvent = function(ev){
  72. // this.validationMode();
  73. // if (ev==="change") this._setBusinessData(this.getInputData());
  74. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  75. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  76. // }
  77. // }.bind(this);
  78. // },
  79. _createElementHtml: function(){
  80. //var numberStr = (this.json.inputType === "number" && this.json.resultType === "number" ) ? ".number" : "";
  81. var html = "<el-input";
  82. html += " v-model"+"=\""+this.json.$id+"\"";
  83. html += " :maxlength=\"maxlength\"";
  84. html += " :minlength=\"minlength\"";
  85. html += " :show-word-limit=\"showWordLimit\"";
  86. html += " :show-password=\"showPassword\"";
  87. html += " :disabled=\"disabled\"";
  88. html += " :size=\"size\"";
  89. html += " :prefix-icon=\"prefixIcon\"";
  90. html += " :suffix-icon=\"suffixIcon\"";
  91. html += " :rows=\"rows\"";
  92. html += " :autosize=\"autosize\"";
  93. html += " :readonly=\"readonly\"";
  94. html += " :resize=\"resize\"";
  95. html += " :clearable=\"clearable\"";
  96. html += " :type=\"inputType\"";
  97. html += " :placeholder=\"description\"";
  98. // this.options.elEvents.forEach(function(k){
  99. // html += " @"+k+"=\"$loadElEvent('"+k+"')\"";
  100. // });
  101. this.options.elEvents.forEach(function(k){
  102. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  103. });
  104. if (this.json.elProperties){
  105. Object.keys(this.json.elProperties).forEach(function(k){
  106. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  107. }, this);
  108. }
  109. if (this.json.elStyles) html += " :style=\"elStyles\"";
  110. // if (this.json.elStyles){
  111. // var style = "";
  112. // Object.keys(this.json.elStyles).forEach(function(k){
  113. // if (this.json.elStyles[k]) style += k+":"+this.json.elStyles[k]+";";
  114. // }, this);
  115. // html += " style=\""+style+"\"";
  116. // }
  117. html += ">";
  118. if (this.json.vueSlot) html += this.json.vueSlot;
  119. html += "</el-input>";
  120. return html;
  121. },
  122. _createEventFunction: function(methods, k){
  123. methods["$loadElEvent_"+k.camelCase()] = function(){
  124. var flag = true;
  125. if (k==="change"){
  126. if(this.json.inputType === "number" && this.json.resultType === "number" ){
  127. if( parseFloat(arguments[0]).toString() !== "NaN" ){
  128. this.json[this.json.$id] = parseFloat(arguments[0]);
  129. }
  130. }
  131. this.validationMode();
  132. this._setBusinessData(this.getInputData());
  133. if( !this.validation() )flag = false;
  134. }
  135. if (this.json.events && this.json.events[k] && this.json.events[k].code){
  136. this.form.Macro.fire(this.json.events[k].code, this, arguments);
  137. }
  138. if( flag )this.fireEvent(k, arguments);
  139. }.bind(this);
  140. },
  141. getValue: function(){
  142. if (this.moduleValueAG) return this.moduleValueAG;
  143. var value = this._getBusinessData();
  144. if (value || value===0 || value===false){
  145. return value;
  146. }else{
  147. value = this._computeValue();
  148. return (o2.typeOf(value)!=="null") ? value : "";
  149. }
  150. }
  151. });