nzTimer.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //'/service?wdApplication=env&wdService=env.getAllNz&wdToken=2&now=s'
  2. var nzinterval
  3. var data = {};
  4. var h6;
  5. var nzdatas;
  6. var errorTimes = 0;
  7. var maxErrorTimes = 3;
  8. initNz();
  9. function initData() {
  10. $.ajax({
  11. /* 改。Lin
  12. url: "/service?wdApplication=zzfb_&wdService=getAllNz&wdToken=2&now=" + new Date().Format("yyyy-MM-dd hh:mm:ss"),
  13. */ url: "/service?ssServ=selAllSched&ssToken=2&now="+ new Date().Format("yyyy-MM-dd hh:mm:ss"),
  14. // dataType:"json",
  15. success: function(dat) {
  16. data = eval("(" + dat + ")");
  17. nzdatas = document.getElementById("nzdatas");
  18. if (!nzdatas) {
  19. console.log("append");
  20. $("body").append("<div style='display:none' id='nzdatas'></div>");
  21. }
  22. console.log($("#nzdatas")[0]);
  23. document.getElementById("nzdatas").innerHTML = dat;
  24. if (data.length > 0 && h6) {
  25. var lis = '';
  26. var now = new Date();
  27. $.each(data, function(i) {
  28. var kssj = new Date(this.start);
  29. var sjstr;
  30. if (now.Format("yyyy-MM-dd") == kssj.Format("yyyy-MM-dd")) {
  31. sjstr = kssj.Format("hh:mm:ss");
  32. } else {
  33. sjstr = this.start;
  34. }
  35. lis += '<li id="' + this.id + "_" + this.rclbm + '">' + sjstr + ': ' + this.title + '</li>'
  36. if (i >= 10) {
  37. return false;
  38. }
  39. });
  40. var f = window.top.data[0];
  41. var fsj = new Date(f.start);
  42. var sj;
  43. if (now.Format("yyyy-MM-dd") == fsj.Format("yyyy-MM-dd")) {
  44. sj = fsj.Format("hh:mm:ss");
  45. } else {
  46. if(now.getFullYear() == fsj.getFullYear())
  47. sj = fsj.Format("MM-dd hh:mm:ss");
  48. else
  49. sj = f.start;
  50. }
  51. console.log("sj"+ sj);
  52. $.each(h6, function(index) {
  53. var s = "";
  54. if (data.length > 1) {
  55. s = "<span class='sho' onmouseover=\"$(this).parent().find('ul').show('fast','swing')\" onmouseleave=\"$(this).parent().find('ul').hide('fast','swing')\">▲<ul>" + lis + "</ul></span>";
  56. }
  57. $(this).html("<div><span id=\"" + f.id + "_" + f.rclbm + "\" >" + sj + ":" + f.title + "</span>" + s + "</div>");
  58. });
  59. } else if (data.length == 0) {
  60. $.each(h6, function(index) {
  61. $(this).html(new Date().Format("yyyy-MM-dd E"));
  62. });
  63. }
  64. $(h6).find("span").on("click", function(e) {
  65. var t = $(this);
  66. var id = t.attr("id");
  67. if (!id) {
  68. return;
  69. }
  70. window.top.rcapid = id;
  71. var jj = $(h6).parent().find(".showcal").eq(0).val();
  72. console.log(jj);
  73. eval(jj);
  74. return false;
  75. });
  76. $(h6).find("li").on('click', function(e) {
  77. var t = $(this);
  78. var id = t.attr("id");
  79. window.top.rcapid = id;
  80. var jj = $(h6).parent().find(".showcal").eq(0).val();
  81. console.log(jj);
  82. eval(jj);
  83. return false;
  84. });
  85. $(h6).find("div").on("click", function() {
  86. eval($(h6).parent().find(".showcal").eq(0).val());
  87. });
  88. },
  89. //请求出现错误
  90. error: function(dat){
  91. errorTimes++;
  92. //超过三次 删除定时器
  93. if(maxErrorTimes > errorTimes){
  94. ;
  95. }else{
  96. if(undefined != nzinterval)
  97. clearInterval(nzinterval);
  98. }
  99. },
  100. async: false
  101. });
  102. }
  103. function initNz() {
  104. if(!nzinterval) {
  105. nzinterval = setInterval(
  106. function() {
  107. var now = new Date();
  108. $.each(
  109. data,
  110. function(a) {
  111. var b = this
  112. var nowStr = now
  113. .Format("yyyy-MM-dd hh:mm:ss");
  114. var dataTime = new Date(b.start);
  115. var dataTimeStr = dataTime
  116. .Format("yyyy-MM-dd hh:mm:ss")
  117. if(nowStr == dataTimeStr) {
  118. // wd.display
  119. // .showComponent({
  120. // show: ["wdDialog"],
  121. // hide: [],
  122. // url: "/service?wdApplication=env&wdService=env.xgNz&wdOutputComponent=440122853&wdtest=false&wdComponentWebsite=4461&rcapid=" + b.id,
  123. // dest: "env.grsydialog.tip",
  124. // title: "闹钟提醒",
  125. // width: 650,
  126. // high: 450,
  127. // wdDialogId: 440122853,
  128. // form: ""
  129. // });
  130. //shownzjs = shownzjs.replace("ID=ID", "rcapid=" + b.id);
  131. var json = JSON.parse('{"ID":"'+b.id+'"}');
  132. shownzjs = wd.display.replaceDynamicParam(shownzjs, json);
  133. eval(shownzjs);
  134. //console.log(shownzjs);
  135. data.splice(a, 1);
  136. return false;
  137. }
  138. if(now > dataTime) { // 如果存在小于现在的时间,重新获取闹钟时间
  139. initData();
  140. return false;
  141. }
  142. });
  143. }, 1000);
  144. } else {
  145. initData();
  146. }
  147. }