Eldatetime.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. o2.xDesktop.requireApp("process.Xform", "Eldate", 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 MWF.xApplication.process.Xform.Eldatetime# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APPEldate,
  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. _queryLoaded: function(){
  41. var data = this._getBusinessData();
  42. if( data ){
  43. if( ["datetimerange"].contains(this.json.selectType) ) {
  44. if (typeOf(data) === "string") this._setBusinessData([data, ""]);
  45. }else{
  46. if( typeOf(data) === "array" )this._setBusinessData(data[0] || "");
  47. }
  48. }
  49. },
  50. __setReadonly: function(data){
  51. var format = this.json.format || this.json.valueFormat;
  52. if (this.isReadonly()){
  53. if( o2.typeOf(data) === "array" ){
  54. var ds = data.map(function (d){
  55. return this.formatDate(new Date(d), format);
  56. }.bind(this));
  57. this.node.set("text", this.json.rangeSeparator ? ds.join(this.json.rangeSeparator) : ds );
  58. }else{
  59. this.node.set("text", data ? this.formatDate(new Date(data), format) : "");
  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. if( !this.eventLoaded ){
  68. this._loadDomEvents();
  69. this.eventLoaded = true;
  70. }
  71. this.fireEvent("postLoad");
  72. this.fireEvent("load");
  73. this.isLoaded = true;
  74. }
  75. },
  76. _appendVueData: function(){
  77. if (!this.json.isReadonly && !this.form.json.isReadonly) this.json.isReadonly = false;
  78. if (!this.json.disabled) this.json.disabled = false;
  79. if (!this.json.clearable) this.json.clearable = false;
  80. if (!this.json.disabled) this.json.disabled = false;
  81. if (!this.json.editable) this.json.editable = false;
  82. if (!this.json.size) this.json.size = "";
  83. if (!this.json.valueFormat) this.json.valueFormat = this.json.format || "";
  84. if (!this.json.prefixIcon) this.json.prefixIcon = "";
  85. if (!this.json.description) this.json.description = "";
  86. if (!this.json.arrowControl) this.json.arrowControl = false;
  87. this.json.pickerOptions = {
  88. firstDayOfWeek: this.json.firstDayOfWeek.toInt()
  89. }
  90. if (this.json.disabledDate && this.json.disabledDate.code){
  91. this.json.pickerOptions.disabledDate = function(date){
  92. return this.form.Macro.fire(this.json.disabledDate.code, this, date);
  93. }.bind(this)
  94. }
  95. // if(this.json.selectableRange && this.json.selectableRange.code){
  96. // this.json.pickerOptions.selectableRange = this.form.Macro.fire(this.json.selectableRange.code, this);
  97. // }
  98. },
  99. _createElementHtml: function() {
  100. var html = "<el-date-picker";
  101. html += " v-model=\""+this.json.$id+"\"";
  102. html += " :type=\"selectType\"";
  103. html += " :readonly=\"isReadonly\"";
  104. html += " :disabled=\"disabled\"";
  105. html += " :editable=\"editable\"";
  106. html += " :clearable=\"clearable\"";
  107. html += " :size=\"size\"";
  108. html += " :prefix-icon=\"prefixIcon\"";
  109. html += " :range-separator=\"rangeSeparator\"";
  110. html += " :start-placeholder=\"startPlaceholder\"";
  111. html += " :end-placeholder=\"endPlaceholder\"";
  112. html += " :value-format=\"valueFormat\"";
  113. html += " :format=\"format\"";
  114. html += " :picker-options=\"pickerOptions\"";
  115. html += " :arrow-control=\"arrowControl\"";
  116. // html += " :picker-options=\"{" +
  117. // ":firstDayOfWeek=firstDayOfWeek," +
  118. // ":disabledDate=\"disabledDateFun\""+
  119. // "}\"";
  120. this.options.elEvents.forEach(function(k){
  121. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  122. });
  123. if (this.json.elProperties){
  124. Object.keys(this.json.elProperties).forEach(function(k){
  125. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  126. }, this);
  127. }
  128. if (this.json.elStyles) html += " :style=\"elStyles\"";
  129. html += ">";
  130. if (this.json.vueSlot) html += this.json.vueSlot;
  131. html += "</el-date-picker>";
  132. return html;
  133. },
  134. getInputData: function(){
  135. var data = this.json[this.json.$id];
  136. if( data === null ){
  137. if( ["datetimerange"].contains(this.json.selectType) ) {
  138. return [];
  139. }else{
  140. return "";
  141. }
  142. }
  143. return this.json[this.json.$id];
  144. },
  145. getExcelData: function(){
  146. var value = this.getData();
  147. return o2.typeOf(value) === "array" ? value.join(", ") : value;
  148. },
  149. setExcelData: function(data){
  150. var arr = this.stringToArray(data);
  151. this.excelData = arr;
  152. var value = arr.length === 0 ? arr[0] : arr;
  153. this.setData(value, true);
  154. }
  155. });