Eltime.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. o2.xDesktop.requireApp("process.Xform", "$Elinput", null, false);
  2. /** @class Eltime 基于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/time-picker|Element UI TimePicker 时间选择器}
  15. */
  16. MWF.xApplication.process.Xform.Eltime = MWF.APPEltime = new Class(
  17. /** @lends o2.xApplication.process.Xform.Eltime# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APP$Elinput,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad"],
  23. /**
  24. * 当 input 失去焦点时触发。this.event[0]指向组件实例
  25. * @event MWF.xApplication.process.Xform.Eltime#blur
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/time-picker|时间选择组件的Events章节}
  27. */
  28. /**
  29. * 当 input 获得焦点时触发。this.event[0]指向组件实例
  30. * @event MWF.xApplication.process.Xform.Eltime#focus
  31. * @see {@link https://element.eleme.cn/#/zh-CN/component/time-picker|时间选择组件的Events章节}
  32. */
  33. /**
  34. * 用户确认选定的值时触发。this.event[0]为组件绑定值
  35. * @event MWF.xApplication.process.Xform.Eltime#change
  36. * @see {@link https://element.eleme.cn/#/zh-CN/component/time-picker|时间选择组件的Events章节}
  37. */
  38. "elEvents": ["focus", "blur", "change"]
  39. },
  40. _queryLoaded: function(){
  41. var data = this._getBusinessData();
  42. if( ["picker"].contains(this.json.timeSelectType) && this.json.isRange) {
  43. if (typeOf(data) === "string") this._setBusinessData([data, ""]);
  44. }else{
  45. if( typeOf(data) === "array" )this._setBusinessData(data[0] || "");
  46. }
  47. },
  48. _appendVueData: function(){
  49. if (!this.json.readonly) this.json.readonly = false;
  50. if (!this.json.disabled) this.json.disabled = false;
  51. if (!this.json.clearable) this.json.clearable = false;
  52. if (!this.json.disabled) this.json.disabled = false;
  53. if (!this.json.editable) this.json.editable = false;
  54. if (!this.json.size) this.json.size = "";
  55. if (!this.json.prefixIcon) this.json.prefixIcon = "";
  56. if (!this.json.suffixIcon) this.json.suffixIcon = "";
  57. if (!this.json.description) this.json.description = "";
  58. if (!this.json.arrowControl) this.json.arrowControl = false;
  59. if (this.json.timeSelectType === "select"){
  60. this.json.pickerOptions = {
  61. "start": this.json.start,
  62. "step": this.json.step,
  63. "end": this.json.end
  64. };
  65. }else{
  66. this.json.pickerOptions = {
  67. "format": this.json.format
  68. };
  69. if (!this.json.isRange && this.json.selectableRange && this.json.selectableRange.code){
  70. this.json.pickerOptions.selectableRange = this.form.Macro.fire(this.json.selectableRange.code, this);
  71. }
  72. }
  73. },
  74. _createElementHtml: function() {
  75. if (this.json.timeSelectType === "select"){
  76. return this.createSelectElementHtml();
  77. }else{
  78. if (this.json.isRange) {
  79. return this.createPickerRangeElementHtml();
  80. } else {
  81. return this.createPickerElementHtml();
  82. }
  83. }
  84. },
  85. getCommonHtml: function(){
  86. var html = "";
  87. html += " v-model=\""+this.json.$id+"\"";
  88. html += " :readonly=\"isReadonly\"";
  89. html += " :disabled=\"disabled\"";
  90. html += " :editable=\"editable\"";
  91. html += " :clearable=\"clearable\"";
  92. html += " :size=\"size\"";
  93. html += " :prefix-icon=\"prefixIcon\"";
  94. this.options.elEvents.forEach(function(k){
  95. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  96. });
  97. if (this.json.elProperties){
  98. Object.keys(this.json.elProperties).forEach(function(k){
  99. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  100. }, this);
  101. }
  102. if (this.json.elStyles) html += " :style=\"elStyles\"";
  103. html += ">";
  104. if (this.json.vueSlot) html += this.json.vueSlot;
  105. return html;
  106. },
  107. createSelectElementHtml: function(){
  108. var html = "<el-time-select";
  109. html += " :placeholder=\"description\"";
  110. html += " :picker-options=\"pickerOptions\"";
  111. html += this.getCommonHtml();
  112. html += "</el-time-select>";
  113. return html;
  114. },
  115. // createSelectRangeElementHtml: function(){
  116. // var html = "<el-time-select";
  117. // html += " :placeholder=\"startPlaceholder\"";
  118. // html += this.getSelectOpt();
  119. // html += this.getCommonHtml();
  120. // html += "</el-time-select>";
  121. //
  122. // html += "<span>"+this.json.rangeSeparator+"</span>";
  123. //
  124. // html += "<el-time-select";
  125. // html += " :placeholder=\"endPlaceholder\"";
  126. // html += this.getSelectOpt();
  127. // html += this.getCommonHtml();
  128. // html += "</el-time-select>";
  129. // return html;
  130. // },
  131. createPickerElementHtml: function(){
  132. var html = "<el-time-picker";
  133. html += " :placeholder=\"description\"";
  134. html += " :arrow-control=\"arrowControl\"";
  135. html += " :value-format=\"format\"";
  136. html += " :picker-options=\"pickerOptions\"";
  137. html += this.getCommonHtml();
  138. html += "</el-time-picker>";
  139. return html;
  140. },
  141. createPickerRangeElementHtml: function(){
  142. var html = "<el-time-picker";
  143. html += " is-range";
  144. html += " :range-separator=\"rangeSeparator\"";
  145. html += " :start-placeholder=\"startPlaceholder\"";
  146. html += " :end-placeholder=\"endPlaceholder\"";
  147. html += " :arrow-control=\"arrowControl\"";
  148. html += " :value-format=\"format\"";
  149. html += " :picker-options=\"pickerOptions\"";
  150. html += this.getCommonHtml();
  151. html += "</el-time-picker>";
  152. return html;
  153. },
  154. getExcelData: function(){
  155. var value = this.getData();
  156. return o2.typeOf(value) === "array" ? value.join(", ") : value;
  157. },
  158. setExcelData: function(data){
  159. var arr = this.stringToArray(data);
  160. this.excelData = arr;
  161. var value = arr.length === 0 ? arr[0] : arr;
  162. this.setData(value, true);
  163. }
  164. });