人人商城

display.html 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. {template 'common/header'}
  2. <style>
  3. .datetimepicker{width:200px}
  4. </style>
  5. <ul class="nav nav-tabs">
  6. <li {if $do == 'list'} class="active"{/if}><a href="{php echo url('cron/display/list');}">任务列表</a></li>
  7. <li {if $do == 'post' && empty($id)} class="active"{/if}><a href="{php echo url('cron/display/post');}">添加任务</a></li>
  8. {if $do == 'post' && !empty($id)}<li class="active"><a href="{php echo url('cron/display/post');}">编辑任务</a></li>{/if}
  9. </ul>
  10. {if $do == 'post'}
  11. <div class="clearfix">
  12. <div class="panel panel-default">
  13. <div class="panel-heading">计划任务</div>
  14. <div class="panel-body">
  15. <form class="form-horizontal form" id="form1" action="" method="post">
  16. <input type="hidden" name="id" value="{$cron['id']}">
  17. <div class="form-group">
  18. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"><span class="text-danger">* </span>任务名称</label>
  19. <div class="col-sm-10 col-xs-12">
  20. <input type="text" class="form-control" placeholder="设置本任务的任务名称" name="name" value="{$cron['name']}"/>
  21. <span class="help-block help-text">设置本任务的任务名称</span>
  22. </div>
  23. </div>
  24. <div class="form-group">
  25. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"><span class="text-danger">* </span>所属模块</label>
  26. <div class="col-sm-10 col-xs-12">
  27. <select name="module" id="module" class="form-control">
  28. {loop $modules $module}
  29. <option value="{$module['name']}">{$module['title']}</option>
  30. {/loop}
  31. </select>
  32. <span class="help-block help-text">设置本任务的任务名称</span>
  33. </div>
  34. </div>
  35. <div class="form-group">
  36. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"><span class="text-danger">* </span> 任务脚本:</label>
  37. <div class="col-sm-10 col-xs-12">
  38. <input type="text" class="form-control" placeholder="设置本任务的执行程序文件名" name="filename" value="{$cron['filename']}"/>
  39. <span class="help-block help-text">设置本任务的执行程序文件名,必须是PHP文件。请勿包含路径,系统计划任务位于 source/include/cron/ 目录中,插件计划任务位于 source/plugin/插件目录/cron/ 目录中</span>
  40. </div>
  41. </div>
  42. <div class="form-group">
  43. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"><span class="text-danger"> </span> 是否可用:</label>
  44. <div class="col-sm-10 col-xs-12">
  45. <label class="radio-inline">
  46. <input type="radio" name="status" value="1" {if $cron['status'] == 1}checked{/if}/> 可用
  47. </label>
  48. <label class="radio-inline">
  49. <input type="radio" name="status" value="0" {if $cron['status'] == 0}checked{/if}/> 不可用
  50. </label>
  51. </div>
  52. </div>
  53. <div class="form-group">
  54. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"><span class="text-danger"> </span> 任务类型:</label>
  55. <div class="col-sm-10 col-xs-12">
  56. <label class="radio-inline" onclick="$('.type').hide();$('#type1').show();">
  57. <input type="radio" name="type" value="1" {if $cron['type'] == 1}checked{/if}/> 定时任务
  58. </label>
  59. <label class="radio-inline" onclick="$('.type').hide();$('#type2').show();">
  60. <input type="radio" name="type" value="2" {if $cron['type'] == 2}checked{/if}/> 循环任务
  61. </label>
  62. <span class="help-block">定时任务是某个时间只执行一次,执行后将会自动关闭。定时群发的执行时间必须在当前时间一小时之后</span>
  63. </div>
  64. </div>
  65. <div class="form-group type" id="type1" {if $cron['type'] == 2}style="display:none"{/if}>
  66. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">执行时间:</label>
  67. <div class="col-sm-10 col-xs-12">
  68. {php echo tpl_form_field_date('executetime', $cron['lastruntime'], true);}
  69. </div>
  70. </div>
  71. <div class="type" id="type2" {if $cron['type'] == 1}style="display:none"{/if}>
  72. <div class="form-group">
  73. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">执行时间:</label>
  74. <div class="col-sm-10 col-xs-12">
  75. <label class="radio-inline" style="padding-top:0"><input type="radio" name="time" {if $cron['weekday'] == -1 && $cron['day'] > 0}checked{/if}/> 每 月</label>
  76. <select name="day" id="day" class="form-control" style="display:inline-block;width:200px;" onclick="$(this).prev().find(':radio').prop('checked', true);$('#weekday').val(-1);">
  77. <option value="-1" {if $cron['day'] == '-1'}selected{/if}>*</option>
  78. <?php
  79. for($i = 1; $i < 32; $i ++) {
  80. if($cron['day'] == $i) {
  81. echo '<option selected value="'.$i.'">'.$i.'日</option>';
  82. } else {
  83. echo '<option value="'.$i.'">'.$i.'日</option>';
  84. }
  85. }
  86. ?>
  87. </select>
  88. </div>
  89. </div>
  90. <div class="form-group">
  91. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
  92. <div class="col-sm-10 col-xs-12">
  93. <label class="radio-inline" style="padding-top:0"><input type="radio" name="time" {if $cron['weekday'] != -1}checked{/if}/> 或每周</label>
  94. <select name="weekday" id="weekday" class="form-control" style="display:inline-block;width:200px;" onclick="$(this).prev().find(':radio').prop('checked', true);$('#day').val(-1);">
  95. <option value="-1" {if $cron['weekday'] == '-1'}selected{/if}>*</option>
  96. <option value="0" {if $cron['weekday'] == '0'}selected{/if}>周日</option>
  97. <option value="1" {if $cron['weekday'] == '1'}selected{/if}>周一</option>
  98. <option value="2" {if $cron['weekday'] == '2'}selected{/if}>周二</option>
  99. <option value="3" {if $cron['weekday'] == '3'}selected{/if}>周三</option>
  100. <option value="4" {if $cron['weekday'] == '4'}selected{/if}>周四</option>
  101. <option value="5" {if $cron['weekday'] == '5'}selected{/if}>周五</option>
  102. <option value="6" {if $cron['weekday'] == '6'}selected{/if}>周六</option>
  103. </select>
  104. </div>
  105. </div>
  106. <div class="form-group">
  107. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
  108. <div class="col-sm-10 col-xs-12">
  109. <label class="radio-inline" style="padding-top:0" onclick="$('#weekday, #day').val(-1);"><input type="radio" name="time" {if $cron['weekday'] == -1 && $cron['day'] == -1}checked{/if}/> 或每天</label>
  110. </div>
  111. </div>
  112. <div class="form-group">
  113. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
  114. <div class="col-sm-10 col-xs-12">
  115. <div class="input-group">
  116. <span class="input-group-addon">当天</span>
  117. <select name="hour" class="form-control" style="display:inline-block;">
  118. <option value="-1" {if $cron['hour'] == '-1'}selected{/if}>*</option>
  119. <?php
  120. for($i = 0; $i < 24; $i ++) {
  121. if($cron['hour'] == $i) {
  122. echo '<option selected value="'.$i.'">'.$i.'时</option>';
  123. } else {
  124. echo '<option value="'.$i.'">'.$i.'时</option>';
  125. }
  126. }
  127. ?>
  128. </select>
  129. <span class="input-group-addon">分钟</span>
  130. <input type="text" name="minute" value="{$cron['minute']}" placeholder="设置哪些分钟执行本任务" class="form-control" style="display:inline-block;"/>
  131. </div>
  132. <span class="help-block help-text">设置哪些分钟执行本任务,至多可以设置 2 个分钟值,多个值之间用半角逗号 "," 隔开</span>
  133. </div>
  134. </div>
  135. </div>
  136. <div class="form-group">
  137. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
  138. <div class="col-sm-10 col-xs-12">
  139. <input type="hidden" value="{$_W['token']}" name="token"/>
  140. <input type="hidden" name="form" value="{$_W['token']}"/>
  141. <input type="submit" value="提交" class="btn btn-primary col-lg-1"/>
  142. </div>
  143. </div>
  144. </form>
  145. </div>
  146. </div>
  147. </div>
  148. <script>
  149. require(['select2', 'validator'], function(){
  150. $('#module').select2();
  151. $('#form1').bootstrapValidator({
  152. fields: {
  153. name: {
  154. validators: {
  155. notEmpty: {
  156. message: '任务名称不能为空'
  157. }
  158. }
  159. },
  160. module: {
  161. validators: {
  162. notEmpty: {
  163. message: '所属模块不能为空'
  164. }
  165. }
  166. },
  167. filename: {
  168. validators: {
  169. notEmpty: {
  170. message: '任务脚本不能为空'
  171. },
  172. regexp: {
  173. regexp: /^[a-z0-9_]+$/,
  174. message: '脚本名称只能包含字母数字下划线'
  175. }
  176. }
  177. }
  178. }
  179. });
  180. });
  181. </script>
  182. {/if}
  183. {if $do == 'list'}
  184. <div class="clearfix">
  185. <form action="{php echo url('cron/display/del')}" id="form1" method="post">
  186. <div class="panel panel-default">
  187. <div class="table-responsive panel-body">
  188. <table class="table table-hover">
  189. <thead class="navbar-inner">
  190. <tr>
  191. <th width="30"></th>
  192. <th>名称</th>
  193. <th>所属模块</th>
  194. <th>类型</th>
  195. <th style="min-width:180px;">执行时间</th>
  196. <th>上次执行时间</th>
  197. <th>下次执行时间</th>
  198. <th>添加时间</th>
  199. <th>状态</th>
  200. <th width="200">操作</th>
  201. </tr>
  202. </thead>
  203. <tbody>
  204. {loop $crons $cron}
  205. <tr>
  206. <td>
  207. <input type="checkbox" name="id[]" value="{$cron['id']}"/>
  208. </td>
  209. <td>{$cron['name']}</td>
  210. <td><span class="label label-success">{$modules[$cron['module']]['title']}</span></td>
  211. <td>
  212. {if $cron['type'] == 1}
  213. <span class="label label-success">定时任务</span>
  214. {else}
  215. <span class="label label-danger">循环任务</span>
  216. {/if}
  217. </td>
  218. <td>{$cron['cn']}</td>
  219. <td>{$cron['lastruntime']}</td>
  220. <td>{$cron['nextruntime']}</td>
  221. <td>{php echo date('Y-m-d H:i', $cron['createtime']);}</td>
  222. <td>
  223. <span class="switch">
  224. <input type="checkbox" value="1" {if $cron['status']==1} checked="checked" {/if} data-id="{$cron['id']}"/>
  225. </span>
  226. </td>
  227. <td>
  228. <div class="btn-group">
  229. <a title="同步" class="btn btn-default btn-sm" href="{php echo url('cron/display/sync', array('id' => $cron['id']))}">同步</a>
  230. <a title="编辑" class="btn btn-default btn-sm" href="{php echo url('cron/display/post', array('id' => $cron['id']))}">编辑</a>
  231. <a title="执行" class="btn btn-default btn-sm" onclick="if(!confirm('确定执行吗?')) return false;" href="{php echo url('cron/display/run', array('id' => $cron['id']))}">执行</a>
  232. <a title="删除" class="btn btn-default btn-sm" onclick="if(!confirm('确定删除吗?')) return false;" href="{php echo url('cron/display/del', array('id' => $cron['id']))}">删除</a>
  233. </div>
  234. </td>
  235. </tr>
  236. {/loop}
  237. {if !empty($crons)}
  238. <tr>
  239. <td>
  240. <input type="checkbox" id="selectall"/>
  241. </td>
  242. <td colspan="9">
  243. <input type="hidden" value="{$_W['token']}" name="token"/>
  244. <input type="submit" value="删除" name="submit" class="btn btn-primary" onclick="if(!confirm('删除后将不可恢复,确定删除吗?'))return false;"/>
  245. </td>
  246. </tr>
  247. {/if}
  248. </tbody>
  249. </table>
  250. </div>
  251. </div>
  252. </form>
  253. </div>
  254. {/if}
  255. <script>
  256. require(['bootstrap.switch', 'select2', 'validator'], function(){
  257. $('#selectall').click(function(){
  258. $('#form1 :checkbox').prop('checked', $(this).prop('checked'));
  259. });
  260. $('.switch :checkbox').bootstrapSwitch();
  261. $('.switch :checkbox').on('switchChange.bootstrapSwitch', function(e, state){
  262. $this = $(this);
  263. var id = $this.data('id');
  264. var status = this.checked ? 1 : 0;
  265. $.post("{php echo url('cron/display/status');}", {id:id, status:status}, function(resp){
  266. if(resp != 'success') {
  267. util.message(resp, '', 'error')
  268. } else {
  269. location.reload();
  270. }
  271. return false;
  272. });
  273. });
  274. });
  275. </script>
  276. {template 'common/footer'}