Elslider.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/slider|Element UI Slider 滑块}
  15. */
  16. MWF.xApplication.process.Xform.Elslider = MWF.APPElslider = new Class(
  17. /** @lends o2.xApplication.process.Xform.Elslider# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APP$Elinput,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad"],
  23. /**
  24. * 值改变时触发(使用鼠标拖曳时,只在松开鼠标后触发)。this.event[0]为改变后的值
  25. * @event MWF.xApplication.process.Xform.Elslider#change
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/slider|Slider 滑块的 Events章节}
  27. */
  28. /**
  29. * 数据改变时触发(使用鼠标拖曳时,活动过程实时触发)。this.event[0]为改变后的值
  30. * @event MWF.xApplication.process.Xform.Elslider#input
  31. * @see {@link https://element.eleme.cn/#/zh-CN/component/slider|Slider 滑块的 Events章节}
  32. */
  33. "elEvents": ["change", "input"]
  34. },
  35. /**
  36. * @summary 组件的配置信息,同时也是Vue组件的data。
  37. * @member MWF.xApplication.process.Xform.Elinput#json {JsonObject}
  38. * @example
  39. * //可以在脚本中获取此对象,下面两行代码是等价的,它们获取的是同一个对象
  40. * var json = this.form.get("elinput").json; //获取组件的json对象
  41. * var json = this.form.get("elinput").vm.$data; //获取Vue组件的data数据,
  42. *
  43. * //通过json对象操作Element组件
  44. * json.disabled = true; //设置输入框为禁用
  45. */
  46. // _loadNode: function(){
  47. // if (this.isReadonly()) this.json.disabled = true;
  48. // this._loadNodeEdit();
  49. // },
  50. _loadMergeReadContentNode: function( contentNode, data ){
  51. contentNode.set("text", data.data);
  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.max || !this.json.max.toFloat()) this.json.max = 100;
  57. if (!this.json.min || !this.json.min.toFloat()) this.json.min = 0;
  58. this.json.min = this.json.min.toFloat();
  59. this.json.max = this.json.max.toFloat();
  60. if (!this.json.step || !this.json.step.toFloat()) this.json.step = 1;
  61. this.json.step = this.json.step.toFloat();
  62. if (this.json.showTooltip!==false) this.json.showTooltip = true;
  63. if (this.json.vertical && !this.json.height) this.json.height = "100px";
  64. if (!this.json.height) this.json.height = "";
  65. if (!this.json.inputSize) this.json.inputSize = "";
  66. if (!this.json.tooltipClass) this.json.tooltipClass = "";
  67. if (!this.json.disabled) this.json.disabled = false;
  68. if (this.json.marksScript && this.json.marksScript.code){
  69. this.json.marks = this.form.Macro.exec(this.json.marksScript.code, this);
  70. }else{
  71. this.json.marks = {};
  72. }
  73. },
  74. appendVueExtend: function(app){
  75. if (!app.methods) app.methods = {};
  76. // app.methods.$loadElEvent = function(ev){
  77. // this.validationMode();
  78. // if (ev==="change") this._setBusinessData(this.getInputData());
  79. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  80. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  81. // }
  82. // }.bind(this);
  83. if (this.json.formatTooltip && this.json.formatTooltip.code){
  84. var fun = this.form.Macro.exec(this.json.formatTooltip.code, this);
  85. if (o2.typeOf(fun)==="function"){
  86. app.methods.$formatTooltip = function(){
  87. fun.apply(this, arguments);
  88. }.bind(this);
  89. }else{
  90. app.methods.$formatTooltip = function(){};
  91. }
  92. }
  93. },
  94. _createElementHtml: function(){
  95. var html = "<el-slider";
  96. html += " v-model=\""+this.json.$id+"\"";
  97. html += " :max=\"max\"";
  98. html += " :min=\"min\"";
  99. html += " :step=\"step\"";
  100. html += " :show-stops=\"showStops\"";
  101. html += " :range=\"range\"";
  102. html += " :vertical=\"vertical\"";
  103. html += " :height=\"height\"";
  104. html += " :show-input=\"showInput\"";
  105. html += " :show-input-controls=\"showInputControls\"";
  106. html += " :input-size=\"inputSize\"";
  107. html += " :show-tooltip=\"showTooltip\"";
  108. html += " :tooltip-class=\"tooltipClass\"";
  109. html += " :disabled=\"disabled\"";
  110. html += " :marks=\"marks\"";
  111. if (this.json.formatTooltip && this.json.formatTooltip.code){
  112. html += " :format-tooltip=\"$formatTooltip\"";
  113. }
  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-slider>";
  135. return html;
  136. }
  137. // __setReadonly: function(data){
  138. //
  139. // }
  140. });