schedu.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * @author jiangyong
  3. *
  4. * @date 2020年3月23日10:57:53
  5. *
  6. * layui-调度计划插件
  7. *
  8. *
  9. * 1。两个输入参数,第一个参数定义该插件的依赖插件;第二个参数是回调函数,编写我们自定义插件的业务逻辑
  10. * 2.返回插件,调用exports函数,两个参数分别是 插件名称和插件对象
  11. *
  12. */
  13. layui.define(['jquery', 'form', 'laydate'], function(exports) {
  14. "use strict";
  15. var $ = layui.jquery,
  16. form = layui.form;
  17. var laydate = layui.laydate;
  18. var schedu = function() {
  19. this.scheduType = {
  20. "0": {
  21. "desc": "按分执行",
  22. "type": "time",
  23. "format": "mm"
  24. },
  25. "1": {
  26. "desc": "按秒执行",
  27. "type": "time",
  28. "format": "ss"
  29. },
  30. "2": {
  31. "desc": "按天执行",
  32. "type": "time",
  33. "format":"HH:mm:ss"
  34. }
  35. // ,"3": {
  36. // "desc": "特定时间执行",
  37. // "type": "datetime"
  38. // },
  39. // "4": {
  40. // "desc": "自定义执行"
  41. // }
  42. }
  43. this.selects = null
  44. };
  45. //组件初始化方法
  46. schedu.prototype.init = function() {
  47. this.selects = $(".ag-schedu");
  48. this.initSelect();
  49. this.buildEvent();
  50. form.render("select");
  51. }
  52. /**
  53. * 初始化下拉框
  54. */
  55. schedu.prototype.initSelect = function() {
  56. var that = this;
  57. $.each(that.selects, function(i, item) {
  58. $(item).empty();
  59. $(item).siblings().remove();
  60. $(item).append("<option value =''>--请选择--</option>");
  61. for (var key in that.scheduType) {
  62. $(item).append("<option value='" + key + "'>" + that.scheduType[key].desc + "</option>");
  63. }
  64. $(item).attr("lay-filter", "a"+util.randomWord(false, 16));
  65. $(item).after("<div style='position:absolute;top:0;z-index:-1'><div style='position: relative;' id=" + $(item).attr("lay-filter") + "_date" + "></div></div>");
  66. $(item).after("<div style='position:absolute;top:0;z-index:-1'><div style='position: relative;' id=" + $(item).attr("lay-filter") + "_date2" + "></div></div>");
  67. });
  68. }
  69. /**
  70. * 特定时间事件
  71. * @param {Object} data
  72. * @param {Object} scheduObj
  73. */
  74. schedu.prototype.clickDateTime = function(data){
  75. util.error("功能实现中");
  76. return ;
  77. var that = this;
  78. var id = "#" + $(data.elem).attr("lay-filter") + "_date2";
  79. var opt = {
  80. elem: id,
  81. type: that.currScheduType.type,
  82. position:"fixed",
  83. trigger: 'click'
  84. ,done: function(value, data, endDate) {
  85. var exeExpr = data.seconds+" "+data.minutes+" "+data.hours+" "+data.date+" "+data.month+" ? "+data.year;
  86. $("[name=scheduCron]").val(exeExpr);
  87. }
  88. }
  89. laydate.render(opt);
  90. $(id).click();
  91. }
  92. /**
  93. * 自定义事件
  94. * @param {Object} data
  95. */
  96. schedu.prototype.customTime = function(data){
  97. util.error("功能实现中");
  98. return ;
  99. util.openWin("/views/schedu/customSchedu.html", "自定义表达式配置", 1000, 1000);
  100. }
  101. /**
  102. * 天,分,秒 事件
  103. * @param {Object} data
  104. * @param {Object} scheduObj
  105. */
  106. schedu.prototype.clickTime = function(data){
  107. var that = this;
  108. var id = "#" + $(data.elem).attr("lay-filter") + "_date";
  109. var opt = {
  110. elem: id,
  111. type: that.currScheduType.type,
  112. position:"fixed",
  113. trigger: 'click'
  114. ,done: function(value, data, endDate) {
  115. var exeExpr = "";
  116. if (that.currScheduType.format == "ss") {
  117. exeExpr ="*/" + data.seconds + " * * * * ?";
  118. }
  119. if (that.currScheduType.format == "mm") {
  120. exeExpr = " 0 */" + data.minutes + " * * * ?";
  121. }
  122. if (that.currScheduType.format == "HH:mm:ss") {
  123. exeExpr = data.seconds+" "+data.minutes+" "+data.hours+" * * ? ";
  124. }
  125. $("[name=scheduCron]").val(exeExpr);
  126. }
  127. }
  128. laydate.render(opt);
  129. $(id).click();
  130. /**
  131. * 展示处理
  132. */
  133. if (that.currScheduType.format) {
  134. var li = $("#layui-laydate"+$(id).attr("lay-key") +" .layui-laydate-content .layui-laydate-list.laydate-time-list>li");
  135. if("mm" == that.currScheduType.format){
  136. li.eq(0).addClass("layui-hide");
  137. li.eq(2).addClass("layui-hide");
  138. }
  139. if("ss" == that.currScheduType.format){
  140. li.eq(0).addClass("layui-hide");
  141. li.eq(1).addClass("layui-hide");
  142. }
  143. if("HH:mm:ss" == that.currScheduType.format){
  144. //li.eq(2).addClass("layui-hide");
  145. }
  146. }
  147. }
  148. /**
  149. * 绑定监听事件
  150. */
  151. schedu.prototype.buildEvent = function() {
  152. var that = this;
  153. $.each(that.selects, function() {
  154. form.on("select(" + $(this).attr("lay-filter") + ")", function(data) {
  155. var scheduObj = that.scheduType[data.value];
  156. that.currScheduType = scheduObj;
  157. if (scheduObj.type && scheduObj.type != "datetime") {
  158. return that.clickTime(data)
  159. }
  160. if (scheduObj.type && scheduObj.type == "datetime") {
  161. return that.clickDateTime(data);
  162. }
  163. return that.customTime(data);
  164. });
  165. });
  166. }
  167. var schedu = new schedu();
  168. exports("schedu", schedu);
  169. });