Elrate.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/rate|Element UI Rate 评分}
  15. */
  16. MWF.xApplication.process.Xform.Elrate = MWF.APPElrate = new Class(
  17. /** @lends o2.xApplication.process.Xform.Elrate# */
  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.Elrate#change
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/rate|评分组件的Events章节}
  27. */
  28. "elEvents": ["change"]
  29. },
  30. // _loadNode: function(){
  31. // debugger;
  32. // if (this.isReadonly()) this.json.disabled = true;
  33. // this._loadNodeEdit();
  34. // },
  35. _appendVueData: function(){
  36. if (!this.json.max) this.json.max = "";
  37. if (!this.json.isReadonly && !this.form.json.isReadonly) this.json.isReadonly = false;
  38. if (!this.json.max) this.json.max = 5;
  39. if (!this.json.allowHalf) this.json.allowHalf = false;
  40. if (!this.json.lowThreshold) this.json.lowThreshold = 2;
  41. if (!this.json.highThreshold) this.json.highThreshold = 4;
  42. this.json.colors = [
  43. this.json.lowColor, this.json.mediumColor, this.json.highColor
  44. ];
  45. if( this.json.showAfter === "text" ){
  46. this.json.showText = true;
  47. this.json.showScore = false;
  48. }else if( this.json.showAfter === "score" ){
  49. this.json.showText = false;
  50. this.json.showScore = true;
  51. }else{
  52. this.json.showText = false;
  53. this.json.showScore = false;
  54. }
  55. if( o2.typeOf(this.json.texts) === "string"){
  56. this.json.texts = this.json.texts.split(",");
  57. }
  58. if(!this.json.textColor)this.json.textColor = "";
  59. },
  60. // appendVueExtend: function(app){
  61. // if (!app.methods) app.methods = {};
  62. // app.methods.$loadElEvent = function(ev){
  63. // this.validationMode();
  64. // if (ev==="change") this._setBusinessData(this.getInputData());
  65. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  66. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  67. // }
  68. // }.bind(this);
  69. // },
  70. _createElementHtml: function(){
  71. var html = "<el-rate";
  72. html += " v-model=\""+this.json.$id+"\"";
  73. html += " :readonly=\"isReadonly\"";
  74. html += " :disabled=\"disabled\"";
  75. html += " :max=\"max\"";
  76. html += " :allow-half=\"allowHalf\"";
  77. html += " :low-threshold=\"lowThreshold\"";
  78. html += " :high-threshold=\"highThreshold\"";
  79. html += " :colors=\"colors\"";
  80. html += " :void-color=\"voidColor\"";
  81. html += " :disabled-void-color=\"disabledVoidColor\"";
  82. html += " :show-text=\"showText\"";
  83. html += " :text-color=\"textColor\"";
  84. html += " :texts=\"texts\"";
  85. html += " :show-score=\"showScore\"";
  86. // this.options.elEvents.forEach(function(k){
  87. // html += " @"+k+"=\"$loadElEvent('"+k+"')\"";
  88. // });
  89. this.options.elEvents.forEach(function(k){
  90. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  91. });
  92. if (this.json.elProperties){
  93. Object.keys(this.json.elProperties).forEach(function(k){
  94. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  95. }, this);
  96. }
  97. if (this.json.elStyles) html += " :style=\"elStyles\"";
  98. // if (this.json.elStyles){
  99. // var style = "";
  100. // Object.keys(this.json.elStyles).forEach(function(k){
  101. // if (this.json.elStyles[k]) style += k+":"+this.json.elStyles[k]+";";
  102. // }, this);
  103. // html += " style=\""+style+"\"";
  104. // }
  105. html += ">";
  106. if (this.json.vueSlot) html += this.json.vueSlot;
  107. html += "</el-rate>";
  108. return html;
  109. }
  110. });