Elrate.js 4.4 KB

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