Eldate.js 6.5 KB

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