Eldatetime.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. o2.xDesktop.requireApp("process.Xform", "$Elinput", null, false);
  2. /** @class Eldatetime 基于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/datetime-picker|Element UI DateTimePicker 日期时间选择器}
  15. */
  16. MWF.xApplication.process.Xform.Eldatetime = MWF.APPEldatetime = new Class(
  17. /** @lends o2.xApplication.process.Xform.Eldatetime# */
  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.Eldatetime#blur
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/datetime-picker|日期时间选择组件的Events章节}
  27. */
  28. /**
  29. * 当 input 获得焦点时触发。this.event[0]指向组件实例
  30. * @event MWF.xApplication.process.Xform.Eldatetime#focus
  31. * @see {@link https://element.eleme.cn/#/zh-CN/component/datetime-picker|日期时间选择组件的Events章节}
  32. */
  33. /**
  34. * 用户确认选定的值时触发。this.event[0]为组件绑定值;格式与绑定值一致,可受 value-format 控制
  35. * @event MWF.xApplication.process.Xform.Eldatetime#change
  36. * @see {@link https://element.eleme.cn/#/zh-CN/component/datetime-picker|日期时间选择组件的Events章节}
  37. */
  38. "elEvents": ["focus", "blur", "change"]
  39. },
  40. _loadMergeReadContentNode: function( contentNode, data ){
  41. var d = o2.typeOf( data.data ) === "array" ? data.data : [data.data];
  42. contentNode.set("text", d.join( this.json.rangeSeparator ? " "+this.json.rangeSeparator+" " : " 至 " ) );
  43. },
  44. _queryLoaded: function(){
  45. var data = this._getBusinessData();
  46. if( data ){
  47. if( ["datetimerange"].contains(this.json.selectType) ) {
  48. if (typeOf(data) === "string") this._setBusinessData([data, ""]);
  49. }else{
  50. if( typeOf(data) === "array" )this._setBusinessData(data[0] || "");
  51. }
  52. }
  53. },
  54. __setReadonly: function(data){
  55. if (this.isReadonly()){
  56. if( o2.typeOf(data) === "array" ){
  57. this.node.set("text", this.json.rangeSeparator ? data.join(this.json.rangeSeparator) : data );
  58. }else{
  59. this.node.set("text", data );
  60. }
  61. if( this.json.elProperties ){
  62. this.node.set(this.json.elProperties );
  63. }
  64. if (this.json.elStyles){
  65. this.node.setStyles( this._parseStyles(this.json.elStyles) );
  66. }
  67. this.fireEvent("postLoad");
  68. this.fireEvent("load");
  69. this.isLoaded = true;
  70. }
  71. },
  72. _appendVueData: function(){
  73. if (!this.json.isReadonly && !this.form.json.isReadonly) this.json.isReadonly = false;
  74. if (!this.json.disabled) this.json.disabled = false;
  75. if (!this.json.clearable) this.json.clearable = false;
  76. if (!this.json.disabled) this.json.disabled = false;
  77. if (!this.json.editable) this.json.editable = false;
  78. if (!this.json.size) this.json.size = "";
  79. if (!this.json.prefixIcon) this.json.prefixIcon = "";
  80. if (!this.json.description) this.json.description = "";
  81. if (!this.json.arrowControl) this.json.arrowControl = false;
  82. this.json.pickerOptions = {
  83. firstDayOfWeek: this.json.firstDayOfWeek.toInt()
  84. }
  85. if (this.json.disabledDate && this.json.disabledDate.code){
  86. this.json.pickerOptions.disabledDate = function(date){
  87. return this.form.Macro.fire(this.json.disabledDate.code, this, date);
  88. }.bind(this)
  89. }
  90. // if(this.json.selectableRange && this.json.selectableRange.code){
  91. // this.json.pickerOptions.selectableRange = this.form.Macro.fire(this.json.selectableRange.code, this);
  92. // }
  93. },
  94. _createElementHtml: function() {
  95. var html = "<el-date-picker";
  96. html += " v-model=\""+this.json.$id+"\"";
  97. html += " :type=\"selectType\"";
  98. html += " :readonly=\"isReadonly\"";
  99. html += " :disabled=\"disabled\"";
  100. html += " :editable=\"editable\"";
  101. html += " :clearable=\"clearable\"";
  102. html += " :size=\"size\"";
  103. html += " :prefix-icon=\"prefixIcon\"";
  104. html += " :range-separator=\"rangeSeparator\"";
  105. html += " :start-placeholder=\"startPlaceholder\"";
  106. html += " :end-placeholder=\"endPlaceholder\"";
  107. html += " :value-format=\"format\"";
  108. html += " :format=\"format\"";
  109. html += " :picker-options=\"pickerOptions\"";
  110. html += " :arrow-control=\"arrowControl\"";
  111. // html += " :picker-options=\"{" +
  112. // ":firstDayOfWeek=firstDayOfWeek," +
  113. // ":disabledDate=\"disabledDateFun\""+
  114. // "}\"";
  115. this.options.elEvents.forEach(function(k){
  116. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  117. });
  118. if (this.json.elProperties){
  119. Object.keys(this.json.elProperties).forEach(function(k){
  120. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  121. }, this);
  122. }
  123. if (this.json.elStyles) html += " :style=\"elStyles\"";
  124. html += ">";
  125. if (this.json.vueSlot) html += this.json.vueSlot;
  126. html += "</el-date-picker>";
  127. return html;
  128. },
  129. getInputData: function(){
  130. var data = this.json[this.json.$id];
  131. if( data === null ){
  132. if( ["datetimerange"].contains(this.json.selectType) ) {
  133. return [];
  134. }else{
  135. return "";
  136. }
  137. }
  138. return this.json[this.json.$id];
  139. },
  140. getExcelData: function(){
  141. var value = this.getData();
  142. return o2.typeOf(value) === "array" ? value.join(", ") : value;
  143. },
  144. setExcelData: function(data){
  145. var arr = this.stringToArray(data);
  146. this.excelData = arr;
  147. var value = arr.length === 0 ? arr[0] : arr;
  148. this.setData(value, true);
  149. }
  150. });