mytask.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. {{include "head.html"}}
  2. <div class="content-wrapper">
  3. <section class="content-header">
  4. <h1>
  5. 日常任务列表
  6. </h1>
  7. <ol class="breadcrumb">
  8. <li><a href="#"><i class="fa fa-dashboard"></i> 任务</a></li>
  9. <li class="active">列表</li>
  10. </ol>
  11. </section>
  12. <section class="content">
  13. <div class="box">
  14. <div class="box-body">
  15. <table id="mytask" class="table table-bordered table-striped">
  16. <thead>
  17. <tr>
  18. <th>爬虫代码</th>
  19. <th>网站名称</th>
  20. <th>栏目名称</th>
  21. <th>平台</th>
  22. <th>节点</th>
  23. <th>任务状态</th>
  24. <th>类型</th>
  25. <!-- <th>紧急度</th>-->
  26. <th>次数</th>
  27. <!-- <th>频率次数</th>-->
  28. <th>来源</th>
  29. <th>7日下载量</th>
  30. <th>失败占比</th>
  31. <th>最迟完成时间</th>
  32. <!-- <th>挂起</th>-->
  33. <th class="hidden-xs">操作</th>
  34. </tr>
  35. </thead>
  36. </table>
  37. </div>
  38. </div>
  39. </section>
  40. <script>
  41. // common.setActive("index_rwlb");
  42. common.menuActive("mytask");
  43. $(function(){
  44. setCookie("mytask","");
  45. mytask = $('#mytask').DataTable({
  46. "language": {
  47. "url": "/js/dataTables.chinese.lang"
  48. },
  49. "ajax": {
  50. "url": "/center/mytask",
  51. "type": "POST"
  52. },
  53. "columnDefs": [
  54. { "orderable": false, "targets": [0,1,2,3,4,5,6,12] },
  55. ],
  56. "order": [[11,"desc"]], //默认排序列
  57. "lengthChange":false,
  58. "serverSide": true,
  59. "searching": true,
  60. "ordering": true,
  61. "info": true,
  62. "autoWidth": false,
  63. "columns": [
  64. {"data":"s_code"},
  65. {"data": "s_site"},
  66. {"data": "s_channel"},
  67. {"data": "s_platform",render:function(val,a,row){
  68. if (val == null || val == undefined){
  69. return "golua平台"
  70. }
  71. return val
  72. }},
  73. {"data": "i_event"},
  74. {"data": "i_state","width":"5%",render:function(val,a,row){
  75. if (val == 0){
  76. return "待确认"
  77. }else if (val == 1){
  78. return "待处理"
  79. }else if (val == 2){
  80. return "处理中"
  81. }else if (val == 3){
  82. return "待审核"
  83. }else if (val == 4){
  84. return "审核通过"
  85. }else if (val == 5){
  86. return "未通过"
  87. }else if (val == 6){
  88. return "关闭"
  89. }
  90. }},
  91. {"data": "s_type","width":"7%",render:function(val,a,row){
  92. if(val== "1"){
  93. val="列表页异常"
  94. }else if(val=="2"){
  95. val="数据异常错误"
  96. }else if(val=="3"){
  97. val="爬虫翻页异常"
  98. }else if(val=="4"){
  99. val="采集频率异常"
  100. }else if(val=="5"){
  101. val="下载异常"
  102. }else if(val=="6"){
  103. val="数据异常警告"
  104. }else if(val=="0"){
  105. val="常规任务"
  106. }
  107. return val;
  108. }},
  109. {"data": "i_times"},
  110. {"data": "s_source"},
  111. {"data": "i_count"},
  112. {"data": "f_failrate"},
  113. {"data": "l_complete","width":"8%",render:function(val,a,row){
  114. var dt = new Date()
  115. dt.setTime(parseInt(val) * 1000);
  116. return dt.format("yyyy-MM-dd hh:mm:ss");
  117. }},
  118. {"data":"_id",render:function(val,a,row){
  119. var div=$("<div><div class=\"btn-group\"></div></div>")
  120. var dbutton=$('<a type="button" href="#" class="btn btn-sm btn-info" onclick="viewtask(\''+row._id+'\',\''+row.relatecode+'\');">查看</a>');
  121. div.find(".btn-group").append(dbutton);
  122. return div.html();
  123. // var div=$("<div><div class=\"btn-group\"></div></div>")
  124. // var buttonWatch=$('<a type="button" class="btn btn-sm btn-default">查看</a>');
  125. // buttonWatch.attr("href","/center/task/edit/"+row['_id']+"__1");
  126. // div.find(".btn-group").append(buttonWatch);
  127. // return div.html()
  128. }}
  129. ],
  130. "fnDrawCallback": function(table) {
  131. $("ul.pagination").prepend("&nbsp;&nbsp;&nbsp;转到第 <input type='text' id='changePage' style='width:20px;'> 页 <a type='text' href='javascript:void(0);' id='dataTable-btn' style='text-align:center'>GO</a>");
  132. $('#dataTable-btn').click(function(e) {
  133. var redirectpage=0
  134. if($("#changePage").val() && $("#changePage").val() > 0) {
  135. var redirectpage = $("#changePage").val() - 1;
  136. }
  137. ttable.page(redirectpage).draw(false);
  138. });
  139. },
  140. "fnServerParams": function (e) {
  141. var taskState = $("#task_state").val();
  142. var taskEvent = $("#task_event").val();
  143. var taskStype = $("#task_stype").val();
  144. var platform = $("#platform").val();
  145. if(taskState){
  146. e.taskState = taskState;
  147. }else{
  148. e.taskState="2";//默认选中处理中任务
  149. }
  150. //节点
  151. if(taskEvent){
  152. e.taskEvent = taskEvent;
  153. }else{
  154. e.taskEvent="-1";
  155. }
  156. //任务类型
  157. if(taskStype){
  158. e.taskStype = taskStype;
  159. }else{
  160. e.taskStype="-1";
  161. }
  162. //平台
  163. if(platform){
  164. e.platform = platform;
  165. }else{
  166. e.platform="-1";
  167. }
  168. }
  169. });
  170. mytask.on('init.dt', function () {
  171. var search=getCookie("mytask");
  172. if(search){
  173. $("[type=search]").val(search);
  174. }
  175. var taskState="<option value='-1'>全部</option>"+
  176. "<option value='0'>待确认</option>"+
  177. "<option value='1'>待处理</option>"+
  178. "<option selected value='2'>处理中</option>"+
  179. "<option value='3'>待审核</option>"+
  180. "<option value='4'>审核通过</option>"+
  181. "<option value='5'>未通过</option>"+
  182. "<option value='6'>关闭</option>";
  183. var selectState="<div class='form-group'><label for='name'>任务状态:</label>"+
  184. "<select id='task_state' onchange='checkclick(this.value)' class='form-control input-sm'>"+
  185. taskState+
  186. "</select></div>"
  187. $("#mytask_filter").prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  188. $("#mytask_filter").prepend(selectState);
  189. var taskStype="<option value='-1'>全部</option>"+
  190. "<option value='1'>列表页异常</option>"+
  191. "<option value='2'>数据异常错误</option>"+
  192. "<option value='3'>爬虫翻页异常</option>"+
  193. "<option value='4'>采集频率异常</option>"+
  194. "<option value='5'>下载异常</option>"+
  195. "<option value='6'>数据异常警告</option>"+
  196. "<option value='0'>常规任务</option>";
  197. var selectStype="<div class='form-group'><label for='name'>任务类型:</label>"+
  198. "<select id='task_stype' onchange='checkclick(this.value)' class='form-control input-sm'>"+
  199. taskStype+
  200. "</select></div>"
  201. $("#mytask_filter").prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  202. $("#mytask_filter").prepend(selectStype);
  203. var taskEvent="<option value='-1'>全部</option>"
  204. var events={{.T.events}}
  205. for(k in events){
  206. taskEvent+="<option value='"+events[k]+"'>"+events[k]+"</option>"
  207. }
  208. var selectEvent="<div class='form-group'><label for='name'>节点:</label>"+
  209. "<select id='task_event' onchange='checkclick(this.value)' class='form-control input-sm'>"+
  210. taskEvent+
  211. "</select></div>"
  212. $("#mytask_filter").prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  213. $("#mytask_filter").prepend(selectEvent);
  214. //平台
  215. var platform="<option value='-1'>全部</option>"
  216. platform+="<option value='golua平台'>golua平台</option>";
  217. platform+="<option value='chrome'>chrome</option>";
  218. platform+="<option value='python'>python</option>";
  219. platform+="<option value='通用平台'>通用平台</option>";
  220. platform+="<option value='jschrome'>jschrome</option>";
  221. var selectPlatform="<div class='form-group'><label for='name'>平台:</label>"+
  222. "<select id='platform' onchange='checkclick(this.value)' class='form-control input-sm'>"+
  223. platform+
  224. "</select></div>"
  225. $("#mytask_filter").prepend("&nbsp;&nbsp;");
  226. $("#mytask_filter").prepend(selectPlatform);
  227. //修改样式
  228. $("#mytask_wrapper .col-sm-6").css({width:"100%"});
  229. });
  230. mytask.on('preXhr.dt', function ( e, settings, data ) {
  231. $("[type=search]").keypress(function(){
  232. setCookie("mytask",$("[type=search]").val());
  233. })
  234. });
  235. //每次登陆提示还有多少条未通过的任务和错误爬虫个数
  236. var failedtasknum = {{.T.failedtasknum}};
  237. var errluanum = {{.T.errluanum}};
  238. var tips = "";
  239. if(failedtasknum>0){
  240. tips = "你当前有未通过的任务"+failedtasknum.toString()+"条;";
  241. }
  242. if(errluanum>0){
  243. tips = tips + "你当前有错误爬虫"+errluanum.toString()+"个";
  244. }
  245. if(tips!=""){
  246. showTip(tips,5000);
  247. }
  248. });
  249. function checkclick(urgency){
  250. mytask.ajax.reload();
  251. }
  252. function createComboxPendState(code,id){
  253. return "<select onchange='changeCodePendState(this.value,\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+
  254. "<option value=1>是</option>"+
  255. "<option value=0>否</option>"+
  256. "</select>"
  257. };
  258. function changeCodePendState(pendstate,code,id){
  259. $.ajax({
  260. url:"/center/spider/updatePendState",
  261. type:"post",
  262. data:{
  263. "pendstate":pendstate,
  264. "id":id,
  265. "code":code,
  266. "stype":"task"
  267. },
  268. success:function(r){
  269. if(!r || !r.success){
  270. showTip("修改失败", 1000, function() {});
  271. }
  272. mytask.ajax.reload();
  273. }
  274. })
  275. }
  276. function viewtask(id,relatecode) {
  277. if(relatecode != ""){
  278. showConfirm("请注意修改关联爬虫:"+relatecode, function() {
  279. $.get("/center/task/createrelatetask?relatecode="+relatecode+"&id="+id,function(r){
  280. if (r&&r.ok){
  281. window.location.href="/center/task/edit/"+id+"__1";
  282. }else{
  283. showTip("关联爬虫任务创建失败", 1000, function() {});
  284. }
  285. })
  286. });
  287. }else{
  288. window.location.href="/center/task/edit/"+id+"__1";
  289. }
  290. }
  291. </script>
  292. </div>
  293. {{include "bottom.html"}}